示例#1
0
def get_configure_by_name(name):
    """根据配置名获取配置值"""
    val = cache.get_hash('configure', name)
    if val is None:
        val = Configure.objects.get(name=name).val
        cache.set_hash('configure', name, val)
    return val
示例#2
0
def get_meter_flow_data(meter_id):
    """
    获取流量计总用气量
    :param meter_id:
    :return:
    """
    data = conf_cache_api.get_hash('flow_statistic', meter_id)
    if not data:
        data = 0
    return float(data.decode('utf-8'))
示例#3
0
def get_meter_recent_month_data(meter_id):
    """
    获取最近12个月
    :param meter_id:
    :return:
    """
    data_str = conf_cache_api.get_hash('month_statistic', meter_id)
    if data_str:
        return json.loads(data_str)
    else:
        return []
示例#4
0
def get_meter_recent_week_data(meter_id):
    """
    获取最近七天的历史数据
    :param meter_id:
    :return:
    """
    data_str = conf_cache_api.get_hash('week_statistic', meter_id)
    if data_str:
        return json.loads(data_str)
    else:
        return []
示例#5
0
def get_meter_year_data(meter_id):
    """
    获取最近几年的历史数据
    :param meter_id:
    :return:
    """
    data_str = conf_cache_api.get_hash('year_statistic', meter_id)
    if data_str:
        return json.loads(data_str.decode('utf-8'))
    else:
        return {}
示例#6
0
def get_meter_month_data(meter_id):
    """
    获取最近12个月
    :param meter_id:
    :return:
    """
    data_str = conf_cache_api.get_hash('month_statistic', meter_id)
    if data_str:
        return json.loads(data_str.decode('utf-8'))
    else:
        return {}
示例#7
0
def get_query_meter_time():
    """
    获取未执行的操作的检查时间
    例如:每5秒检查是否有操作还未执行
    :return:
    """
    key = 'query_meter_time'
    check_time = cache.get_hash('configure', key)
    # 如果不存在缓存中,则从数据库中读取
    if check_time is None:
        check_time = Configure.objects.get(name=key).val
        check_time = int(check_time)
        cache.set_hash('configure', key, check_time)

    return int(check_time)
示例#8
0
    def __render_action_type_str(action, params):
        """
        渲染信息字符串
        :return:
        """
        log_dict_str = conf_cache_api.get_hash('log_configure', action)
        # 配置信息还没加载到缓存中就立即加载
        if log_dict_str is None:
            load_log_configure()
            log_dict_str = conf_cache_api.get_hash('log_configure', action)
            if log_dict_str is None:
                return None

        log_dict = json.loads(log_dict_str.decode('utf-8'))

        # 获得行为类型模板
        msg = log_dict['msg']
        data_field = log_dict['data_field']
        # 渲染系统日志行为类型字段
        data_list = []
        for field in data_field:
            data_list.append(params.get(field, ''))

        return msg.format(*data_list)
示例#9
0
def find_register_by_opr_type(opr_type):

    register_str = conf_cache_api.get_hash('control_register', opr_type)
    if register_str is None:
        register = core.find_one_control_register({'opr_type': opr_type})
        register_str = json.dumps({
            'field_val': register.field_val,
            'const_data': register.const_data
        })
        # 重新设置缓存
        conf_cache_api.set_hash('control_register', opr_type, register_str)
    else:
        register_dict = json.loads(register_str.decode('utf-8'))
        register = ControlRegister()
        register.field_val = register_dict['field_val']
        register.const_data = register_dict['const_data']

    return register