コード例 #1
0
ファイル: utils.py プロジェクト: imfht/flaskapp1
def get_model_schema(model_name):
    cache = Cache()
    models_schema_cache = cache.models_schema_cache
    if models_schema_cache.get(model_name):
        model_schema = models_schema_cache[model_name]
    else:
        from app import schemas

        schema_name = f"{model_name}Schema"
        if hasattr(schemas, schema_name):
            model_schema = getattr(schemas, schema_name)()
            cache.models_schema_cache[model_name] = model_schema
        else:
            model_schema = None
    return model_schema
コード例 #2
0
def handle_action_config(record=None):
    cache = Cache()
    dict_code = cache.dict_code
    action_config = record.get('config')
    action_type = record.get('actionType')
    record['actionTypeLabel'] = dict_code.get('actionType').get(action_type) \
        .get(f'{g.language}Label')

    if action_type == 1:
        alert_severity = action_config.get('alertSeverity')
        severity_label = dict_code.get('alertSeverity').get(alert_severity) \
            .get(f'{g.language}Label')
        action_config['alertSeverityLabel'] = severity_label
    elif action_type == 3 and action_config.get('token'):
        ...
    elif action_type == 4:
        device_uid = action_config.get('deviceID')
        device = db.session.query(Device.deviceName) \
            .filter_tenant(tenant_uid=g.tenant_uid) \
            .filter(Device.deviceID == device_uid) \
            .first()
        if not device:
            raise DataNotFound(field='deviceID')
        action_config['deviceName'] = device.deviceName
    else:
        pass
    return record
コード例 #3
0
ファイル: schemas.py プロジェクト: stevenHewl/ActorCloud
 def validate_region(self, value):
     if value is None:
         return
     cache = Cache()
     dict_code_cache = cache.dict_code
     region_cache = dict_code_cache['region']
     if value not in region_cache.keys():
         raise DataNotFound(field='region')
コード例 #4
0
ファイル: schemas.py プロジェクト: stevenHewl/ActorCloud
 def validate_fcnt_check(self, value):
     if value is None:
         return
     cache = Cache()
     dict_code_cache = cache.dict_code
     fcnt_check_cache = dict_code_cache['fcntCheck']
     if value not in fcnt_check_cache.keys():
         raise DataNotFound(field='fcntCheck')
コード例 #5
0
def _convert_query_message(query_results, x_data):
    message_type_dict = defaultdict(dict)
    for message in query_results:
        msg_time, msg_type, msg_obj = message
        message_type_dict[msg_type][msg_time] = msg_obj
    msg_type_dict_code = Cache().dict_code['msgType']
    msg_types: List[int] = list(msg_type_dict_code.keys())
    records = {}
    query_types = []
    for msg_type, msg_dict in message_type_dict.items():
        y_data = [msg_dict.get(date, 0) for date in x_data]
        if msg_type_dict_code.get(msg_type):
            code_label = msg_type_dict_code[msg_type]['enLabel']
            records[code_label] = {'time': x_data, 'value': y_data}
            query_types.append(msg_type)
    defect_types = set(msg_types) ^ set(query_types)
    for defect_type in defect_types:
        code_label = msg_type_dict_code[defect_type]['enLabel']
        records[code_label] = {'time': x_data, 'value': [0] * len(x_data)}
    return records
コード例 #6
0
ファイル: utils.py プロジェクト: imfht/flaskapp1
def dict_code_label(record: Dict, code_list: List = None):
    """ Convert dict_code """

    cache = Cache()
    dict_code_cache = cache.dict_code
    if not dict_code_cache:
        return record

    for code in code_list:
        if record.get(code) is None or not dict_code_cache.get(code):
            continue
        code_value_dict = dict_code_cache[code]
        code_value = record[code]
        if code_value_dict.get(code_value):
            record[f'{code}Label'] = code_value_dict[code_value].get(
                f'{g.language}Label')
        else:
            record[f'{code}Label'] = None
    return record