Exemplo n.º 1
0
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
Exemplo n.º 2
0
def up_seed_process(item: ReqSeedProcess, res: ResponseBase):
  session = mysql_session.session()
  try:
    sc = SeedCraft()
    sc.setData(item)
    session.add(sc)
    session.commit()
    mongo_session.insert_collection(f'{sc.furnace_id}_craft',sc.chg2mongo())
    res.succ()
    pass
    
  except Exception as e:
    res.error(Error.OPT_ERR)
    logger.error(e)
    pass
  session.close()
  return res
Exemplo n.º 3
0
def up_temp_process(item: ReqTempProcess, res: ResponseBase):
  # 更新 数据
  session = mysql_session.session()
  try:
    tc = TempCraft()
    tc.setData(item)
    session.add(tc)
    session.commit()
    mongo_session.insert_collection(f'{tc.furnace_id}_craft',tc.chg2mongo())
    res.succ()
    pass
  except Exception as e:
    res.error(Error.OPT_ERR)
    logger.error(e)
    pass
  session.close()
  return res
Exemplo n.º 4
0
def up_cyl_process(item: ReqCylProcess, res: ResponseBase):
  session = mysql_session.session()
  # 更新 数据
  try:
    # 保存数据库 mysql
    cc = CylCraft()
    cc.setData(item)
    session.add(cc)
    session.commit()
    mongo_session.insert_collection(f'{cc.furnace_id}_craft',cc.chg2mongo())
    res.succ()
    pass  
  except Exception as e:
    res.error(Error.OPT_ERR)
    logger.error(e)
    pass
  session.close()
  return res
Exemplo n.º 5
0
def up_shoulder_process(item: ReqShoulderProcess, res: ResponseBase):
  session = mysql_session.session()
  # 更新 数据
  try:
    # 保存数据库 mysql
    shc = ShoulderCraft()
    shc.setData(item)
    session.add(shc)
    session.commit()
    mongo_session.insert_collection(f'{shc.furnace_id}_craft',shc.chg2mongo())
    res.succ()
    pass
    
  except Exception as e:
    res.error(Error.OPT_ERR)
    logger.error(e)
    pass
  session.close()
  return res
Exemplo n.º 6
0
def regular_std_stic():
    session = mysql_session.session()
    try:
        print('wc')
        # 查询数据库 当天的数据
        now = datetime.now()
        before = now - timedelta(days=1)  # 一天前
        # save_time = now - timedelta(minutes=10)

        cdt_weld = []
        cdt_weld.append(TempCraft.gmt_update >= before)
        cdt_weld.append(TempCraft.gmt_update < now)
        db_weld = session.query(TempCraft.weld_std, func.count('*')).filter(
            and_(*cdt_weld)).group_by(TempCraft.weld_std).all()
        mg_weld_obj = CommonStd(now, 'weld')
        for item in db_weld:
            if item[0] == 0: mg_weld_obj.std_o = item[1]
            elif item[0] == 1: mg_weld_obj.std = item[1]
            else: pass
        # 更新
        logger.error('update_weld', mg_weld_obj.__dict__)
        mongo_session.insert_collection('std_stic', mg_weld_obj.__dict__)

        cdt_seed = []
        cdt_seed.append(SeedCraft.gmt_update >= before)
        cdt_seed.append(SeedCraft.gmt_update < now)
        db_seed = session.query(SeedCraft.seed_std, func.count('*')).filter(
            and_(*cdt_seed)).group_by(SeedCraft.seed_std).all()
        mg_seed_obj = SeedStd(now, 'seed')
        for item in db_seed:
            if item[0] == 1: mg_seed_obj.std = item[1]
            elif item[0] == 2: mg_seed_obj.l_o = item[1]
            elif item[0] == 3: mg_seed_obj.s_o = item[1]
            elif item[0] == 4: mg_seed_obj.b_o = item[1]
            else: pass
        # 更新
        logger.error('update_seed', mg_seed_obj.__dict__)
        mongo_session.insert_collection('std_stic', mg_seed_obj.__dict__)

        cdt_shoulder = []
        cdt_shoulder.append(ShoulderCraft.gmt_update >= before)
        cdt_shoulder.append(ShoulderCraft.gmt_update < now)
        db_shoulder = session.query(ShoulderCraft.shoulder_std,
                                    func.count('*')).filter(
                                        and_(*cdt_shoulder)).group_by(
                                            ShoulderCraft.shoulder_std).all()
        mg_shoulder_obj = CommonStd(now, 'shoulder')
        for item in db_shoulder:
            if item[0] == 0: mg_shoulder_obj.std_o = item[1]
            elif item[0] == 1: mg_shoulder_obj.std = item[1]
            else: pass
        # 更新
        logger.error('update_shoulder', mg_shoulder_obj.__dict__)
        mongo_session.insert_collection('std_stic', mg_shoulder_obj.__dict__)

    except Exception as e:
        logger.error(e)
        pass
    session.close()
    return None
