Commit 34c195bb by 陈森彬

add get_platform_none_data_rate

parent 8b226b51
Showing with 60 additions and 3 deletions
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import sys import sys
import time import time
import pymongo
from utils.glo import Glo
from urllib.parse import quote_plus from urllib.parse import quote_plus
import pymongo glo =Glo()
MG_HOST_SET = { MG_HOST_SET = {
'test': '192.168.1.237', 'test': '192.168.1.237',
...@@ -16,12 +19,13 @@ ENV = 'test' if sys.platform in ('darwin', 'win32') else 'produce' ...@@ -16,12 +19,13 @@ ENV = 'test' if sys.platform in ('darwin', 'win32') else 'produce'
def get_mongo_conf(): def get_mongo_conf():
host = MG_HOST_SET[ENV] host = MG_HOST_SET[ENV]
psd = 'huntmon66499' if ENV == 'produce' else 'huntmon6699'
conf = { conf = {
"host": host, "host": host,
"port": 27017, "port": 27017,
"database": 'ichunt', "database": 'ichunt',
"user": 'ichunt', "user": 'ichunt',
"password": 'huntmon66499' "password": psd
} }
return conf return conf
...@@ -37,7 +41,10 @@ class MongoOperator: ...@@ -37,7 +41,10 @@ class MongoOperator:
# element14 chip1stop ti # element14 chip1stop ti
self.colls = ('alliedelec', 'arrow', 'avnet', 'buerklin', 'digikey', 'master', 'rs', 'rochester', self.colls = ('alliedelec', 'arrow', 'avnet', 'buerklin', 'digikey', 'master', 'rs', 'rochester',
'verical', "powell", 'microchip', 'tme', 'heilind', 'maxim', 'aipco', 'company', 'rutronik', 'verical', "powell", 'microchip', 'tme', 'heilind', 'maxim', 'aipco', 'company', 'rutronik',
'mouser', 'corestaff', 'wpg', 'szlc', 'element14', 'chip1stop', 'future') 'mouser', 'corestaff', 'wpg', 'szlc', 'element14', 'chip1stop', 'future',"nep","cdi",
"nac","richardsonrfpd","pui")
@staticmethod @staticmethod
def get_unexpired_time(plat): def get_unexpired_time(plat):
...@@ -61,6 +68,13 @@ class MongoOperator: ...@@ -61,6 +68,13 @@ class MongoOperator:
expired_query = {'time': {"$gt": ts}} expired_query = {'time': {"$gt": ts}}
return expired_query, total_query return expired_query, total_query
@staticmethod
def get_mongo_query():
stock_query ={"stock.1":{"$lte":0}} #获取库存为零
tiered_query ={"tiered": []} #获取价格阶梯为空
total_query = {}
return stock_query,tiered_query,total_query
def get_platform_data_expired_rate(self): def get_platform_data_expired_rate(self):
msg = '数据过期率监控预警 过去3小时内:\n' msg = '数据过期率监控预警 过去3小时内:\n'
demo = '平台:{} 数据过期率为{:.2f}%' demo = '平台:{} 数据过期率为{:.2f}%'
...@@ -91,3 +105,45 @@ class MongoOperator: ...@@ -91,3 +105,45 @@ class MongoOperator:
return msg return msg
else: else:
return return
def get_platform_none_data_rate(self):
msg = '空数据预警 过去3小时内:\n'
demo1 = '平台:{} 第一次运行,库存空数据率为{:.2f}%,价格空数据率为{:.2f}%'
demo2 = '平台:{} 相比上一次监控库存空数据率变化为{:.2f}%,价格空数据率变化为{:.2f}%'
msgs = []
for plat in self.colls:
coll = self.db[plat]
snq, tnq,tq = self.get_mongo_query()
stock_num = coll.count(snq)
tiered_num = coll.count(tnq)
total = coll.count(tq)
if total > 0 :
stock_rate = stock_num / total * 100
tiered_rate = tiered_num / total * 100
old_stock_rate = glo.get_value(plat)["stock"] if glo.get_value(plat)else 0
old_tiered_rate = glo.get_value(plat)["tiered"] if glo.get_value(plat) else 0
if stock_rate >= 10 or tiered_rate >= 10:
msg_line =""
if old_stock_rate ==0 :
print(plat, "空库存数量", stock_num, "空价格数量", stock_num, "总量", total
, "空库存率", stock_rate, "空价格率", tiered_rate, )
msg_line = demo1.format(plat, stock_rate,tiered_rate)
else:
stock__ontrast_ratio = stock_rate - old_stock_rate
tiered__ontrast_ratio = tiered_rate - old_tiered_rate
if not -10 < stock__ontrast_ratio < 10 or not -10 < tiered__ontrast_ratio < 10 :
msg_line = demo2.format(plat, stock__ontrast_ratio, tiered__ontrast_ratio)
print(plat, "空库存数量", stock_num, "空价格数量", stock_num, "总量", total , "空库存率",
stock_rate, "空价格率", tiered_rate, "空库存变化率", stock__ontrast_ratio,
"空价格变化率", tiered__ontrast_ratio,)
glo.set_value(plat, {"stock":stock_rate,"tiered":tiered_rate})
if msg_line:
msgs.append(msg_line)
msg += msg_line + '\n'
else:
print(plat,"空库存数量",stock_num,"空价格数量",stock_num,"总量",total)
if msgs:
return msg
else:
return
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment