def for_each_facility(self, data, combination, other_cycle_data={}): ratio = combination.get(RATIO) df1_records = filter_consumption_records(data, combination[DF1]) df2_records = filter_consumption_records(data, combination[DF2]) other_records = filter_consumption_records(data, combination.get(OTHER, [])) df1_count = len(df1_records) df2_count = len(df2_records) + len(other_records) df1_values = values_for_records(combination[FIELDS], df1_records) df2_values = values_for_records(combination[FIELDS], df2_records) other_values = values_for_records(combination[FIELDS], other_records) sum_df1 = pydash.chain(df1_values).reject(lambda x: x is None).map(float).sum().value() sum_df2 = pydash.chain(df2_values).reject(lambda x: x is None).map(float).sum().value() other_sum = pydash.chain(other_values).reject(lambda x: x is None).map(float).sum().value() all_df1_fields_are_blank = pydash.every(df1_values, lambda x: x is None) and len(df1_values) > 0 b1 = pydash.every(df2_values, lambda x: x is None) and len(df2_values) > 0 b2 = pydash.every(other_values, lambda x: x is None) and len(other_values) > 0 all_df2_fields_are_blank = b1 and b2 adjusted_sum_df1 = sum_df1 / ratio numerator = adjusted_sum_df1 denominator = (sum_df2 / ratio) + other_sum if df1_count == 0 or df2_count == 0: return NOT_REPORTING if all_df1_fields_are_blank or all_df2_fields_are_blank: result = NO elif (sum_df2 == 0 and sum_df1 == 0) or (denominator != 0 and 0.7 < abs(numerator / denominator) < 1.429): result = YES else: result = NO return result
def for_each_facility(self, data, combination, previous_cycle_data=None): df1_records = filter_consumption_records(data, combination[DF1]) df2_records = filter_consumption_records(data, combination[DF2]) df1_count = len(df1_records) df2_count = len(df2_records) df1_values = values_for_records(combination.get(FIELDS, []), df1_records) df2_values = values_for_records(combination.get(FIELDS, []), df2_records) all_df1_fields_are_blank = pydash.every( df1_values, lambda x: x is None) and len(df1_values) > 0 all_df2_fields_are_blank = pydash.every( df2_values, lambda x: x is None) and len(df2_values) > 0 sum_df1 = pydash.chain(df1_values).reject(lambda x: x is None).map( float).sum().value() sum_df2 = pydash.chain(df2_values).reject(lambda x: x is None).map( float).sum().value() if df1_count == 0 or df2_count == 0: return NOT_REPORTING if all_df1_fields_are_blank or all_df2_fields_are_blank: result = NO elif (sum_df2 == 0 and sum_df1 == 0) or (sum_df2 != 0 and 0.7 < abs(sum_df1 / sum_df2) < 1.429): result = YES else: result = NO return result
def for_each_facility(self, data, combination, previous_cycle_data=None): ratio = combination[RATIO] df1_records = filter_consumption_records(data, combination[DF1]) df2_records = filter_consumption_records(data, combination[DF2]) df1_count = len(df1_records) df2_count = len(df2_records) df1_values = values_for_records(combination[FIELDS], df1_records) df2_values = values_for_records(combination[FIELDS], df2_records) sum_df1 = pydash.chain(df1_values).reject(lambda x: x is None).sum().value() sum_df2 = pydash.chain(df2_values).reject(lambda x: x is None).sum().value() all_df1_fields_are_blank = pydash.every(df1_values, lambda x: x is None) all_df2_fields_are_blank = pydash.every(df2_values, lambda x: x is None) return calculate_score(df1_count, df2_count, sum_df1, sum_df2, ratio, all_df1_fields_are_blank, all_df2_fields_are_blank, facility_not_reporting(data))
def for_each_facility(self, data, combination, previous_cycle_data=None): ratio = combination[RATIO] df1_records = filter_consumption_records(data, combination[DF1]) df2_records = filter_consumption_records(data, combination[DF2]) df1_count = len(df1_records) df2_count = len(df2_records) df1_values = values_for_records(combination[FIELDS], df1_records) df2_values = values_for_records(combination[FIELDS], df2_records) sum_df1 = pydash.chain(df1_values).reject( lambda x: x is None).sum().value() sum_df2 = pydash.chain(df2_values).reject( lambda x: x is None).sum().value() all_df1_fields_are_blank = pydash.every(df1_values, lambda x: x is None) all_df2_fields_are_blank = pydash.every(df2_values, lambda x: x is None) return calculate_score(df1_count, df2_count, sum_df1, sum_df2, ratio, all_df1_fields_are_blank, all_df2_fields_are_blank, facility_not_reporting(data))
def for_each_facility(self, data, combination, other_cycle_data={}): ratio = combination.get(RATIO) df1_records = filter_consumption_records(data, combination[DF1]) df2_records = filter_consumption_records(data, combination[DF2]) other_records = filter_consumption_records(data, combination.get(OTHER, [])) df1_count = len(df1_records) df2_count = len(df2_records) + len(other_records) df1_values = values_for_records(combination[FIELDS], df1_records) df2_values = values_for_records(combination[FIELDS], df2_records) other_values = values_for_records(combination[FIELDS], other_records) sum_df1 = pydash.chain(df1_values).reject(lambda x: x is None).map( float).sum().value() sum_df2 = pydash.chain(df2_values).reject(lambda x: x is None).map( float).sum().value() other_sum = pydash.chain(other_values).reject(lambda x: x is None).map( float).sum().value() all_df1_fields_are_blank = pydash.every( df1_values, lambda x: x is None) and len(df1_values) > 0 b1 = pydash.every(df2_values, lambda x: x is None) and len(df2_values) > 0 b2 = pydash.every(other_values, lambda x: x is None) and len(other_values) > 0 all_df2_fields_are_blank = b1 and b2 adjusted_sum_df1 = sum_df1 / ratio numerator = adjusted_sum_df1 denominator = (sum_df2 / ratio) + other_sum if df1_count == 0 or df2_count == 0: return NOT_REPORTING if all_df1_fields_are_blank or all_df2_fields_are_blank: result = NO elif (sum_df2 == 0 and sum_df1 == 0) or (denominator != 0 and 0.7 < abs(numerator / denominator) < 1.429): result = YES else: result = NO return result
def for_each_facility(self, data, combination, previous_cycle_data=None): df1_records = filter_consumption_records(data, combination[DF1]) df2_records = filter_consumption_records(data, combination[DF2]) df1_count = len(df1_records) df2_count = len(df2_records) df1_values = values_for_records(combination.get(FIELDS, []), df1_records) df2_values = values_for_records(combination.get(FIELDS, []), df2_records) all_df1_fields_are_blank = pydash.every(df1_values, lambda x: x is None) and len(df1_values) > 0 all_df2_fields_are_blank = pydash.every(df2_values, lambda x: x is None) and len(df2_values) > 0 sum_df1 = pydash.chain(df1_values).reject(lambda x: x is None).map(float).sum().value() sum_df2 = pydash.chain(df2_values).reject(lambda x: x is None).map(float).sum().value() if df1_count == 0 or df2_count == 0: return NOT_REPORTING if all_df1_fields_are_blank or all_df2_fields_are_blank: result = NO elif (sum_df2 == 0 and sum_df1 == 0) or (sum_df2 != 0 and 0.7 < abs(sum_df1 / sum_df2) < 1.429): result = YES else: result = NO return result