liumiaomiao 9 tháng trước cách đây
mục cha
commit
f3d39c783e
1 tập tin đã thay đổi với 157 bổ sung0 xóa
  1. 157 0
      tools/数据时效监控/data_timeliness.py

+ 157 - 0
tools/数据时效监控/data_timeliness.py

@@ -0,0 +1,157 @@
+from pymongo import MongoClient
+from datetime import datetime, timedelta
+from lib.monitor_tools import monitor
+from lib.mongo_tools import MongoUtil
+#数据时效性 每周统计
+def data_timeliness():
+    try:
+        now = datetime.now()
+        end_date = now.strftime("%Y-%m-%d")
+        start_date = (datetime.now() - timedelta(days=7)).strftime("%Y-%m-%d")
+
+        collection = MongoUtil.get_coon(host='127.0.0.1:27088', database='qfw', collection='bidding_zhibiao',
+                                        authuser='viewdata', authpass='viewdata')
+        query = {"日期": {"$gte": start_date, "$lt": end_date}}
+        a1s = 0
+        a2s = 0
+        a3s = 0
+        a4s = 0
+        a5s = 0
+        a6s = 0
+        a7s = 0
+        a8s = 0
+        a9s = 0
+        a10s = 0
+        a11s = 0
+
+        for item in collection.find(query).sort("_id",-1):
+            a1=item.get("数据时效指标").get("数据时效分位数统计").get("a1")
+            number_str1 = a1.rstrip('%')
+            # 转换为浮点数
+            number_float1 = float(number_str1)
+            a1s+=number_float1
+
+            a2 = item.get("数据时效指标").get("数据时效分位数统计").get("a2")
+            number_str2 = a2.rstrip('%')
+            # 转换为浮点数
+            number_float2 = float(number_str2)
+            a2s+=number_float2
+
+            a3 = item.get("数据时效指标").get("数据时效分位数统计").get("a3")
+            number_str3 = a3.rstrip('%')
+            # 转换为浮点数
+            number_float3 = float(number_str3)
+            a3s += number_float3
+
+            a4 = item.get("数据时效指标").get("数据时效分位数统计").get("a4")
+            number_str4 = a4.rstrip('%')
+            # 转换为浮点数
+            number_float4 = float(number_str4)
+            a4s += number_float4
+
+            a5 = item.get("数据时效指标").get("数据时效分位数统计").get("a5")
+            number_str5 = a5.rstrip('%')
+            # 转换为浮点数
+            number_float5 = float(number_str5)
+            a5s += number_float5
+
+            a6 = item.get("数据时效指标").get("数据时效分位数统计").get("a6")
+            number_str6 = a6.rstrip('%')
+            # 转换为浮点数
+            number_float6 = float(number_str6)
+            a6s += number_float6
+
+            a7 = item.get("数据时效指标").get("数据时效分位数统计").get("a7")
+            number_str7 = a7.rstrip('%')
+            # 转换为浮点数
+            number_float7 = float(number_str7)
+            a7s += number_float7
+
+            a8 = item.get("数据时效指标").get("数据时效分位数统计").get("a8")
+            number_str8 = a8.rstrip('%')
+            # 转换为浮点数
+            number_float8 = float(number_str8)
+            a8s += number_float8
+
+            a9 = item.get("数据时效指标").get("数据时效分位数统计").get("a9")
+            number_str9 = a9.rstrip('%')
+            # 转换为浮点数
+            number_float9 = float(number_str9)
+            a9s += number_float9
+
+            a10 = item.get("数据时效指标").get("数据时效分位数统计").get("a10")
+            number_str10 = a10.rstrip('%')
+            # 转换为浮点数
+            number_float10 = float(number_str10)
+            a10s += number_float10
+
+            a11 = item.get("数据时效指标").get("数据时效分位数统计").get("a11")
+            number_str11 = a11.rstrip('%')
+            # 转换为浮点数
+            number_float11 = float(number_str11)
+            a11s += number_float11
+
+        a11=a1s/7
+        a11 = round(a11, 2)
+        a11=f"{a11}%"
+
+        a22=a2s/7
+        a22 = round(a22, 2)
+        a22 = f"{a22}%"
+
+        a33=a3s/7
+        a33 = round(a33, 2)
+        a33 = f"{a33}%"
+
+        a44=a4s/7
+        a44 = round(a44, 2)
+        a44 = f"{a44}%"
+
+        a55=a5s/7
+        a55 = round(a55, 2)
+        a55 = f"{a55}%"
+
+        a66=a6s/7
+        a66 = round(a66, 2)
+        a66 = f"{a66}%"
+
+        a77=a7s/7
+        a77 = round(a77, 2)
+        a77 = f"{a77}%"
+
+        a88=a8s/7
+        a88 = round(a88, 2)
+        a88 = f"{a88}%"
+
+        a99 = a9s / 7
+        a99 = round(a99, 2)
+        a99 = f"{a99}%"
+
+        a100 = a10s / 7
+        a100 = round(a100, 2)
+        a100 = f"{a100}%"
+
+        a111 = a11s / 7
+        a111 = round(a111, 2)
+        a111 = f"{a111}%"
+
+        times={}
+
+        times["a1"]=  a11
+        times["a2"] = a22
+        times["a3"] = a33
+        times["a4"] = a44
+        times["a5"] = a55
+        times["a6"] = a66
+        times["a7"] = a77
+        times["a8"] = a88
+        times["a9"] = a99
+        times["a10"] = a100
+        times["a11"] = a111
+        return times
+    except Exception as e:
+        print(f"An error occurred: {e}")
+
+times=data_timeliness()
+print(times)
+monitor.save_to_mongo('data_timeliness',times)