Commit 8911f4dc by lichenggang

update pep8

parent 2d8a3116
Showing with 23 additions and 28 deletions
......@@ -58,10 +58,11 @@ def task_running_flag_monitor():
dd_send_msg(traceback.format_exc())
time.sleep(60 * 5)
def mongo_none_data_rate_monitor():
while True:
try:
msg = mongo.get_platform_none_data_rate ()
msg = mongo.get_platform_none_data_rate()
if msg:
logger.info(msg)
dd_send_msg(msg)
......@@ -71,6 +72,7 @@ def mongo_none_data_rate_monitor():
dd_send_msg(traceback.format_exc())
time.sleep(60 * 5)
def main():
thread_monitor1 = threading.Thread(target=task_fail_rate_monitor)
thread_monitor1.start()
......
......@@ -5,14 +5,13 @@ class Glo():
global _global_dict
_global_dict = {}
def set_value(self,key,value):
def set_value(self, key, value):
_global_dict[key] = value
def get_value(self,key):
def get_value(self, key):
try:
return _global_dict[key]
except KeyError:
return None
\ No newline at end of file
return None
......@@ -7,7 +7,7 @@ import pymongo
from utils.glo import Glo
from urllib.parse import quote_plus
glo =Glo()
glo = Glo()
MG_HOST_SET = {
'test': '192.168.1.237',
......@@ -41,10 +41,8 @@ class MongoOperator:
# element14 chip1stop ti
self.colls = ('alliedelec', 'arrow', 'avnet', 'buerklin', 'digikey', 'master', 'rs', 'rochester',
'verical', "powell", 'microchip', 'tme', 'heilind', 'maxim', 'aipco', 'company', 'rutronik',
'mouser', 'corestaff', 'wpg', 'szlc', 'element14', 'chip1stop', 'future',"nep","cdi",
"nac","richardsonrfpd","pui")
'mouser', 'corestaff', 'wpg', 'szlc', 'element14', 'chip1stop', 'future', "nep", "cdi",
"nac", "richardsonrfpd", "pui")
@staticmethod
def get_unexpired_time(plat):
......@@ -70,10 +68,10 @@ class MongoOperator:
@staticmethod
def get_mongo_query():
stock_query ={"stock.1":{"$lte":0}} #获取库存为零
tiered_query ={"tiered": []} #获取价格阶梯为空
stock_query = {"stock.1": {"$lte": 0}} # 获取库存为零
tiered_query = {"tiered": []} # 获取价格阶梯为空
total_query = {}
return stock_query,tiered_query,total_query
return stock_query, tiered_query, total_query
def get_platform_data_expired_rate(self):
msg = '数据过期率监控预警 过去3小时内:\n'
......@@ -113,37 +111,35 @@ class MongoOperator:
msgs = []
for plat in self.colls:
coll = self.db[plat]
snq, tnq,tq = self.get_mongo_query()
snq, tnq, tq = self.get_mongo_query()
stock_num = coll.count(snq)
tiered_num = coll.count(tnq)
total = coll.count(tq)
if total > 0 :
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_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 :
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)
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 :
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 , "空库存率",
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})
"空价格变化率", 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)
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