コード例 #1
0
ファイル: formula.py プロジェクト: unicefuganda/mics
def simple_indicator(request, indicator_id):
    hierarchy_limit = 2
    selected_location = None
    first_level_location_analyzed = Location.objects.filter(type__name__iexact="country")[0]
    indicator = Indicator.objects.get(id=indicator_id)
    formula = indicator.formula.all()
    if not formula:
        messages.error(request, "No formula was found in this indicator")
        return HttpResponseRedirect(reverse("list_indicator_page"))

    params = request.GET
    if contains_key(params, "location"):
        first_level_location_analyzed = Location.objects.get(id=params["location"])
        selected_location = first_level_location_analyzed
    formula = formula[0]
    indicator_service = SimpleIndicatorService(formula, first_level_location_analyzed)
    data_series, locations = indicator_service.get_location_names_and_data_series()
    context = {
        "request": request,
        "data_series": data_series,
        "tabulated_data": indicator_service.tabulated_data_series(),
        "location_names": locations,
        "indicator": indicator,
        "locations": LocationWidget(selected_location, level=hierarchy_limit),
    }
    return render(request, "formula/simple_indicator.html", context)
コード例 #2
0
ファイル: formula.py プロジェクト: rajkumarenmu/uSurvey
def simple_indicator(request, indicator_id):
    hierarchy_limit = 2
    selected_location = None
    params = request.GET or request.POST
    locations_filter = LocationsFilterForm(data=params)
    first_level_location_analyzed = Location.objects.filter(
        type__name__iexact="country")[0]
    indicator = Indicator.objects.get(id=indicator_id)
    formula = indicator.formula.all()
    if not formula:
        messages.error(request, "No formula was found in this indicator")
        return HttpResponseRedirect(reverse("list_indicator_page"))
    request.breadcrumbs([
        ('Indicator List', reverse('list_indicator_page')),
    ])
    if locations_filter.last_location_selected:
        first_level_location_analyzed = locations_filter.last_location_selected
        selected_location = first_level_location_analyzed
    formula = formula[0]
    indicator_service = SimpleIndicatorService(formula,
                                               first_level_location_analyzed)
    data_series, locations = indicator_service.get_location_names_and_data_series(
    )
    context = {
        'request': request,
        'data_series': data_series,
        'tabulated_data': indicator_service.tabulated_data_series(),
        'location_names': locations,
        'indicator': indicator,
        'locations_filter': locations_filter
    }
    return render(request, 'formula/simple_indicator.html', context)
コード例 #3
0
    def test_formats_details_data(self):
        self.investigator.member_answered(self.question_3, self.household_head_1, self.yes_option.order, self.batch)
        self.investigator.member_answered(self.question_3, self.household_head_2, self.yes_option.order, self.batch)
        self.investigator.member_answered(self.question_3, self.household_head_3, self.yes_option.order, self.batch)
        self.investigator.member_answered(self.question_3, self.household_head_4, self.no_option.order, self.batch)
        self.investigator.member_answered(self.question_3, self.household_head_5, self.no_option.order, self.batch)

        self.investigator_2.member_answered(self.question_3, self.household_head_6, self.yes_option.order, self.batch)
        self.investigator_2.member_answered(self.question_3, self.household_head_7, self.yes_option.order, self.batch)
        self.investigator_2.member_answered(self.question_3, self.household_head_8, self.no_option.order, self.batch)
        self.investigator_2.member_answered(self.question_3, self.household_head_9, self.no_option.order, self.batch)

        kibungo = Location.objects.create(name="Kibungo", type=self.district, tree_parent=self.west)
        mpigi = Location.objects.create(name="Mpigi", type=self.district, tree_parent=self.central)
        table_row_1 = {'Region': self.central.name, 'District': self.kampala.name, self.yes_option.text: 3, self.no_option.text: 2,'Total': 5}
        table_row_2 = {'Region': self.central.name, 'District': mpigi.name, self.yes_option.text: 0, self.no_option.text: 0,'Total': 0}
        table_row_3 = {'Region': self.west.name, 'District': kibungo.name, self.yes_option.text: 0, self.no_option.text: 0,'Total': 0}
        table_row_4 = {'Region': self.west.name, 'District': self.mbarara.name, self.yes_option.text: 2, self.no_option.text: 2,'Total': 4}
        expected_table_data = [table_row_1, table_row_2, table_row_3, table_row_4]

        simple_indicator_service = SimpleIndicatorService(self.formula, self.uganda)
        tabulated_data = simple_indicator_service.tabulated_data_series()

        self.assertEqual(4, len(tabulated_data))
        for i in range(4):
            self.assertEqual(expected_table_data[i], tabulated_data[i])
