Exemplo n.º 1
0
    def read_factor(instance, context):
        raw_data, old_value = instance[pipeline_constants.NEW], instance[pipeline_constants.OLD]
        unit_action_status = ReadFactorAction(type=action.type)
        start = time.time()
        # print("context",context)
        variable_type, context_target_name = process_variable(action.variableName)
        topic = get_topic_by_id(action.topicId)
        factor = get_factor(action.factorId, topic)
        joint_type, where_condition = build_query_conditions(action.by, pipeline_topic, raw_data, topic, context)
        mongo_query = __build_mongo_query(joint_type, where_condition)
        target_data = query_topic_data(mongo_query, topic.name)
        if target_data is not None:
            if factor.name in target_data:
                read_value = target_data[factor.name]
                if factor.name in context:
                    log.warn("factor name {0} is already in context".format(factor.name))

                context[context_target_name] = target_data[factor.name]
                unit_action_status.value = read_value
        else:
            context[context_target_name] = convert_factor_type(factor.defaultValue, factor.type)
            log.warn("target_data is empty ,conditions {0}".format(mongo_query))

        elapsed_time = time.time() - start
        unit_action_status.complete_time = elapsed_time
        # print("read context",context)
        return context, unit_action_status, []
 def copy_to_memory(instance, context):
     raw_data, old_value = instance[pipeline_constants.NEW], instance[pipeline_constants.OLD]
     unit_action_status = CopyToMemoryAction(type=action.type)
     start = time.time()
     variable_type, context_target_name = process_variable(action.variableName)
     value_list = get_source_value_list(pipeline_topic, raw_data, action.source)
     context[context_target_name] = value_list
     elapsed_time = time.time() - start
     unit_action_status.complete_time = elapsed_time
     return context, unit_action_status,[]
    def read_row(instance, context):
        raw_data, old_value = instance[pipeline_constants.NEW], instance[pipeline_constants.OLD]
        unit_action_status = UnitActionStatus(type=action.type)
        start = time.time()
        variable_type, context_target_name = process_variable(action.variableName)
        topic = get_topic_by_id(action.topicId)
        joint_type, where_condition = build_query_conditions(action.by, pipeline_topic, raw_data, topic, context)
        mongo_query = __build_mongo_query(joint_type, where_condition)
        target_data = query_topic_data(mongo_query, topic.name)

        if target_data is not None:
            context[context_target_name] = target_data

        elapsed_time = time.time() - start
        unit_action_status.complete_time = elapsed_time
        return context, unit_action_status, []
    def read_factor(instance, context):
        raw_data, old_value = instance[pipeline_constants.NEW], instance[pipeline_constants.OLD]
        unit_action_status = UnitActionStatus(type=action.type)
        start = time.time()

        variable_type, context_target_name = process_variable(action.variableName)
        topic = get_topic_by_id(action.topicId)
        factor = get_factor(action.factorId, topic)
        joint_type, where_condition = build_query_conditions(action.by, pipeline_topic, raw_data, topic, context)
        mongo_query = __build_mongo_query(joint_type, where_condition)
        target_data = query_topic_data(mongo_query, topic.name)

        if factor.name in target_data:
            read_value = target_data[factor.name]
            context[context_target_name] = target_data[factor.name]

            build_action_log(factor, read_value, topic, unit_action_status)
        elapsed_time = time.time() - start
        unit_action_status.complete_time = elapsed_time
        return context, unit_action_status