浏览代码

更新物理世界数据

李莎 1 年之前
父节点
当前提交
efbe05ee75

+ 0 - 49
physical_world_exporter/MyUtils/ConfigUtils.py

@@ -1,49 +0,0 @@
-import xml.etree.ElementTree as ET
-
-
-#读取xml文件
-class ConfigUtils():
-    def __init__(self,file):
-        self.url = ""
-        self.tree = ET.parse(file)
-        self.root = self.tree.getroot()
-
-    def readTop(self, key, child):
-        datas = []
-        data = self.root.find(key)
-        for key in child:
-            datas.append(data.get(key))
-        return datas
-
-    def readTopDict(self, key, child):
-        datas = {}
-        data = self.root.find(key)
-        for key in child:
-            datas[key] = data.get(key)
-        return datas
-
-    def readConfig(self,parent,child):
-        datas=[]
-        for childLine in self.root.find(parent):
-            data=[]
-            for key in child:
-                data.append(childLine.get(key))
-            datas.append(data)
-        return datas
-
-    def readConfigDict(self,parent,child):
-        datas=[]
-        for childLine in self.root.find(parent):
-            data={}
-            for key in child:
-                data[key]=childLine.get(key)
-            datas.append(data)
-        return datas
-
-    def readConfigSingle(self,key):
-        data = self.root.find(key).text
-        return data
-
-
-if __name__ == '__main__':
-    config = ConfigUtils("logger.conf")

+ 21 - 5
physical_world_exporter/MyUtils/DateUtils.py

@@ -1,10 +1,10 @@
 import datetime
-
+from dateutil.relativedelta import relativedelta
 from dateutil import rrule
 
 YYmmddHHMMSS = "%Y%m%d%H%M%S"
 YYmmdd = "%Y%m%d"
-
+YYmm = "%Y%m"
 # 根据开始月份结束月份获取所有月份
 def get_each_month(start_month, end_month):
     if str(start_month).count('-') != 1 or str(end_month).count('-') != 1:
@@ -53,8 +53,8 @@ def get_eachmonth(start_month, end_month):
 
 def get_month(starttime, endtime):
     months = []
-    starttime = datetime.datetime.strptime(starttime[0:6], "%Y%m")
-    endtime = datetime.datetime.strptime(endtime[0:6], "%Y%m")
+    starttime = datetime.datetime.strptime(starttime, YYmmddHHMMSS)
+    endtime = datetime.datetime.strptime(endtime, YYmmddHHMMSS)
     while starttime <= endtime:
         start = starttime.strftime("%Y%m")
         if start not in months:
@@ -62,6 +62,22 @@ def get_month(starttime, endtime):
         starttime = starttime + datetime.timedelta(days=1)
     return months
 
+def get_month_range(starttime, endtime):
+    months = []
+    starttime = datetime.datetime.strptime(starttime[0:8], YYmmdd)
+    endtime = datetime.datetime.strptime(endtime[0:8], YYmmdd)
+    while starttime < endtime:
+        start = starttime.strftime(YYmmddHHMMSS)
+        endMonth = datetime.datetime.strptime(start[0:6], YYmm) + relativedelta(months=+1)
+
+        end = endMonth.strftime(YYmmddHHMMSS)
+        if endtime <= endMonth:
+            end = endtime.strftime(YYmmddHHMMSS)
+        starttime = endMonth
+        months.append([start, end])
+    return months
+
+
 
 def get_month1(starttime, endtime):
     months = []
@@ -118,4 +134,4 @@ def get_day(starttime,endtime):
     return times
 
 if __name__ == '__main__':
-    print(get_each_month("2020-01", "2020-12"))
+    print(get_day("20220101000000", "20220201000000"))

+ 1 - 1
physical_world_exporter/MyUtils/MetadataWebUtil.py

@@ -1,5 +1,5 @@
 import json
-from HttpUtil import *
+from physical_world_exporter.MyUtils.HttpUtil import *
 
 
 class MetadataWebUtil(object):

+ 0 - 70
physical_world_exporter/MyUtils/MysqlUtils.py

@@ -1,70 +0,0 @@
-import pymysql
-from dbutils.pooled_db import PooledDB
-
-
-class MysqlUtils():
-    # 连接池对象
-    __pool = None
-    def __init__(self,**config):
-        self.host = config["host"]
-        self.port = int(config["port"])
-        self.user = config["user"]
-        self.passwd = config["passwd"]
-        self.database = None
-        if "database" in config:
-            self.database = config["database"]
-        # self.pool = self.get_conn()
-        self.pool = None
-
-    def get_conn(self):
-        if MysqlUtils.__pool is None:
-            __pool = PooledDB(pymysql, mincached=1, maxcached=5, maxconnections=5,
-                              host=self.host, port=self.port, user=self.user, passwd=self.passwd,
-                              database=self.database,
-                               use_unicode=False, blocking=False, charset="utf8")
-            self.pool = __pool
-
-
-    def query(self,sql):
-        con = None
-        cur = None
-        try:
-            con = self.pool.connection()
-            cur = con.cursor()
-            count = cur.execute(sql)
-            if count >= 0:
-                result = cur.fetchall()
-                result = [[j.decode() if isinstance(j,bytes) else j for j in i] for i in result]
-                # print(result)
-            else:
-                result = False
-            return result
-        except Exception as e:
-            print(e)
-        finally:
-            if cur:
-                cur.close()
-            if con:
-                con.close()
-
-
-    def update(self,sql):
-        con = None
-        cur = None
-        try:
-            con = self.pool.connection()
-            cur = con.cursor()
-            cur.execute(sql)
-            con.commit()
-        except Exception as e:
-            con.rollback()  # 事务回滚
-            print(e)
-        finally:
-            if cur:
-                cur.close()
-            if con:
-                con.close()
-
-    def close(self):
-        if MysqlUtils.__pool:
-            MysqlUtils.__pool.close()

+ 1 - 12
physical_world_exporter/MyUtils/ZillionUtil.py

@@ -1,4 +1,4 @@
-from MetadataWebUtil import MetadataWebUtil
+from physical_world_exporter.MyUtils.MetadataWebUtil import MetadataWebUtil
 
 
 class ZillionUtil():
@@ -93,17 +93,6 @@ class ZillionUtil():
         databases = self.metadata.get_hbase(param)
         return databases["Count"]
 
-    def delete(self,database,table,Criteria):
-        param = {
-            "QueryType": "delete",
-            "Database": database,
-            "Datatable": table,
-            "Criteria": Criteria
-        }
-        databases = self.metadata.get_hbase(param)
-        return databases["Count"]
-
-
     def put(self,database,table,InsertObject):
         param = {
             "QueryType": "batch_put",