def model_state(server_ip: str, res: ResponseBase): data = {'model_list': []} r_key = f'model_list_{server_ip}' try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: addr = 'http://{}:5000/model_status'.format(server_ip) resp = s_reqs.get(addr, timeout=5) res_dict = resp.json() model_list = [] for key in res_dict: if key in dict_model_index.keys(): model_list.append( RespModelState(key, dict_model_index.get(key), res_dict.get(key)).__dict__) continue model_list.sort(key=lambda x: x['key'], reverse=False) data['model_list'] = model_list if len(model_list) > 0: redis_session.set_redis_str(data, r_key, 30) pass res.data = data except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res.__dict__
def server_list(res: ResponseBase): session = mysql_session.session() data = {'server_list': []} r_key = 'server_list' try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: db_data = session.query( ServerList.server_ip).filter(ServerList.state > 0).all() server_list = [] for i in db_data: server_list.append(i[0]) data['server_list'] = server_list if len(server_list) > 0: redis_session.set_redis_str(data, r_key, 60 * 60 * 24) else: res.code = 1 pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res.__dict__
def shoulder_type_stic(dtype: int, res: ResponseBase): data = {'shoulder_type_list': [], 'total': 0} r_key = f'shoulder_type_list_{dtype}' session = mysql_session.session() try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: shoulder_type_list = [] condition = [] condition.append(ShoulderCraft.gmt_update >= get_startdate(dtype)) db_data = session.query(ShoulderCraft.shoulder_type,func.count('*')).filter(and_(*condition)).group_by(ShoulderCraft.shoulder_type).order_by(ShoulderCraft.shoulder_type).all() for child in db_data: data['total'] += child[1] shoulder_type_list = mysql_init_data(db_data,shoulder_model,CommonListItem) data['shoulder_type_list'] = shoulder_type_list if len(shoulder_type_list) > 0: redis_session.set_redis_str(data,r_key, 1) pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res
def series_list(server_ip: str, res: ResponseBase): data = {'series_list': []} series_list = [] try: pipeline = [ { '$group': { '_id': "$furnace_series", 'count': { '$sum': 1 } } }, { '$sort': { '_id': 1 } }, ] if valid_ip(server_ip): pipeline.insert(0, {'$match': {'server_ip': server_ip}}) mg_data = mongo_session.aggregate_coolection('furnace_list', pipeline) for item in mg_data: series_list.append(item['_id']) data['series_list'] = series_list res.data = data pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res
def get_furnace_lists(res: ResponseBase, id: str, series: str, status: str, idx: int, size: int): session = mysql_session.session() data = CommonList() # r_key = "furnace_lists_{}_{}".format(series, id) r_key = f'furnace_lists_{series}_{id}' try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: # 多条件查询 condition = [] if series != '': condition.append(FurnaceList.furnace_series == series) if id != '': condition.append(FurnaceList.furnace_id == int(id)) if status != '': condition.append(FurnaceList.furnace_state == int(status)) db_data = session.query(FurnaceList).filter(and_(*condition)).all() for i in db_data: re = RespFurnaceList(i).__dict__ data.list.append(re) data.total = len(db_data) if len(data.list) > 0: redis_session.set_redis_str(data.__dict__, r_key, 60) pass res.data = data except Exception as e: res.error(Error.OPTION_ERR) logger.error(e) pass session.close() # 关闭session return res
def temp_std(dtype: int, res: ResponseBase): data = {'temp_std_list': [],'total':0} r_key = f'temp_std_list_{dtype}' session = mysql_session.session() try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: temp_std_list = [] condition = [] condition.append(TempCraft.gmt_update >= get_startdate(dtype)) db_data = session.query(TempCraft.weld_std,func.count('*')).filter(and_(*condition)).group_by(TempCraft.weld_std).order_by(TempCraft.weld_std).all() for child in db_data: data['total'] += child[1] std_dict = {'0':'控制不达标','1':'控制达标'} temp_std_list = mysql_init_data(db_data,std_dict,CommonListItem) data['temp_std_list'] = temp_std_list if len(temp_std_list) > 0: redis_session.set_redis_str(data,r_key, gr_sec(0)) pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res
def get_server_lists(res: ResponseBase, ipt: str, idx: int, size: int): session = mysql_session.session() data = CommonList() r_key = "server_lists_" + ipt try: if redis_session.exists(r_key): # data = redis_session.hash2obj(data.__dict__, r_key) data = redis_session.get_redis_str(r_key) pass else: ipt = '%{}%'.format(ipt) db_data = session.query(ServerList).filter( and_(ServerList.server_ip.like(ipt), ServerList.state > 0)).all() for i in db_data: re = RespServerList(i).__dict__ data.list.append(re) data.total = len(db_data) if len(data.list) > 0: # redis_session.set_redis(data.__dict__, r_key, 60*60) redis_session.set_redis_str(data.__dict__, r_key, 60 * 60) pass res.data = data except Exception as e: res.error(Error.OPTION_ERR) logger.error(e) pass session.close() # 关闭session return res
def login(item: ReqLogin, res: ResponseBase): # denglu data = {'token': '', 'account': '', 'type': 0} try: search_col = {'username': item.username, 'state': 1} user_dict = mongo_session.select_one_collection( 'user_info', search_col) if user_dict == None: res.error(Error.PARAM_ERR, err_msg="用户不存在") return res if user_dict['password'] != item.password: res.error(Error.PARAM_ERR, err_msg="密码错误") return res # 成功 更新登录时间 user_dict['login_time'] = datetime.now() mongo_session.save_collection('user_info', user_dict) # 生成token token = get_token(item.username) data['token'] = token data['account'] = user_dict['username'] data['type'] = user_dict['type'] print(data) if user_dict['type'] == 1: data['server_ip'] = user_dict['server_ip'] # token存入 redis redis_session.set(token, item.username, 60 * 60) res.msg = "登录成功" res.data = data pass except Exception as e: res.error(Error.OPT_ERR) logger.error(e) pass return res
def user_list(value: str, res: ResponseBase): data = {'user_list': [], 'total': 0} try: search_col = {'username': {'$regex': f'{value}'}, 'state': 1} # 模糊匹配 return_type = { '_id': 0, 'username': 1, 'login_time': 1, 'type': 1, 'state': 1 } mg_data = mongo_session.select_all_collection('user_info', search_col, return_type, sort_col='update', sort='desc') if len(mg_data) > 0: data['user_list'] = mg_data data['total'] = len(mg_data) res.data = data pass except Exception as e: res.error(Error.OPT_ERR) logger.error(e) pass return res
def temp_type_stic(dtype: int, res: ResponseBase): data = {'temp_type_list': [],'total':0} r_key = f'temp_type_list_{dtype}' session = mysql_session.session() try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: temp_type_list = [] condition = [] condition.append(TempCraft.gmt_update >= get_startdate(dtype)) db_data = session.query(TempCraft.weld_type,func.count('*')).filter(and_(*condition)).group_by(TempCraft.weld_type).order_by(TempCraft.weld_type).all() for child in db_data: data['total'] += child[1] # tm_keys_list = list(temp_model.keys()) # temp_keys_list = [] # for item in db_data: # temp_keys_list.append(f'{item[0]}') # temp_type_list.append(CommonListItem(temp_model[f'{item[0]}'],item[1]).__dict__) # d_set = sort(list(set(tm_keys_list).difference(set(temp_keys_list)))) # for i in d_set: # temp_type_list.insert(tm_keys_list.index(i),CommonListItem(temp_model[f'{i}'],0).__dict__) temp_type_list = mysql_init_data(db_data,temp_model,CommonListItem) data['temp_type_list'] = temp_type_list if len(temp_type_list) > 0: redis_session.set_redis_str(data,r_key, gr_sec(0)) pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res
def shoulder_pd_dist(dtype: int,res: ResponseBase): data = {'shoulder_pd_list': []} r_key = f'shoulder_pd_list_{dtype}' session = mysql_session.session() try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: # 查询数据库 condition = [] condition.append(ShoulderCraft.gmt_update >= get_startdate(dtype)) db_data = session.query(ShoulderCraft.shoulder_powerdec).filter(and_(*condition)).all() shoulder_pd_list = [] if len(db_data)>0: l = np.array(db_data)[:,0] cso = CommonSticOp(l) cso.get_dist(5) for item in cso.result: shoulder_pd_list.append(CommonListItem(item[0],item[1]).__dict__) data['shoulder_pd_list'] = shoulder_pd_list if len(shoulder_pd_list) > 0: redis_session.set_redis_str(data,r_key, 1) pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res
def current_fur_list(series: str, res: ResponseBase): session = mysql_session.session() data = {'fur_list': [], 'series': ''} r_key = f'current_fur_list_{series}' try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: db_data = session.query( FurnaceList.furnace_id, FurnaceList.furnace_state).filter( FurnaceList.furnace_series == series).order_by( FurnaceList.furnace_id).all() fur_list = [] if len(db_data) > 0: for i in db_data: fur_list.append( CurrentFurList(series + str(i[0]), i[1]).__dict__) data['fur_list'] = fur_list data['series'] = series if len(fur_list) > 0: redis_session.set_redis_str(data, r_key, 30) pass else: res.error(Error.NO_DATA) pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res.__dict__
def broken_info(date: datetime, craft: str, res: ResponseBase): data = {'broken_list': []} try: search_col = { 'alarm_time': { '$gte': date, '$lt': date + timedelta(days=1) } } if craft == '': search_col['alarm_craft'] = {'$in': [9, 11]} pass else: search_col['alarm_craft'] = int(craft) pass return_type = {'_id': 0, 'update': 0} mg_data = mongo_session.select_all_collection('alarm_info', search_col, return_type, sort_col='update', sort='desc') if len(mg_data) > 0: data['broken_list'] = mg_data data['total'] = len(mg_data) res.data = data except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res
def online_fur(server_ip: str, res: ResponseBase): data = {'online_list': []} try: pipeline = [{ '$match': { 'furnace_state': { '$in': [4, 5, 9, 11, 12, 20, 28, 29] }, 'online': 1, 'server_ip': server_ip } }, { '$group': { '_id': "$furnace_state", 'count': { '$sum': 1 } } }, { '$sort': { '_id': 1 } }] mg_data = mongo_session.aggregate_coolection('furnace_list', pipeline) data['online_list'], data['total'] = mongo_init_data( mg_data, dict_model, CommonListItem) pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass res.data = data return res
def craft_off_prop(dtype: int,craft: str,res: ResponseBase): data = {'seed_off':0,'seed_total':0,'shoulder_off':0,'shoulder_total':0} r_key = f'craft_off_{craft}_{dtype}' session = mysql_session.session() try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: # 查询数据库 condition = [] db_data = [] if craft == 'shoulder': condition.append(ShoulderCraft.gmt_update >= get_startdate(dtype)) db_data = session.query(ShoulderCraft.shoulder_off,func.count('*')).filter(and_(*condition)).group_by(ShoulderCraft.shoulder_off).order_by(ShoulderCraft.shoulder_off).all() if len(db_data)>0: l = np.array(db_data)[:,1] data['shoulder_off'] = int(l[1]) data['shoulder_total'] = int(l[0] + l[1]) if craft == 'seed': condition.append(SeedCraft.gmt_update >= get_startdate(dtype)) db_data = session.query(SeedCraft.seed_off,func.count('*')).filter(and_(*condition)).group_by(SeedCraft.seed_off).order_by(SeedCraft.seed_off).all() if len(db_data)>0: l = np.array(db_data)[:,1] data['seed_off'] = int(l[1]) data['seed_total'] = int(l[0] + l[1]) except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res
def history_broken(days: int, server_ip: str, res: ResponseBase): data = {'broken_list': []} try: broken_list = [] search_col = { 'date': { '$gte': datetime.today() - timedelta(days) }, 'server_ip': server_ip } return_type = {'_id': 0, 'update': 0} mg_data = mongo_session.select_all_collection('history_broken', search_col, return_type, sort_col='date') for child in mg_data: date = child['date'].strftime("%Y-%m-%d") broken_list.append( GroupListItem('等径', date, child['diameter']).__dict__) broken_list.append( GroupListItem('放肩', date, child['shoulder']).__dict__) data['broken_list'] = broken_list res.data = data except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res
def server_state(server_ip: str, res: ResponseBase): data = {'cpu_info': {}, 'memory_info': {}, 'disk_info': {}, 'gpu_info': []} try: if redis_session.exists(server_ip) == 0: # 不存在 res.error(Error.NO_DATA) return res h1 = redis_session.hget(server_ip, 'cpu_info') if h1: data['cpu_info'] = json.loads(h1) pass h2 = redis_session.hget(server_ip, 'memory_info') if h2: data['memory_info'] = json.loads(h2) pass h3 = redis_session.hget(server_ip, 'gpu_info') if h3: data['gpu_info'] = json.loads(h3) pass h4 = redis_session.hget(server_ip, 'disk_info') if h4: data['disk_info'] = json.loads(h4) pass res.data = data except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res
def alarm_info_list(fur_series: str, fur_id: str, alarm_func: str, res: ResponseBase): data = {'alarm_info_list': [], 'total': 0} try: # search_col = {'username':{'$regex':f'{value}'},'state':1} # 模糊匹配 search_col = {} if fur_series != '': search_col['fur_series'] = fur_series if fur_id != '': search_col['fur_id'] = int(fur_id) if alarm_func != '': search_col['alarm_func'] = alarm_func return_type = {'_id': 0, 'update': 0} mg_data = mongo_session.select_all_collection('alarm_info', search_col, return_type, sort_col='alarm_time', sort='desc') if len(mg_data) > 0: data['alarm_info_list'] = mg_data data['total'] = len(mg_data) res.data = data pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res
def series_list(res: ResponseBase): session = mysql_session.session() data = {'series_list': []} r_key = 'series_list' try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: db_data = session.query(FurnaceList.furnace_series, func.count('*').label("count")).group_by( FurnaceList.furnace_series).all() series_list = [] for i in db_data: series_list.append(i[0]) series_list.sort(key=None, reverse=False) data['series_list'] = series_list if len(series_list) > 0: redis_session.set_redis_str(data, r_key, 60 * 60 * 24) pass pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res.__dict__
def fur_result(furnace_id: str, img_idx: str, furnace_state: str, model_name: str, res: ResponseBase): session = mysql_session.session() # r_key = 'fur_result_{}_{}'.format(furnace_id, img_idx) # 不做缓存 try: # if r.exists(r_key): # data = {'img_origin': '', 'img_detection': '','final_rst':'','img_nums':''} # res.data = hash2obj(data, r_key) # pass # 根据furnace_id寻找 A1 服务器地址 # else: series = furnace_id[0] id = furnace_id[1:] db_data = session.query(FurnaceList.server_ip).filter( FurnaceList.furnace_id == id, FurnaceList.furnace_series == series).first() server_ip = db_data[0] addr = '' if img_idx == '': addr = 'http://{}:5000/furnace_detection_first?device_id={}&device_state={}&model_name={}'.format( server_ip, furnace_id, furnace_state, model_name) else: addr = 'http://{}:5000/furnace_detection?device_id={}&img_idx={}&device_state={}&model_name={}'.format( server_ip, furnace_id, img_idx, furnace_state, model_name) resp = s_reqs.get(addr, timeout=5).json() res.data = resp # set_redis(resp, r_key, 60) pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() return res.__dict__
def current_fur_list(series: str, server_ip: str, res: ResponseBase): data = {'fur_list': [], 'series': series} fur_list = [] try: search_col = { 'furnace_series': series, 'server_ip': server_ip, 'online': 1 } return_type = {'_id': 0, 'update': 0, 'server_ip': 0} mg_data = mongo_session.select_all_collection('furnace_list', search_col, return_type, sort_col='furnace_id') if len(mg_data) > 0: for item in mg_data: child = {} child['s'] = series child['id'] = item["furnace_id"] child['name'] = f'{series}{item["furnace_id"]}' child['state'] = item["furnace_state"] fur_list.append(child) data['fur_list'] = fur_list else: res.error(Error.NO_DATA) pass res.data = data except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res
def shoulder_wt_dist(dtype: int, res:ResponseBase): data = {'shoulder_wt_list': [], 'mean':0, 'total':0} r_key = f'shoulder_wt_list_{dtype}' session = mysql_session.session() try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: # 查询数据库 condition = [] condition.append(ShoulderCraft.gmt_update >= get_startdate(dtype)) db_data = session.query(ShoulderCraft.shoulder_wt).filter(and_(*condition)).all() shoulder_wt_list = [] if len(db_data)>0: l = np.array(db_data)[:,0] data['mean'] = round(np.mean(l),4) data['total'] = len(l) # for key,value in interval_static(l).items(): # shoulder_wt_list.append(CommonFitListItem(key,value,0).__dict__) cso = CommonSticOp(l) cso.get_dist_fit() for item in cso.result: shoulder_wt_list.append(CommonFitListItem(item[0],item[1],round(item[2],4)).__dict__) data['shoulder_wt_list'] = shoulder_wt_list if len(shoulder_wt_list) > 0: redis_session.set_redis_str(data,r_key, 1) pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res
async def find_course_selective(current_user: User = Depends(get_current_active_user), request: FindCourseListRequest = Body(None, title="课程筛选条件")): ''' 这是查找课程列表的接口,可以根据id,名称,科目去筛选 ''' sql_exec = find_course_selective_sql_append(request) result = sql_helper.fetch_all2(sql_exec) responseVo = ResponseBase() responseVo.data = {"courses": result} return responseVo
def model_state(server_ip: str, res: ResponseBase): data = {'model_list': []} try: if redis_session.exists(server_ip) == 0: res.error(Error.NO_DATA) return res h = redis_session.hget(server_ip, 'model_list') if h: data['model_list'] = json.loads(h) pass res.data = data except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res
def single_seed_history_lates(furnace_id, res: ResponseBase): data = {'single_seed_lates':[]} try: single_seed_lates = [] search_col = {'craft':'seed','gmt_update':{'$gte':datetime.today()-timedelta(days=30)}} return_type = {'_id':0,'gmt_update':1,'seed_lates':1} mg_data = mongo_session.select_all_collection(f'{furnace_id}_craft',search_col,return_type,sort_col='gmt_update') for item in mg_data: date = item['gmt_update'].strftime("%m-%d %H:%M") value = item['seed_lates'] single_seed_lates.append(CommonListItem(date,value).__dict__) data['single_seed_lates'] = single_seed_lates except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass res.data = data return res
def history_broken(type: int, res: ResponseBase): session = mysql_session.session() data = {'broken_list': []} r_key = f'history_broken_{type}' try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: dt_ago = (datetime.now() - timedelta(days=30)).date() if type == '1': # shouldering db_data = session.query( BrokenHistoryResult.date, func.sum( BrokenHistoryResult.shouldering_broken_nums).label( "count")).filter( BrokenHistoryResult.date >= dt_ago).group_by( BrokenHistoryResult.date).order_by( BrokenHistoryResult.date).all() elif type == '2': db_data = session.query( BrokenHistoryResult.date, func.sum(BrokenHistoryResult.diameter_broken_nums).label( "count")).filter( BrokenHistoryResult.date >= dt_ago).group_by( BrokenHistoryResult.date).order_by( BrokenHistoryResult.date).all() else: db_data = [] pass broken_list = [] for i in db_data: broken_list.append( CommonListItem(str(i[0]), int(i[1])).__dict__) data['broken_list'] = broken_list if len(broken_list) > 0: redis_session.set_redis_str(data, r_key, 60 * 60 * 2) except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res.__dict__
def alarm_info_simplify(count, res: ResponseBase): data = {'alarm_info_list': []} try: search_col = {} return_type = {'_id': 0, 'update': 0} mg_data = mongo_session.select_all_collection('alarm_info', search_col, return_type, limit_num=count, sort_col='alarm_time', sort='desc') if len(mg_data) > 0: data['alarm_info_list'] = mg_data data['total'] = len(mg_data) res.data = data pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res
def seed_type_stic(dtype: int, res: ResponseBase): data = {'seed_type_list': [], 'total':0} r_key = f'seed_type_list_{dtype}' session = mysql_session.session() try: if redis_session.exists(r_key): data = redis_session.get_redis_str(r_key) pass else: seed_type_list = [] condition = [] condition.append(SeedCraft.gmt_update >= get_startdate(dtype)) condition.append(SeedCraft.seed_type <= 4) db_data = session.query(SeedCraft.seed_type,func.count('*')).filter(and_(*condition)).group_by(SeedCraft.seed_type).order_by(SeedCraft.seed_type).all() for child in db_data: data['total'] += child[1] # db_data = session.query(SeedCraft.seed_type,func.count(case(whens=((SeedCraft.seed_type.in_([1,2,3,4]),1),),else_=0))).filter(and_(*condition)).group_by(SeedCraft.seed_type).all() # sm_keys_list = list(seed_model.keys()) # temp_keys_list = [] # for item in db_data: # temp_keys_list.append(f'{item[0]}') # seed_type_list.append(CommonListItem(seed_model[f'{item[0]}'],item[1]).__dict__) # # 初始化未添加的内容 # d_map = map(int,list(set(sm_keys_list).difference(set(temp_keys_list)))) # d_set = sorted(list(d_map)) # for i in d_set: # seed_type_list.insert(sm_keys_list.index(f'{i}'),CommonListItem(seed_model[f'{i}'],0).__dict__) seed_type_list = mysql_init_data(db_data,seed_model,CommonListItem) data['seed_type_list'] = seed_type_list if len(seed_type_list) > 0: redis_session.set_redis_str(data,r_key, 60) pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass session.close() res.data = data return res
def fur_result(furnace_series: str, furnace_id: str, device_state: str, model_name: str, res: ResponseBase): try: data = {'img_list': []} search_col = { 'furnace_id': int(furnace_id), 'furnace_series': furnace_series } mongo_dict = mongo_session.select_one_collection( 'furnace_list', search_col) if mongo_dict == None: raise Exception('furnace is not exist') server_ip = mongo_dict.get('server_ip', '127.0.0.1') device_id = furnace_series + furnace_id addr = f'http://{server_ip}:5000/furnace_realtime_detection?device_id={device_id}&device_state={device_state}&model_name={model_name}' resp = s_reqs.get(addr, timeout=1).json() res.data = resp pass except Exception as e: res.error(Error.SERVER_EXCEPTION, e.__str__()) logger.error(e) pass return res
def shoulder_history_stdr(res: ResponseBase): data = {'shoulder_stdr_list':[]} try: shoulder_stdr_list = [] search_col = {'date':{'$gte':datetime.today()-timedelta(days=30)},'craft':'shoulder'} return_type = {'_id':0,'craft':0} mg_data = mongo_session.select_all_collection('std_stic',search_col,return_type,sort_col='date') for item in mg_data: date = item['date'].strftime("%m-%d") total = item['std'] + item['std_o'] value = 0 if total != 0: value = round(item['std']/total,4) shoulder_stdr_list.append(CommonListItem(date,value*100).__dict__) data['shoulder_stdr_list'] = shoulder_stdr_list pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass res.data = data return res