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 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() 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] unit_action_status.value = read_value # 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