Ejemplo n.º 1
0
    def get_chart(self, rows, x_label, y_label, data_provider):
        def _get_label_with_percentage(row):
            return "%s [%s%%]" % (row[0]['html'], str(int(row[-1]['html'][:-1])))

        if isinstance(data_provider, NutritionBirthWeightDetails):
            chart = PieChart('BirthWeight', '',
                             [{'label': "%s [%s%%]" % (row[0]['html'], str(int(row[-1]['html'][:-1]))),
                               'value': int(row[-1]['html'][:-1])} for row in rows[2:]], ['red', 'green'])
            chart.showLabels = False
        elif isinstance(data_provider, DeliveryPlaceDetailsExtended):
            chart = PieChart('', '', [{'label': _get_label_with_percentage(row),
                                       'value': int(row[-1]['html'][:-1])} for row in rows[1:]])
            chart.showLabels = False
        elif isinstance(data_provider, (PostnatalCareOverview, ImmunizationOverview)):
            chart = MultiBarChart('', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart.rotateLabels = -45
            chart.marginBottom = 120
            if isinstance(data_provider, ImmunizationOverview):
                chart.stacked = True
                chart.add_dataset('Percentage',
                                  [{'x': row[0]['html'],
                                    'y': int(row[3]['html'][:-1]) / 100.0} for row in rows],
                                  color='green')
                chart.add_dataset('Dropout Percentage',
                                  [{'x': row[0]['html'],
                                    'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows],
                                  color='red')
            else:
                chart.add_dataset('Percentage',
                                  [{'x': row[0]['html'], 'y':int(row[-1]['html'][:-1]) / 100.0} for row in rows])
        elif isinstance(data_provider, AnteNatalCareServiceOverviewExtended):
            chart1 = MultiBarChart('', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart2 = MultiBarChart('', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart1.rotateLabels = -45
            chart2.rotateLabels = -45
            chart1.marginBottom = 120
            chart2.marginBottom = 120
            chart1.add_dataset('Percentage', [{'x': row[0]['html'],
                                               'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows[1:6]])
            chart2.add_dataset('Percentage', [{'x': row[0]['html'],
                                               'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows[6:12]])
            return [chart1, chart2]
        elif isinstance(data_provider, ChildrenDeathsByMonth):
            chart = LineChart('Seasonal Variation of Child Deaths', x_axis=Axis(x_label, dateFormat="%B"),
                              y_axis=Axis(y_label, '.2%'))
            chart.rotateLabels = -45
            chart.marginBottom = 120
            months_mapping = dict((v, k) for k, v in enumerate(calendar.month_abbr))
            chart.add_dataset('Percentage', [{'x': datetime.date(1, months_mapping[row[0][:3]], 1),
                                              'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows])
        else:
            chart = PieChart('', '', [{'label': "%s [%s%%]" % (row[0]['html'], str(int(row[-1]['html'][:-1]))),
                                       'value': int(row[-1]['html'][:-1])} for row in rows])
            chart.showLabels = False
        return [chart]
Ejemplo n.º 2
0
    def get_chart(self, rows, x_label, y_label, data_provider):
        def _get_label_with_percentage(row):
            return "%s [%d: %s%%]" % (row[0]['html'], int(row[-2]['html']), str(int(row[-1]['html'][:-1])))

        if isinstance(data_provider, NutritionBirthWeightDetails):
            chart = PieChart(data_provider.chart_title, '',
                             [{'label': _get_label_with_percentage(row),
                               'value': int(row[-1]['html'][:-1])} for row in rows[2:]], ['red', 'green'])
            chart.showLabels = False
            chart.marginLeft = 20
            chart.marginRight = 0
            chart.marginBottom = 20
        elif isinstance(data_provider, DeliveryPlaceDetailsExtended):
            chart = PieChart(data_provider.chart_title, '',
                             [{'label': _get_label_with_percentage(row),
                               'value': int(row[-1]['html'][:-1])} for row in rows[1:]])
            chart.showLabels = False
        elif isinstance(data_provider, (PostnatalCareOverview, ImmunizationOverview)):
            chart = MultiBarChart(data_provider.chart_title, x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart.rotateLabels = -45
            chart.marginBottom = 150
            chart.marginLeft = 45
            chart.marginRight = 0

            if isinstance(data_provider, ImmunizationOverview):
                chart.stacked = True
                chart.add_dataset('Percentage',
                                  [{'x': row[0]['html'],
                                    'y': int(row[3]['html'][:-1]) / 100.0} for row in rows],
                                  color='green')
                chart.add_dataset('Dropout Percentage',
                                  [{'x': row[0]['html'],
                                    'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows],
                                  color='red')
            else:
                chart.add_dataset('Percentage',
                                  [{'x': row[0]['html'], 'y':int(row[-1]['html'][:-1]) / 100.0} for row in rows])
        elif isinstance(data_provider, AnteNatalCareServiceOverviewExtended):
            chart1 = MultiBarChart('ANC Visits', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart2 = MultiBarChart('Maternal TT & IFA', x_axis=Axis(x_label), y_axis=Axis(y_label, '.2%'))
            chart1.rotateLabels = -45
            chart2.rotateLabels = -45
            chart1.marginBottom = 150
            chart2.marginBottom = 150
            chart1.marginLeft = 20
            chart2.marginLeft = 45
            chart1.marginRight = 0
            chart2.marginRight = 0

            chart1.add_dataset('Percentage', [{'x': row[0]['html'],
                                               'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows[1:6]])
            chart2.add_dataset('Percentage', [{'x': row[0]['html'],
                                               'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows[6:12]])
            return [chart1, chart2]
        elif isinstance(data_provider, ChildrenDeathsByMonth):
            chart = MultiBarChart(data_provider.chart_title, x_axis=Axis(x_label, dateFormat="%B"),
                                  y_axis=Axis(y_label, '.2%'))
            chart.rotateLabels = -45
            chart.marginBottom = 50
            chart.marginLeft = 20
            chart.add_dataset('Percentage', [{'x': row[0],
                                              'y': int(row[-1]['html'][:-1]) / 100.0} for row in rows])
        else:
            chart = PieChart(data_provider.chart_title, '', [{'label': _get_label_with_percentage(row),
                                                              'value': int(row[-1]['html'][:-1])} for row in rows])
            chart.showLabels = False
            chart.marginLeft = 20
            chart.marginRight = 0
            chart.marginBottom = 0
        return [chart]
Ejemplo n.º 3
0
    def get_chart(self, rows, x_label, y_label, data_provider):
        def _get_label_with_percentage(row):
            return "%s [%d: %s%%]" % (row[0]["html"], int(row[-2]["html"]), str(int(row[-1]["html"][:-1])))

        if isinstance(data_provider, NutritionBirthWeightDetails):
            chart = PieChart(
                data_provider.chart_title,
                "",
                [{"label": _get_label_with_percentage(row), "value": int(row[-1]["html"][:-1])} for row in rows[2:]],
                ["red", "green"],
            )
            chart.showLabels = False
            chart.marginLeft = 20
            chart.marginRight = 0
            chart.marginBottom = 20
        elif isinstance(data_provider, DeliveryPlaceDetailsExtended):
            chart = PieChart(
                data_provider.chart_title,
                "",
                [{"label": _get_label_with_percentage(row), "value": int(row[-1]["html"][:-1])} for row in rows[1:]],
            )
            chart.showLabels = False
        elif isinstance(data_provider, (PostnatalCareOverview, ImmunizationOverview)):
            chart = MultiBarChart(data_provider.chart_title, x_axis=Axis(x_label), y_axis=Axis(y_label, ".2%"))
            chart.rotateLabels = -45
            chart.marginBottom = 150
            chart.marginLeft = 45
            chart.marginRight = 0

            if isinstance(data_provider, ImmunizationOverview):
                chart.stacked = True
                chart.add_dataset(
                    "Percentage",
                    [{"x": row[0]["html"], "y": int(row[3]["html"][:-1]) / 100.0} for row in rows],
                    color="green",
                )
                chart.add_dataset(
                    "Dropout Percentage",
                    [{"x": row[0]["html"], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows],
                    color="red",
                )
            else:
                chart.add_dataset(
                    "Percentage", [{"x": row[0]["html"], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows]
                )
        elif isinstance(data_provider, AnteNatalCareServiceOverviewExtended):
            chart1 = MultiBarChart("ANC Visits", x_axis=Axis(x_label), y_axis=Axis(y_label, ".2%"))
            chart2 = MultiBarChart("Maternal TT & IFA", x_axis=Axis(x_label), y_axis=Axis(y_label, ".2%"))
            chart1.rotateLabels = -45
            chart2.rotateLabels = -45
            chart1.marginBottom = 150
            chart2.marginBottom = 150
            chart1.marginLeft = 20
            chart2.marginLeft = 45
            chart1.marginRight = 0
            chart2.marginRight = 0

            chart1.add_dataset(
                "Percentage", [{"x": row[0]["html"], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows[1:6]]
            )
            chart2.add_dataset(
                "Percentage", [{"x": row[0]["html"], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows[6:12]]
            )
            return [chart1, chart2]
        elif isinstance(data_provider, ChildrenDeathsByMonth):
            chart = MultiBarChart(
                data_provider.chart_title, x_axis=Axis(x_label, dateFormat="%B"), y_axis=Axis(y_label, ".2%")
            )
            chart.rotateLabels = -45
            chart.marginBottom = 50
            chart.marginLeft = 20
            chart.add_dataset("Percentage", [{"x": row[0], "y": int(row[-1]["html"][:-1]) / 100.0} for row in rows])
        else:
            chart = PieChart(
                data_provider.chart_title,
                "",
                [{"label": _get_label_with_percentage(row), "value": int(row[-1]["html"][:-1])} for row in rows],
            )
            chart.showLabels = False
            chart.marginLeft = 20
            chart.marginRight = 0
            chart.marginBottom = 0
        return [chart]