示例#1
0
    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
示例#2
0
    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
示例#3
0
 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))
示例#4
0
 def for_each_facility(self, data, combination, previous_cycle_data=None):
     df1_records = get_consumption_records(data, combination[CONSUMPTION_QUERY])
     values = values_for_records(self.fields, df1_records)
     all_cells_not_negative = pydash.every(values, lambda x: x is None or x >= 0)
     if len(df1_records) == 0:
         return NOT_REPORTING
     return YES if all_cells_not_negative else NO
示例#5
0
 def test_values_for_records(self):
     assert values_for_records([NEW], [{
         NEW: 10,
         EXISTING: 12
     }, {
         NEW: None,
         EXISTING: 12
     }]) == [10, None]
示例#6
0
 def for_each_facility(self, data, combination, previous_cycle_data=None):
     df1_records = get_consumption_records(data,
                                           combination[CONSUMPTION_QUERY])
     values = values_for_records(self.fields, df1_records)
     all_cells_not_negative = pydash.every(values,
                                           lambda x: x is None or x >= 0)
     if len(df1_records) == 0:
         return NOT_REPORTING
     return YES if all_cells_not_negative else NO
示例#7
0
 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))
示例#8
0
    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
示例#9
0
    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
示例#10
0
    def for_each_facility(self, data, combination, previous_cycle_data=None):
        result = NOT_REPORTING

        values = values_for_records(self.fields, data.get(C_RECORDS, []))
        number_of_consumption_record_blanks = len(
            pydash.select(values, lambda v: v is None))

        c_count_ = data.get(C_COUNT, 0)
        a_count_ = data.get(A_COUNT, 0)
        p_count_ = data.get(P_COUNT, 0)
        if c_count_ == 0 and a_count_ == 0 and p_count_ == 0:
            return result
        if c_count_ < 25 or a_count_ < 22 or p_count_ < 7:
            result = NO
        elif number_of_consumption_record_blanks > 2:
            result = NO
        else:
            result = YES
        return result
示例#11
0
    def for_each_facility(self, data, combination, previous_cycle_data=None):
        result = NOT_REPORTING

        values = values_for_records(self.fields, data.get(C_RECORDS, []))
        number_of_consumption_record_blanks = len(pydash.select(
            values, lambda v: v is None))

        c_count_ = data.get(C_COUNT, 0)
        a_count_ = data.get(A_COUNT, 0)
        p_count_ = data.get(P_COUNT, 0)
        if c_count_ == 0 and a_count_ == 0 and p_count_ == 0:
            return result
        if c_count_ < 25 or a_count_ < 22 or p_count_ < 7:
            result = NO
        elif number_of_consumption_record_blanks > 2:
            result = NO
        else:
            result = YES
        return result
示例#12
0
 def test_values_for_records(self):
     assert values_for_records([NEW], [{NEW: 10, EXISTING: 12}, {NEW: None, EXISTING: 12}]) == [10, None]