Ejemplo n.º 1
0
 def build_chart(self):
     mun_data = models.MunData.objects.get(pk=self.kwargs['pk'])
     hh = round((mun_data.dem_th_energy_hh * 1000 / mun_data.pop_2017))
     rca = round((mun_data.dem_th_energy_rca * 1000 / mun_data.pop_2017))
     data = pd.DataFrame({
         'name': ['Haushalte', 'GHD und Landw.'],
         'y': [hh, rca]
     })
     data.set_index('name', inplace=True)
     # convert data to appropriate format for pie chart
     data = data.reset_index().to_dict(orient='records')
     setup_labels = {
         'title': {'text': 'Wärmebedarf'},
         'subtitle': {'text': 'je EinwohnerIn nach Verbrauchergruppe'},
         'plotOptions': {
             'pie': {
                 'dataLabels': {
                     'format': '<b>{point.name}</b>: {point.y} KWh<br>({point.percentage:.1f} %)',
                 }
             }
         },
         'tooltip': {
             'pointFormat': '<b>{point.name}</b>: {point.y} KWh<br>({point.percentage:.1f} %)'
         }
     }
     chart = visualizations.HCPiechart(
         data=data,
         setup_labels=setup_labels,
         style='display: inline-block'
     )
     return chart
Ejemplo n.º 2
0
 def build_chart(self):
     mun_data = models.MunData.objects.get(pk=self.kwargs['pk'])
     wind = round((mun_data.gen_el_energy_wind / mun_data.pop_2017), 1)
     pv_roof = round((mun_data.gen_el_energy_pv_roof / mun_data.pop_2017), 1)
     pv_ground = round((mun_data.gen_el_energy_pv_ground / mun_data.pop_2017), 1)
     hydro = round((mun_data.gen_el_energy_hydro / mun_data.pop_2017), 1)
     data = pd.DataFrame({
         'name': ['Wind', 'PV Dach', 'PV Freifläche', 'Hydro'],
         'y': [wind, pv_roof, pv_ground, hydro]
     })
     data.set_index('name', inplace=True)
     # convert data to appropriate format for pie chart
     data = data.reset_index().to_dict(orient='records')
     setup_labels = {
         'title': {'text': 'Gewonnene Energie aus EE'},
         'subtitle': {'text': 'je EinwohnerIn'},
         'plotOptions': {
             'pie': {
                 'dataLabels': {
                     'format': '<b>{point.name}</b>: {point.y} MWh<br>({point.percentage:.1f} %)',
                 }
             }
         },
         'tooltip': {
             'pointFormat': '<b>{point.name}</b>: {point.y} MWh<br>({point.percentage:.1f} %)'
         }
     }
     chart = visualizations.HCPiechart(
         data=data,
         setup_labels=setup_labels,
         style='display: inline-block'
     )
     return chart
Ejemplo n.º 3
0
 def build_chart(self):
     mun_data = models.MunData.objects.get(pk=self.kwargs['pk'])
     wind = round((mun_data.gen_capacity_wind / mun_data.area), 2)
     pv_roof = round((mun_data.gen_capacity_pv_roof_large / mun_data.area), 2)
     pv_ground = round((mun_data.gen_capacity_pv_ground / mun_data.area), 2)
     hydro = round((mun_data.gen_capacity_hydro / mun_data.area), 2)
     bio = round((mun_data.gen_capacity_bio / mun_data.area), 2)
     data = pd.DataFrame({
         'name': ['Wind', 'PV Dach, groß', 'PV Freifläche', 'Hydro', 'Bio'],
         'y': [wind, pv_roof, pv_ground, hydro, bio]
     })
     data.set_index('name', inplace=True)
     # convert data to appropriate format for pie chart
     data = data.reset_index().to_dict(orient='records')
     setup_labels = {
         'title': {'text': 'Installierte Leistung EE'},
         'subtitle': {'text': 'je km²'},
         'plotOptions': {
             'pie': {
                 'dataLabels': {
                     'format': '<b>{point.name}</b>: {point.y} MW<br>({point.percentage:.1f} %)',
                 }
             }
         },
         'tooltip': {
             'pointFormat': '<b>{point.name}</b>: {point.y} MW<br>({point.percentage:.1f} %)'
         }
     }
     chart = visualizations.HCPiechart(
         data=data,
         setup_labels=setup_labels,
         style='display: inline-block'
     )
     return chart
Ejemplo n.º 4
0
    def visualize(self):
        if self.type == 'line':
            visualization = visualizations.HCTimeseries(
                data=self.data,
                setup_labels=self.setup_labels,
                style='display: inline-block')
        elif self.type == 'pie':
            # temp data
            data = pd.DataFrame({'name': ['a', 'b', 'c'], 'y': [100, 30, 20]})
            data.set_index('name', inplace=True)

            # convert data to appropriate format for pie chart
            data = data.reset_index().to_dict(orient='records')

            visualization = visualizations.HCPiechart(
                data=data,
                setup_labels=self.setup_labels,
                style='display: inline-block')
        elif self.type == 'column':
            visualization = visualizations.HCStackedColumn(
                data=self.data,
                setup_labels=self.setup_labels,
                style='display: inline-block')
        else:
            raise ValueError
        return visualization