su-lmstack 3 years ago
parent
commit
654a067d99
1 changed files with 7 additions and 4 deletions
  1. 7 4
      LIB/MIDDLE/CellStateEstimation/Common/DBDownload.py

+ 7 - 4
LIB/MIDDLE/CellStateEstimation/Common/DBDownload.py

@@ -4,12 +4,13 @@ import pandas as pd
 
 
 class DBDownload:
 class DBDownload:
 
 
-    def __init__(self, host='', port='', db='', user='', password=''):
+    def __init__(self, host='', port='', db='', user='', password='', mode=''):
         self.host = host
         self.host = host
         self.port = port
         self.port = port
         self.db = db
         self.db = db
         self.user = user
         self.user = user
         self.password = password
         self.password = password
+        self.mode=mode
         pass
         pass
 
 
     def __enter__(self):
     def __enter__(self):
@@ -33,7 +34,7 @@ class DBDownload:
                 print('数据库连接成功!')
                 print('数据库连接成功!')
                 self.cursor = self.conn.cursor()
                 self.cursor = self.conn.cursor()
 
 
-    def getdata(self,*param,tablename,sn):
+    def getdata(self,*param,tablename,sn,timename,st,sp):
         print('数据获取中......')
         print('数据获取中......')
         param=list(param)
         param=list(param)
         str=''
         str=''
@@ -42,8 +43,10 @@ class DBDownload:
                 str=str+param[i]
                 str=str+param[i]
             else:
             else:
                 str=str+','+param[i]
                 str=str+','+param[i]
-        # self.cursor.execute("select %s from %s where time between '%s' and '%s'" %(str,tablename,st,sp))
-        self.cursor.execute("select %s from %s where sn='%s' order by id desc limit 1" %(str,tablename,sn))
+        if self.mode==1:
+            self.cursor.execute("select %s from %s where sn='%s' order by id desc limit 1" %(str,tablename,sn))
+        else:
+            self.cursor.execute("select %s from %s where sn='%s' and %s between '%s' and '%s'" %(str,tablename,sn,timename,st,sp))
         res = self.cursor.fetchall()
         res = self.cursor.fetchall()
         df_res = pd.DataFrame(res, columns=param)
         df_res = pd.DataFrame(res, columns=param)
         df_res = df_res.reset_index(drop=True)
         df_res = df_res.reset_index(drop=True)