Example #1
0
def fur_state(item: ReqUpdateFurState, res: ResponseBase, host: str):
    session = mysql_session.session()
    try:
        data = session.query(FurnaceList).filter(
            FurnaceList.furnace_id == item.furnace_id,
            FurnaceList.furnace_series == item.furnace_series).first()
        if data == None:
            fl = FurnaceList()
            fl.gmt_create = datetime.now()
            fl.setData(item, host)
            session.add(fl)
            session.commit()
            res.succ()
            pass
        else:
            data.setData(item, host)
            session.commit()
            res.succ()
            pass

    except Exception as e:
        res.error(Error.OPT_ERR)
        logger.error(e)
        pass
    session.close()
    return res.__dict__
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
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
Example #7
0
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
Example #8
0
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
Example #9
0
def up_server(admin: str, item: ReqUpdateServer, res: ResponseBase):
    try:
        admin_col = {'username': admin}
        admin = mongo_session.select_one_collection('user_info', admin_col)
        if admin['type'] != 0:
            res.error(Error.NO_AUTH)
            return res
        search_col = {'server_ip': item.server_ip}
        mongo_dict = mongo_session.select_one_collection(
            'server_info', search_col)
        if mongo_dict == None:
            mongo_dict = {}
        mongo_dict['server_ip'] = item.server_ip
        mongo_dict['server_name'] = item.server_name
        mongo_dict['update'] = datetime.now()
        if item.operation == 0:  # 新增
            mongo_dict['alarm'] = 0
            mongo_dict['state'] = 1
            pass
        elif item.operation == 2:  # 删除
            mongo_dict['state'] = 0
            pass
        else:
            pass
        mongo_session.save_collection('server_info', mongo_dict)
        res.succ()
        pass
    except Exception as e:
        res.error(Error.OPT_ERR)
        logger.error(e)
        pass
    return res
Example #10
0
def up_history_broken(item: ReqUpdateHistoryBroken, res: ResponseBase,
                      host: str):
    session = mysql_session.session()
    try:
        data = session.query(BrokenHistoryResult).filter(
            and_(BrokenHistoryResult.date == item.date,
                 BrokenHistoryResult.server_ip == host)).first()
        if data == None:
            bhr = BrokenHistoryResult()
            bhr.gmt_update = datetime.now()
            bhr.setData(item, host)
            session.add(bhr)
            session.commit()
            res.succ()
            pass
        else:
            data.setData(item, host)
            session.commit()
            res.succ()
            pass
    except Exception as e:
        res.error(Error.OPT_ERR)
        logger.error(e)
        pass
    # 删除相关缓存
    scan = redis_session.scan(match='history_broken*')
    for i in scan[1]:
        redis_session.delete(i)
    session.close()
    return res.__dict__
Example #11
0
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__
Example #12
0
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__
Example #13
0
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__
Example #14
0
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__
Example #15
0
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
Example #16
0
async def modify_server(item: ReqModifyServer):
    res = ResponseBase()
    if valid_ip(item.server_ip):
        mod_server(item, res)
    else:
        res.error(Error.PARAM_ERR)
    return res
Example #17
0
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
Example #18
0
def mod_server(item: ReqModifyServer, res: ResponseBase):
    session = mysql_session.session()
    try:
        # 删除相关缓存
        scan = redis_session.scan(match='server_list*')
        for i in scan[1]:
            redis_session.delete(i)
        data = session.query(ServerList).filter(
            ServerList.server_ip == item.server_ip).first()
        if data == None:
            sl = ServerList()
            sl.gmt_create = datetime.now()
            sl.setData(item)
            session.add(sl)
            session.commit()
            res.succ()
            pass
        else:
            data.setData(item)
            session.commit()
            res.succ()
            pass
    except Exception as e:
        res.error(Error.OPTION_ERR)
        logger.error(e)
        pass
    session.close()  # 关闭session
    return res
Example #19
0
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
Example #20
0
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
Example #21
0
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
Example #22
0
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
Example #23
0
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
Example #24
0
async def get_shoulder_dvt_dist(dvt: str = '',type: int = 2):
    res = ResponseBase()
    if dvt in ['l','d']:
        shoulder_dvt_dist(dvt,type,res)
    else:
        res.error(Error.PARAM_ERR)
    return res
Example #25
0
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
Example #26
0
async def get_craft_off_prop(type: int = 1,craft = ''):
    res = ResponseBase()
    if craft in ['seed','shoulder']:
        craft_off_prop(type,craft,res)
    else:
        res.error(Error.PARAM_ERR)
    return res
Example #27
0
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
Example #28
0
async def get_single_seed_history_lates(furnace_id: str = ''):
    res = ResponseBase()
    if furnace_id:
        single_seed_history_lates(furnace_id,res)
    else:
        res.error(Error.PARAM_ERR)
    return res
Example #29
0
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__
Example #30
0
async def get_model_state():
    res = ResponseBase()
    server_ip = request.args.get('server_ip', '')
    if valid_ip(server_ip):
        model_state(server_ip, res)
    else:
        res.error(Error.PARAM_ERR)
    return res.__dict__