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 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 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 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 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 regular_broken_stic(): try: now = datetime.now() before = now - timedelta(days=1) # 一天前 # 查询 在线服务器 search_col = {'state': 1} # 模糊匹配 return_type = {'_id': 0, 'server_ip': 1} mg_data = mongo_session.select_all_collection('server_info', search_col, return_type) for child in mg_data: pipeline = [{ '$match': { 'alarm_time': { '$gte': before, '$lt': now }, 'alarm_craft': { '$in': [9, 11] }, 'server_ip': child['server_ip'] } }, { '$group': { '_id': "$alarm_craft", 'count': { '$sum': 1 } } }, { '$sort': { '_id': 1 } }] broken_stic = mongo_session.aggregate_coolection( 'alarm_info', pipeline) mongo_dict = {} mongo_dict['shoulder'] = 0 mongo_dict['diameter'] = 0 for item in broken_stic: if item['_id'] == 9: mongo_dict['shoulder'] = item['count'] elif item['_id'] == 11: mongo_dict['diameter'] = item['count'] else: pass mongo_dict['date'] = now mongo_dict['update'] = datetime.now() mongo_dict['server_ip'] = child['server_ip'] mongo_session.insert_collection('history_broken', mongo_dict) except Exception as e: logger.error(e) pass return None
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 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 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
def furnace_lists(id: str, series: str, status: str, idx: int, size: int, res: ResponseBase): data = {'fur_list': [], 'total': 0} try: search_col = {} if series != '': search_col['furnace_series'] = series if id != '': search_col['furnace_id'] = int(id) if status != '': search_col['furnace_state'] = int(status) return_type = {'_id': 0} mg_data = mongo_session.select_all_collection('furnace_list', search_col, return_type, sort_col='furnace_id') if len(mg_data) > 0: data['fur_list'] = mg_data data['total'] = len(mg_data) res.data = data except Exception as e: res.error(Error.OPT_ERR) logger.error(e) pass return res
def server_list(count: int, res: ResponseBase): data = {'server_list_r': [], 'server_list_l': []} try: total_server_list = [] search_col = {'state': 1} # 服务器状态可用 return_type = {'_id': 0, 'server_ip': 1, 'alarm': 1, 'server_name': 1} mg_data = mongo_session.select_all_collection('server_info', search_col, return_type, limit_num=count, sort_col='update', sort='desc') for child in mg_data: if child['alarm'] != 0: child['server_state'] = 1 else: child['server_state'] = 0 # 根据server_ip 查找 count pipeline = [{ '$match': { 'server_ip': child['server_ip'] } }, { '$group': { '_id': "$server_ip", 'count': { '$sum': 1 } } }, { '$sort': { '_id': 1 } }] child_data = mongo_session.aggregate_coolection( 'furnace_list', pipeline) l = list(child_data) if len(l) == 0: child['fur_count'] = 0 else: child['fur_count'] = l[0]['count'] total_server_list.append(child) # 补全处理 for i in range(count - len(mg_data)): temp = {} temp['server_ip'] = f'0.0.0.{i}' temp['server_name'] = "" temp['alarm'] = 0 temp['server_state'] = 0 temp['fur_count'] = 0 total_server_list.append(temp) # 拆分处理 median = int(count / 2) data['server_list_l'] = total_server_list[0:median] data['server_list_r'] = total_server_list[median:] res.data = data pass except Exception as e: res.error(Error.SERVER_EXCEPTION) logger.error(e) pass return res