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 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 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