def test_lop_and_midend_just_mid_reporting(self): self.get_closed_program() indicator_lop = i_factories.IndicatorFactory( target_frequency=Indicator.LOP, lop_target=1000, program=self.program ) lop_data = i_factories.CollectedDataFactory( indicator=indicator_lop, achieved=400, date_collected=self.program.reporting_period_end - datetime.timedelta(days=10) ) indicator_midend = i_factories.IndicatorFactory( target_frequency=Indicator.MID_END, program=self.program ) mid_target = i_factories.PeriodicTargetFactory( indicator=indicator_midend, period=PeriodicTarget.MIDLINE, target=1000 ) mid_data = i_factories.CollectedDataFactory( indicator=indicator_midend, periodic_target=mid_target, achieved=400, date_collected=self.program.reporting_period_start + datetime.timedelta(days=20) ) program = self.get_annotated_program() self.assertEqual(program.scope_counts['nonreporting_count'], 0) self.assertEqual(program.scope_counts['indicator_count'], 2)
def setUp(self): for _ in range(10): program = w_factories.ProgramFactory( reporting_period_start=datetime.date(2014, 1, 1), reporting_period_end=datetime.date(2014, 12, 31)) for _ in range(5): indicator = i_factories.IndicatorFactory( target_frequency=Indicator.LOP, lop_target=100, program=program) i_factories.CollectedDataFactory(indicator=indicator, achieved=105) for _ in range(5): indicator = i_factories.IndicatorFactory( target_frequency=Indicator.LOP, lop_target=100, program=program) evidence = w_factories.DocumentationFactory(program=program) i_factories.CollectedDataFactory(indicator=indicator, achieved=50, evidence=evidence) for _ in range(2): indicator = i_factories.IndicatorFactory( target_frequency=Indicator.LOP, program=program) for _ in range(4): indicator = i_factories.IndicatorFactory( target_frequency=Indicator.MID_END, program=program) for sort in range(2): i_factories.PeriodicTargetFactory( indicator=indicator, target=40, start_date=datetime.date(2014, 5, 1), end_date=datetime.date(2014, 8, 1), customsort=sort)
def test_lop_and_midend_just_mid_reporting(self): self.get_closed_program() indicator_lop = i_factories.IndicatorFactory( target_frequency=Indicator.LOP, lop_target=1000, program=self.program) lop_data = i_factories.CollectedDataFactory( indicator=indicator_lop, achieved=400, date_collected=self.program.reporting_period_end - datetime.timedelta(days=10)) indicator_midend = i_factories.IndicatorFactory( target_frequency=Indicator.MID_END, program=self.program) mid_target = i_factories.PeriodicTargetFactory( indicator=indicator_midend, period=PeriodicTarget.MIDLINE, target=1000) mid_data = i_factories.CollectedDataFactory( indicator=indicator_midend, periodic_target=mid_target, achieved=400, date_collected=self.program.reporting_period_start + datetime.timedelta(days=20)) for indicator in MetricsIndicator.objects.with_annotations( 'reporting').all(): self.assertTrue(indicator.reporting)
def test_midend_target_sums_midend_with_both_data(self): self.indicator.target_frequency = Indicator.MID_END self.indicator.save() mid_target = i_factories.PeriodicTargetFactory( indicator=self.indicator, target=500, period=PeriodicTarget.MIDLINE, customsort=0) end_target = i_factories.PeriodicTargetFactory( indicator=self.indicator, target=800, period=PeriodicTarget.ENDLINE, customsort=1) self.targets.extend([mid_target, end_target]) mid_data = i_factories.CollectedDataFactory( indicator=self.indicator, periodic_target=mid_target, achieved=350, date_collected=self.program.reporting_period_start + datetime.timedelta(days=1)) end_data = i_factories.CollectedDataFactory( indicator=self.indicator, periodic_target=end_target, achieved=950, date_collected=self.program.reporting_period_start + datetime.timedelta(days=10)) self.data.extend([mid_data, end_data]) program = ProgramWithMetrics.home_page.with_annotations('scope').get( pk=self.program.id) self.assertEqual( program.scope_counts['on_scope'], 1, "should show overunder as 0 (in range), got {0}".format( program.scope_counts)) self.indicator.is_cumulative = True self.indicator.save() program = ProgramWithMetrics.home_page.with_annotations('scope').get( pk=self.program.id) # both have data, set to cumulative, so should show latest (endline) target: self.assertEqual( program.scope_counts['high'], 1, "should show overunder as 1 (over range), got {0}".format( program.scope_counts)) self.indicator.direction_of_change = Indicator.DIRECTION_OF_CHANGE_NEGATIVE self.indicator.save() program = ProgramWithMetrics.home_page.with_annotations('scope').get( pk=self.program.id) self.assertEqual( program.scope_counts['low'], 1, "should show overunder as -1 (under range - negative DOC), got {0}" .format(program.scope_counts))
def get_on_target_indicators(self): # lop indicator on target to lop target value lop_indicator = self.get_base_indicator() lop_indicator.target_frequency = Indicator.LOP lop_indicator.lop_target = 10000 lop_indicator.is_cumulative = False lop_indicator.unit_of_measure_type = Indicator.NUMBER lop_indicator.save() lop_data = self.get_base_data(lop_indicator) lop_data.achieved = 10000 lop_data.save() self.data.append(lop_data) # semi annual indicator with target and valid data time_indicator = self.get_base_indicator() time_indicator.target_frequency = Indicator.SEMI_ANNUAL time_indicator.is_cumulative = True time_indicator.unit_of_measure_type = Indicator.NUMBER time_indicator.save() start_date = self.program.reporting_period_start mid_date = datetime.date( start_date.year + 1 if start_date.month > 6 else start_date.year, start_date.month - 6 if start_date.month > 6 else start_date.month + 6, start_date.day) time_target_1 = i_factories.PeriodicTargetFactory( indicator=time_indicator, target=400, start_date=start_date, end_date=mid_date - datetime.timedelta(days=1)) time_target_2 = i_factories.PeriodicTargetFactory( indicator=time_indicator, target=600, start_date=mid_date, end_date=self.program.reporting_period_end) self.targets.extend([time_target_1, time_target_2]) data_1 = i_factories.CollectedDataFactory( indicator=time_indicator, periodic_target=time_target_1, date_collected=time_target_1.start_date + datetime.timedelta(days=2), achieved=200) data_2 = i_factories.CollectedDataFactory( indicator=time_indicator, periodic_target=time_target_2, date_collected=time_target_2.start_date + datetime.timedelta(days=2), achieved=600) self.data.extend([data_1, data_2]) return [lop_indicator, time_indicator]
def get_base_data(self, indicator, target=None): data = i_factories.CollectedDataFactory( indicator=indicator, periodic_target=target, date_collected=self.program.reporting_period_start + datetime.timedelta(days=10)) return data
def test_midend_doesnt_sum_if_no_endline_data(self): self.indicator.target_frequency = Indicator.MID_END self.indicator.save() mid_target = i_factories.PeriodicTargetFactory( indicator=self.indicator, target=500, period=PeriodicTarget.MIDLINE, customsort=0) end_target = i_factories.PeriodicTargetFactory( indicator=self.indicator, target=800, period=PeriodicTarget.ENDLINE, customsort=1) self.targets.extend([mid_target, end_target]) mid_data = i_factories.CollectedDataFactory( indicator=self.indicator, periodic_target=mid_target, achieved=350, date_collected=self.program.reporting_period_start + datetime.timedelta(days=1)) self.data.append(mid_data) program = ProgramWithMetrics.home_page.with_annotations('scope').get( pk=self.program.id) self.assertEqual( program.scope_counts['low'], 1, "should show under (350/500), got {0}".format( program.scope_counts)) self.indicator.direction_of_change = Indicator.DIRECTION_OF_CHANGE_NEGATIVE self.indicator.save() program = ProgramWithMetrics.home_page.with_annotations('scope').get( pk=self.program.id) self.assertEqual( program.scope_counts['high'], 1, "should show over (350/500), got {0}".format(program.scope_counts))
def add_data(self, indicator=None, target=None): data = i_factories.CollectedDataFactory( indicator=indicator, periodic_target=target, date_collected=self.program.reporting_period_start + datetime.timedelta(days=3 + 2 * len(self.data)), achieved=100) self.data.append(data) return data
def load_data(self, indicator=None, achieved=None, date=None, target=None): """adds data to the indicator""" indicator = self.indicator if indicator is None else indicator achieved = 800 if achieved is None else achieved date = self.program.reporting_period_start + datetime.timedelta( days=5) if date is None else date datum = i_factories.CollectedDataFactory(indicator=indicator, achieved=achieved, date_collected=date, periodic_target=target) self.data.append(datum)
def test_midend_doesnt_sum_if_no_endline_data(self): self.indicator.target_frequency = Indicator.MID_END self.indicator.save() mid_target = i_factories.PeriodicTargetFactory( indicator=self.indicator, target=500, period=PeriodicTarget.MIDLINE, customsort=0) end_target = i_factories.PeriodicTargetFactory( indicator=self.indicator, target=800, period=PeriodicTarget.ENDLINE, customsort=1) self.targets.extend([mid_target, end_target]) mid_data = i_factories.CollectedDataFactory( indicator=self.indicator, periodic_target=mid_target, achieved=350, date_collected=self.program.reporting_period_start + datetime.timedelta(days=1)) self.data.append(mid_data) indicator = MetricsIndicator.objects.with_annotations('scope').get( pk=self.indicator.id) # both have data, defaults to non_cumulative, so should show sum of both targets: self.assertEqual( indicator.lop_target_sum, 500, "should not sum targets (no data for endline) expecting 500, got {0}" .format(indicator.lop_target_sum)) self.assertEqual( indicator.lop_actual_sum, 350, "should show only data, 350 got {0}".format( indicator.lop_actual_sum)) self.assertEqual( indicator.over_under, -1, "should show under (350/500), got {0}".format( indicator.over_under)) self.indicator.direction_of_change = Indicator.DIRECTION_OF_CHANGE_NEGATIVE self.indicator.save() indicator = MetricsIndicator.objects.with_annotations('scope').get( pk=self.indicator.id) self.assertEqual( indicator.over_under, 1, "should show over (350/500), got {0}".format(indicator.over_under)) self.indicator.is_cumulative = True self.indicator.save() indicator = MetricsIndicator.objects.with_annotations('scope').get( pk=self.indicator.id) self.assertEqual( indicator.lop_target_sum, 500, "should not take endline target (no data`) expecting 500, got {0}". format(indicator.lop_target_sum))
def add_data(self, indicator): return i_factories.CollectedDataFactory(indicator=indicator, achieved=100)
def do_add_reported_result(indicator, collect_date, program): return i_factories.CollectedDataFactory(indicator=indicator, date_collected=collect_date, achieved=140, program=program)
def test_midend_target_sums_midend_with_both_data(self): self.indicator.target_frequency = Indicator.MID_END self.indicator.save() mid_target = i_factories.PeriodicTargetFactory( indicator=self.indicator, target=500, period=PeriodicTarget.MIDLINE, customsort=0) end_target = i_factories.PeriodicTargetFactory( indicator=self.indicator, target=800, period=PeriodicTarget.ENDLINE, customsort=1) self.targets.extend([mid_target, end_target]) mid_data = i_factories.CollectedDataFactory( indicator=self.indicator, periodic_target=mid_target, achieved=350, date_collected=self.program.reporting_period_start + datetime.timedelta(days=1)) end_data = i_factories.CollectedDataFactory( indicator=self.indicator, periodic_target=end_target, achieved=950, date_collected=self.program.reporting_period_start + datetime.timedelta(days=10)) self.data.extend([mid_data, end_data]) indicator = MetricsIndicator.objects.with_annotations('scope').get( pk=self.indicator.id) # both have data, defaults to non_cumulative, so should show sum of both targets: self.assertEqual( indicator.lop_target_sum, 1300, "should sum both targets 500 and 800 to get 1300, got {0}".format( indicator.lop_target_sum)) # both have data and targets, defaults to non_cumulative, should show sum of both data: self.assertEqual( indicator.lop_actual_sum, 1300, "should sum both data 350 and 950 to get 1300, got {0}".format( indicator.lop_actual_sum)) self.assertEqual( indicator.over_under, 0, "should show overunder as 0 (in range), got {0}".format( indicator.over_under)) self.indicator.is_cumulative = True self.indicator.save() indicator = MetricsIndicator.objects.with_annotations('scope').get( pk=self.indicator.id) # both have data, set to cumulative, so should show latest (endline) target: self.assertEqual( indicator.lop_target_sum, 800, "should show latest target (800), got {0}".format( indicator.lop_target_sum)) # both have data and targets, defaults to non_cumulative, should show sum of both data: self.assertEqual( indicator.lop_actual_sum, 1300, "should show all data (1300), got {0}".format( indicator.lop_actual_sum)) self.assertEqual( indicator.over_under, 1, "should show overunder as 1 (over range), got {0}".format( indicator.over_under)) self.indicator.direction_of_change = Indicator.DIRECTION_OF_CHANGE_NEGATIVE self.indicator.save() indicator = MetricsIndicator.objects.with_annotations('scope').get( pk=self.indicator.id) self.assertEqual( indicator.over_under, -1, "should show overunder as -1 (under range - negative DOC), got {0}" .format(indicator.over_under))
def test_event_sums_all_targets_using_customsort(self): self.indicator.target_frequency = Indicator.EVENT self.indicator.save() target_1 = i_factories.PeriodicTargetFactory(indicator=self.indicator, target=500, period="event 1", customsort=0) target_2 = i_factories.PeriodicTargetFactory(indicator=self.indicator, target=800, period="event 2", customsort=1) self.targets.extend([target_1, target_2]) data_1 = i_factories.CollectedDataFactory( indicator=self.indicator, periodic_target=target_1, achieved=350, date_collected=self.program.reporting_period_start + datetime.timedelta(days=1)) self.data.append(data_1) indicator = MetricsIndicator.objects.with_annotations('scope').get( pk=self.indicator.id) # both have data, defaults to non_cumulative, so should show sum of both targets: self.assertEqual( indicator.lop_target_sum, 500, "should not sum targets (no data for second target) expecting 500, got {0}" .format(indicator.lop_target_sum)) self.assertEqual( indicator.lop_actual_sum, 350, "should show only data, 350 got {0}".format( indicator.lop_actual_sum)) self.assertEqual( indicator.over_under, -1, "should show under (350/500), got {0}".format( indicator.over_under)) data_2 = i_factories.CollectedDataFactory( indicator=self.indicator, periodic_target=target_2, achieved=950, date_collected=self.program.reporting_period_start + datetime.timedelta(days=20)) self.data.append(data_2) indicator = MetricsIndicator.objects.with_annotations('scope').get( pk=self.indicator.id) self.assertEqual( indicator.lop_target_sum, 1300, "expected sum of targets (both have data) 1300, got {0}".format( indicator.lop_target_sum)) self.assertEqual( indicator.lop_actual_sum, 1300, "expecting sum of data 1300, got {0}".format( indicator.lop_actual_sum)) self.assertEqual( indicator.over_under, 0, "should show on target (over under 0, 1300/1300), got {0}".format( indicator.over_under)) self.indicator.is_cumulative = True self.indicator.save() indicator = MetricsIndicator.objects.with_annotations('scope').get( pk=self.indicator.id) self.assertEqual( indicator.lop_target_sum, 800, "expected most recent target for non-cumulative indicator 800, got {0}" .format(indicator.lop_target_sum))
def get_data(indicator): return i_factories.CollectedDataFactory(indicator=indicator, achieved=100, date_collected=datetime.date( 2016, 10, 1))
def add_result(self, indicator): return i_factories.CollectedDataFactory( indicator=indicator, program=self.program, achieved=100, date_collected=self.program.reporting_period_start)