コード例 #4
0
def simple_indicator(request, indicator_id):
    hierarchy_limit = 2
    selected_location = None
    first_level_location_analyzed = Location.objects.filter(
        type__name__iexact="country")[0]
    indicator = Indicator.objects.get(id=indicator_id)
    formula = indicator.formula.all()
    if not formula:
        messages.error(request, "No formula was found in this indicator")
        return HttpResponseRedirect(reverse("list_indicator_page"))

    params = request.GET
    if contains_key(params, 'location'):
        first_level_location_analyzed = Location.objects.get(
            id=params['location'])
        selected_location = first_level_location_analyzed
    formula = formula[0]
    indicator_service = SimpleIndicatorService(formula,
                                               first_level_location_analyzed)
    data_series, locations = indicator_service.get_location_names_and_data_series(
    )
    context = {
        'request': request,
        'data_series': data_series,
        'tabulated_data': indicator_service.tabulated_data_series(),
        'location_names': locations,
        'indicator': indicator,
        'locations': LocationWidget(selected_location, level=hierarchy_limit)
    }
    return render(request, 'formula/simple_indicator.html', context)
コード例 #5
0
ファイル: formula.py プロジェクト: EswarSakamuri/mymics
def simple_indicator(request, indicator_id):
    hierarchy_limit = 2
    selected_location = None
    params = request.GET or request.POST
    locations_filter = LocationsFilterForm(data=params)
    first_level_location_analyzed = Location.objects.filter(type__name__iexact="country")[0]
    indicator = Indicator.objects.get(id=indicator_id)
    formula = indicator.formula.all()
    if not formula:
        messages.error(request, "No formula was found in this indicator")
        return HttpResponseRedirect(reverse("list_indicator_page"))
    request.breadcrumbs([
        ('Indicator List', reverse('list_indicator_page')),
        ])
    if locations_filter.last_location_selected:
        first_level_location_analyzed = locations_filter.last_location_selected
        selected_location = first_level_location_analyzed
    formula = formula[0]
    indicator_service = SimpleIndicatorService(formula, first_level_location_analyzed)
    data_series, locations = indicator_service.get_location_names_and_data_series()
    context = {'request': request,
               'data_series': data_series,
               'tabulated_data': indicator_service.tabulated_data_series(),
               'location_names': locations,
               'indicator': indicator,
               'locations_filter': locations_filter}
    return render(request, 'formula/simple_indicator.html', context)
コード例 #6
0
 def test_gets_location_names_and_data_series_for_a_parent_location_and_formula(
         self):
     simple_indicator_service = SimpleIndicatorService(
         self.formula, self.uganda)
     region_responses = [{'data': [0, 0], 'name': 'This is an option1'}]
     data_series, location = simple_indicator_service.get_location_names_and_data_series(
     )
     self.assertEquals([self.central.name, self.west.name], location)
     self.assertEquals(region_responses, data_series)
