lmstack 2 years ago
parent
commit
b764e22a84
2 changed files with 29 additions and 10 deletions
  1. 3 4
      LIB/FRONTEND/AlgoTest/Algo1/Dockerfile
  2. 26 6
      LIB/MIDDLE/AlgoTest/Algo1/main.py

+ 3 - 4
LIB/FRONTEND/AlgoTest/Algo1/Dockerfile

@@ -22,13 +22,12 @@ RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple \
 #RUN rm -r /usr/bin
 #RUN rm -r /bin
 
-
-
-# 复制算法文件到 容器
+# 配置算法路径
 ARG ALGO_PATH=LIB/MIDDLE/AlgoTest/Algo1
+# 配置版本路径
 ARG ALGO_VERSION=V_1_0_0
 
-# 复制公共库文件到 容器
+# 复制文件文件到 容器
 ADD LIB/BACKEND/ /LIB/BACKEND
 ADD ${ALGO_PATH}/${ALGO_VERSION}/ /${ALGO_VERSION}/
 ADD ${ALGO_PATH}/main.py /main.py

+ 26 - 6
LIB/MIDDLE/AlgoTest/Algo1/main.py

@@ -1,16 +1,36 @@
 import pandas as pd
-from LIB.BACKEND import DBManager # 以相对路径的方式引入!!!!!
-import V_1_0_0.core as core # 以相对路径的方式引入!!!!!
-
+import time
+from LIB.BACKEND import DBManager,Log # 以相对路径的方式引入!!!!!
+from V_1_0_0 import core # 以相对路径的方式引入!!!!!
+import os
 if __name__ == '__main__':
     
-    sn = "PK10001A326000123"
+    # 获取环境变量
+    env_dist = os.environ
+    host = env_dist.get("HOST", '120.25.223.1')
+    port = env_dist.get("PORT", '4901')
+    db = env_dist.get("DB", 'ali')
+    user = env_dist.get("ROOT", 'root')
+    password = env_dist.get("PASSWORD", '123456')
+    
+    # 日志配置
+    now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_")
+    log_path = 'log/' + now_str
+    if not os.path.exists(log_path):
+        os.makedirs(log_path)
+    log = Log.Mylog(log_name='cal_sor', log_level = 'info')
+    log.set_file_hl(file_name='{}/info.log'.format(log_path), log_level='info', size=1024* 1024 * 100)
+    log.set_file_hl(file_name='{}/error.log'.format(log_path), log_level='error', size=1024* 1024 * 100)
+    logger = log.get_logger()
+    
+    # 准备算法数据
+    sn = "PK10001A326000123" 
     st = '2021-07-06 00:00:00'
     et = '2021-07-07 20:00:00'
-
     dbManager = DBManager.DBManager()
     df_data = dbManager.get_data(sn=sn, start_time=st, end_time=et, data_groups=['bms', 'gps', 'accum', 'system'])
-# 
     df_bms = df_data['bms']
+    # 调用核心算法
     calSor = core.CalSor();
+    # 接收算法结果
     print(calSor.calSor(df_bms,df_bms))