This commit is contained in:
parent
af11bddb60
commit
d78125ae03
|
|
@ -13,20 +13,20 @@ class DbfToPostgresCtllogPwrPipeline(BasePipeline):
|
|||
def __init__(self, config):
|
||||
super().__init__(config)
|
||||
# todo:本地调试打开
|
||||
self.data_root = 'D:\disney_test'
|
||||
self.mapping_file = 'D:\disney_test\disney-mapping-elec-v3.xlsx'
|
||||
# self.data_root = 'D:\disney_test'
|
||||
# self.mapping_file = 'D:\disney_test\disney-mapping-elec-v3.xlsx'
|
||||
# todo:本地调试打开
|
||||
# self.data_root = os.getenv('DATA_PVC_MOUNT_PATH', '/data')
|
||||
# self.mapping_file = os.getenv('MAPPING_FILE')
|
||||
self.data_root = os.getenv('DATA_PVC_MOUNT_PATH', '/data')
|
||||
self.mapping_file = os.getenv('MAPPING_FILE')
|
||||
self.dbf_dir = os.getenv('DBF_INPUT_DIR', os.path.join(self.data_root, 'dbf-input'))
|
||||
|
||||
# todo:debug use
|
||||
self.csv_file_path = 'D:\disney_test\debug_controller_log_elec.csv'
|
||||
# 初始化CSV文件
|
||||
if not os.path.exists(self.csv_file_path):
|
||||
with open(self.csv_file_path, 'w') as f:
|
||||
csv.writer(f).writerow(
|
||||
['created', 'control_group_controller_id', 'point_id', 'real_value'])
|
||||
# self.csv_file_path = 'D:\disney_test\debug_controller_log_elec.csv'
|
||||
# # 初始化CSV文件
|
||||
# if not os.path.exists(self.csv_file_path):
|
||||
# with open(self.csv_file_path, 'w') as f:
|
||||
# csv.writer(f).writerow(
|
||||
# ['created', 'control_group_controller_id', 'point_id', 'real_value'])
|
||||
# todo:debug use
|
||||
|
||||
self.db = None
|
||||
|
|
@ -87,8 +87,8 @@ class DbfToPostgresCtllogPwrPipeline(BasePipeline):
|
|||
|
||||
# 连接数据库
|
||||
# todo:本地调试时关闭
|
||||
# db_config = self.config.get_database_config()
|
||||
# self.db = Database(**db_config)
|
||||
db_config = self.config.get_database_config()
|
||||
self.db = Database(**db_config)
|
||||
# todo:本地调试时关闭
|
||||
|
||||
# 处理文件
|
||||
|
|
@ -102,7 +102,7 @@ class DbfToPostgresCtllogPwrPipeline(BasePipeline):
|
|||
|
||||
# 关闭数据库连接
|
||||
# todo:本地调试时关闭
|
||||
# self.db.disconnect()
|
||||
self.db.disconnect()
|
||||
# todo:本地调试时关闭
|
||||
return total_processed
|
||||
|
||||
|
|
@ -177,15 +177,15 @@ class DbfToPostgresCtllogPwrPipeline(BasePipeline):
|
|||
return
|
||||
|
||||
# 实际插入数据库
|
||||
# self.db.execute_batch(
|
||||
# "INSERT INTO controller_log (created, control_group_controller_id, point_id, real_value) VALUES (%s, %s, %s, %s)",
|
||||
# [(data[0], data[1], data[2], data[3]) for data in self.batch_data]
|
||||
# )
|
||||
self.db.execute_batch(
|
||||
"INSERT INTO controller_log (created, control_group_controller_id, point_id, real_value) VALUES (%s, %s, %s, %s)",
|
||||
[(data[0], data[1], data[2], data[3]) for data in self.batch_data]
|
||||
)
|
||||
|
||||
# todo: debug时写入CSV(调试用)
|
||||
with open(self.csv_file_path, "a", newline="") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerows(self.batch_data)
|
||||
# with open(self.csv_file_path, "a", newline="") as f:
|
||||
# writer = csv.writer(f)
|
||||
# writer.writerows(self.batch_data)
|
||||
# todo: debug时写入CSV
|
||||
|
||||
# 更新处理记录数
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user