Browse Source

添加算法模板

lmstack 3 years ago
parent
commit
5adbab315f

+ 1 - 1
LIB/BACKEND/DBManager.py

@@ -31,7 +31,7 @@ class DBManager():
         self.connect()
         return self
 
-    def __exit__(self):
+    def __exit__(self, exc_type, exc_val, exc_tb):
         self.close()
 
     def connect(self):

+ 28 - 0
LIB/MIDDLE/算法类别/算法名/V_1_0_0/core_algorithm.py

@@ -0,0 +1,28 @@
+import other_algorithm
+
+class Algo:
+
+     def __init__(self):
+          pass
+
+     # 算法内部调用的函数
+     def _fun1(self):
+          pass
+
+     # 算法内部调用的函数
+     def _fun2(self):
+          pass
+
+     # 算法对外提供的函数
+     def core_algorithm(self, data1, data2, param1, param2, ....):
+
+          #核心算法逻辑
+          _fun1();
+          _fun2();
+          data3 = other_algorithm(data1);
+          res1 = f(data1, data2, param1,...)
+          res2 = f(data1, data3, param2,...)
+
+          return [res1, res2]
+
+

+ 28 - 0
LIB/MIDDLE/算法类别/算法名/V_1_0_1/core_algorithm.py

@@ -0,0 +1,28 @@
+import other_algorithm
+
+class Algo:
+
+     def __init__(self):
+          pass
+
+     # 算法内部调用的函数
+     def _fun1(self):
+          pass
+
+     # 算法内部调用的函数
+     def _fun2(self):
+          pass
+
+     # 算法对外提供的函数
+     def core_algorithm(self, data1, data2, param1, param2, ....):
+
+          #核心算法逻辑
+          _fun1();
+          _fun2();
+          data3 = other_algorithm(data1);
+          res1 = f(data1, data2, param1,...)
+          res2 = f(data1, data3, param2,...)
+
+          return [res1, res2]
+
+

+ 38 - 0
LIB/MIDDLE/算法类别/算法名/main.py

@@ -0,0 +1,38 @@
+import get_data
+import get_data_by_sql
+import get_data_from_other_algorithm
+import data_process
+import core_algorithm
+
+# 数据库连接参数
+conn = connect(host, ......)
+# 准备算法输入参数
+parameter1 = * 
+parameter2 = *
+
+# 多次调用核心算法时,将循环写在外面
+for (i=1:n){
+     
+     # 获取数据
+     data1 = get_data(sn[i], start_time, end_time, ....) # 函数取数
+     data2 = get_data_by_sql(sn[i], start_time, end_time, ....) # sql 语句直接数据库取数
+     data3 = get_data_from_other_algorithm(data1, parameter1, ....)  # 调用其他人的算法得到数据
+
+     # 通用数据预处理 (可选,由算法说明文档说明算法输入数据是否需要预处理)
+     data1 = data_process(data1)
+     data2 = data_process(data2)
+     
+     # 调用核心算法
+     [res1, res2] = core_algorithm(data1, data2, data3, parameter1, parameter2, ....)
+
+     # 使用结果
+     res1 = res1.append(res)
+     res1.to_csv(...)
+     res1.to_sql(...)
+}
+
+# 批量使用结果
+res.to_csv(...)
+res1.to_sql(...)
+
+

+ 28 - 0
LIB/MIDDLE/算法类别/算法名2/V_1_0_0/core_algorithm.py

@@ -0,0 +1,28 @@
+import other_algorithm
+
+class Algo:
+
+     def __init__(self):
+          pass
+
+     # 算法内部调用的函数
+     def _fun1(self):
+          pass
+
+     # 算法内部调用的函数
+     def _fun2(self):
+          pass
+
+     # 算法对外提供的函数
+     def core_algorithm(self, data1, data2, param1, param2, ....):
+
+          #核心算法逻辑
+          _fun1();
+          _fun2();
+          data3 = other_algorithm(data1);
+          res1 = f(data1, data2, param1,...)
+          res2 = f(data1, data3, param2,...)
+
+          return [res1, res2]
+
+

+ 28 - 0
LIB/MIDDLE/算法类别/算法名2/V_1_0_1/core_algorithm.py

@@ -0,0 +1,28 @@
+import other_algorithm
+
+class Algo:
+
+     def __init__(self):
+          pass
+
+     # 算法内部调用的函数
+     def _fun1(self):
+          pass
+
+     # 算法内部调用的函数
+     def _fun2(self):
+          pass
+
+     # 算法对外提供的函数
+     def core_algorithm(self, data1, data2, param1, param2, ....):
+
+          #核心算法逻辑
+          _fun1();
+          _fun2();
+          data3 = other_algorithm(data1);
+          res1 = f(data1, data2, param1,...)
+          res2 = f(data1, data3, param2,...)
+
+          return [res1, res2]
+
+

+ 38 - 0
LIB/MIDDLE/算法类别/算法名2/main.py

@@ -0,0 +1,38 @@
+import get_data
+import get_data_by_sql
+import get_data_from_other_algorithm
+import data_process
+import core_algorithm
+
+# 数据库连接参数
+conn = connect(host, ......)
+# 准备算法输入参数
+parameter1 = * 
+parameter2 = *
+
+# 多次调用核心算法时,将循环写在外面
+for (i=1:n){
+     
+     # 获取数据
+     data1 = get_data(sn[i], start_time, end_time, ....) # 函数取数
+     data2 = get_data_by_sql(sn[i], start_time, end_time, ....) # sql 语句直接数据库取数
+     data3 = get_data_from_other_algorithm(data1, parameter1, ....)  # 调用其他人的算法得到数据
+
+     # 通用数据预处理 (可选,由算法说明文档说明算法输入数据是否需要预处理)
+     data1 = data_process(data1)
+     data2 = data_process(data2)
+     
+     # 调用核心算法
+     [res1, res2] = core_algorithm(data1, data2, data3, parameter1, parameter2, ....)
+
+     # 使用结果
+     res1 = res1.append(res)
+     res1.to_csv(...)
+     res1.to_sql(...)
+}
+
+# 批量使用结果
+res.to_csv(...)
+res1.to_sql(...)
+
+