コード例 #7
0
    def test_formats_details_data(self):
        kibungo = Location.objects.create(name="Kibungo", type=self.district, tree_parent=self.west)
        mpigi = Location.objects.create(name="Mpigi", type=self.district, tree_parent=self.central)
        table_row_1 = {'Region': self.central.name, 'District': self.kampala.name, self.general_group.name: 5, 'Total': 5}
        table_row_2 = {'Region': self.central.name, 'District': mpigi.name, self.general_group.name: 0, 'Total': 0}
        table_row_3 = {'Region': self.west.name, 'District': kibungo.name, self.general_group.name: 0, 'Total': 0}
        table_row_4 = {'Region': self.west.name, 'District': self.mbarara.name, self.general_group.name: 4, 'Total': 4}
        expected_table_data = [table_row_1, table_row_2, table_row_3, table_row_4]

        simple_indicator_service = SimpleIndicatorService(self.formula, self.uganda)
        tabulated_data = simple_indicator_service.tabulated_data_series()

        self.assertEqual(4, len(tabulated_data))
        for i in range(4):
            self.assertEqual(expected_table_data[i], tabulated_data[i])
コード例 #8
0
    def test_gets_location_names_and_data_series_for_a_parent_location_and_formula(self):
        self.investigator.member_answered(self.question_3, self.household_head_1, self.yes_option.order, self.batch)
        self.investigator.member_answered(self.question_3, self.household_head_2, self.yes_option.order, self.batch)
        self.investigator.member_answered(self.question_3, self.household_head_3, self.yes_option.order, self.batch)
        self.investigator.member_answered(self.question_3, self.household_head_4, self.no_option.order, self.batch)
        self.investigator.member_answered(self.question_3, self.household_head_5, self.no_option.order, self.batch)

        self.investigator_2.member_answered(self.question_3, self.household_head_6, self.yes_option.order, self.batch)
        self.investigator_2.member_answered(self.question_3, self.household_head_7, self.yes_option.order, self.batch)
        self.investigator_2.member_answered(self.question_3, self.household_head_8, self.no_option.order, self.batch)
        self.investigator_2.member_answered(self.question_3, self.household_head_9, self.no_option.order, self.batch)

        simple_indicator_service = SimpleIndicatorService(self.formula, self.uganda)
        region_responses = [{'data': [3, 2], 'name': self.yes_option.text}, {'data': [2, 2], 'name': self.no_option.text}]
        data_series, location = simple_indicator_service.get_location_names_and_data_series()
        self.assertEquals([self.central.name, self.west.name],  location)
        self.assertEquals(region_responses,  data_series)
コード例 #9
0
    def test_formats_details_data(self):
        kibungo = Location.objects.create(name="Kibungo",
                                          type=self.district,
                                          parent=self.west)
        mpigi = Location.objects.create(name="Mpigi",
                                        type=self.district,
                                        parent=self.central)
        table_row_1 = {
            'Region': self.central.name,
            'District': self.kampala.name,
            self.yes_option.text: 3,
            self.no_option.text: 2,
            'Total': 5
        }
        table_row_2 = {
            'Region': self.central.name,
            'District': mpigi.name,
            self.yes_option.text: 0,
            self.no_option.text: 0,
            'Total': 0
        }
        table_row_3 = {
            'Region': self.west.name,
            'District': kibungo.name,
            self.yes_option.text: 0,
            self.no_option.text: 0,
            'Total': 0
        }
        table_row_4 = {
            'Region': self.west.name,
            'District': self.mbarara.name,
            self.yes_option.text: 2,
            self.no_option.text: 2,
            'Total': 4
        }
        expected_table_data = [
            table_row_1, table_row_2, table_row_3, table_row_4
        ]

        simple_indicator_service = SimpleIndicatorService(
            self.formula, self.uganda)
        tabulated_data = simple_indicator_service.tabulated_data_series()

        self.assertEqual(4, len(tabulated_data))
コード例 #10
0
 def test_gets_location_names_and_data_series_for_a_parent_location_and_formula(self):
     simple_indicator_service = SimpleIndicatorService(self.formula, self.uganda)
     region_responses = [{'data': [5, 4], 'name': self.general_group.name}]
     data_series, location = simple_indicator_service.get_location_names_and_data_series()
     self.assertEquals([self.central.name, self.west.name],  location)
     self.assertEquals(region_responses,  data_series)