Exemplo n.º 7
0
def up_alarm_info(item: ReqUpAlarmInfo, res: ResponseBase):
    try:
        mongo_dict = {}
        redis_session.incr('alarm_info_index')
        index = redis_session.get('alarm_info_index')
        mongo_dict['index'] = int(index)
        mongo_dict['update'] = datetime.now()
        mongo_dict['fur_series'] = item.fur_series
        mongo_dict['fur_id'] = item.fur_id
        mongo_dict['alarm_time'] = item.alarm_time
        mongo_dict['alarm_craft'] = item.alarm_craft
        mongo_dict['alarm_func'] = item.alarm_func
        mongo_dict['alarm_result'] = item.alarm_result
        mongo_dict['server_ip'] = item.server_ip
        mongo_session.insert_collection('alarm_info', mongo_dict)
        res.succ()
        pass
    except Exception as e:
        res.error(Error.OPT_ERR)
        logger.error(e)
        pass
    return res
Exemplo n.º 8
0
def regular_std_stic():
    try:
        # 查询数据库 当天的数据
        now = datetime.now()
        before = now - timedelta(days=1)  # 一天前
        # save_time = now - timedelta(minutes=10)
        cdt_weld = [{
            '$match': {
                'update': {
                    '$gte': before,
                    '$lt': now
                }
            }
        }, {
            '$group': {
                '_id': "$weld_std",
                'count': {
                    '$sum': 1
                }
            }
        }, {
            '$sort': {
                '_id': 1
            }
        }]
        mg_weld = mongo_session.aggregate_coolection('weld_craft', cdt_weld)
        mg_weld_obj = CommonStd(now, 'weld')
        for item in mg_weld:
            if item['_id'] == 0: mg_weld_obj.std_o = item['count']
            elif item['_id'] == 1: mg_weld_obj.std = item['count']
            else: pass
        # cdt_weld = []
        # cdt_weld.append(TempCraft.gmt_update >= before)
        # cdt_weld.append(TempCraft.gmt_update < now)
        # db_weld = session.query(TempCraft.weld_std,func.count('*')).filter(and_(*cdt_weld)).group_by(TempCraft.weld_std).all()
        # mg_weld_obj = CommonStd(now,'weld')
        # for item in db_weld:
        #     if item[0] == 0: mg_weld_obj.std_o = item[1]
        #     elif item[0] == 1: mg_weld_obj.std = item[1]
        #     else: pass
        # 更新
        logger.error('update_weld', mg_weld_obj.__dict__)
        mongo_session.insert_collection('std_stic', mg_weld_obj.__dict__)

        cdt_seed = [{
            '$match': {
                'update': {
                    '$gte': before,
                    '$lt': now
                }
            }
        }, {
            '$group': {
                '_id': "$seed_std",
                'count': {
                    '$sum': 1
                }
            }
        }, {
            '$sort': {
                '_id': 1
            }
        }]
        mg_seed = mongo_session.aggregate_coolection('seed_craft', cdt_seed)
        mg_seed_obj = SeedStd(now, 'seed')
        for item in mg_seed:
            if item['_id'] == 1: mg_seed_obj.std = item['count']
            elif item['_id'] == 2: mg_seed_obj.l_o = item['count']
            elif item['_id'] == 3: mg_seed_obj.s_o = item['count']
            elif item['_id'] == 4: mg_seed_obj.b_o = item['count']
            else: pass
        logger.error('update_seed', mg_seed_obj.__dict__)
        mongo_session.insert_collection('std_stic', mg_seed_obj.__dict__)

        cdt_shoulder = [{
            '$match': {
                'update': {
                    '$gte': before,
                    '$lt': now
                }
            }
        }, {
            '$group': {
                '_id': "$seed_std",
                'count': {
                    '$sum': 1
                }
            }
        }, {
            '$sort': {
                '_id': 1
            }
        }]
        mg_shoulder = mongo_session.aggregate_coolection(
            'shoulder_craft', cdt_shoulder)
        mg_shoulder_obj = CommonStd(now, 'shoulder')
        for item in mg_shoulder:
            if item['_id'] == 0: mg_shoulder_obj.std_o = item[1]
            elif item['_id'] == 1: mg_shoulder_obj.std = item[1]
            else: pass
        logger.error('update_seed', mg_shoulder_obj.__dict__)
        mongo_session.insert_collection('std_stic', mg_shoulder_obj.__dict__)

    except Exception as e:
        logger.error(e)
        pass
    return None