Ejemplo n.º 1
0
 def get(self, request, scenario_id):
     scenario = get_object_or_404(Scenario, pk=scenario_id)
     plt.style.use(DEFAULT_PLOT_STYLE)
     # Crop data.
     if scenario.crop_mix:
         crop_mix, data, years, commodities = read_crop_mix(
             scenario.crop_mix.id)
         groups = [
             g.as_cropgroup() for g in crop_mix.cropmixgroup_set.all()
         ]
         dataframe = self.data_function(data, groups)
         fig, ax = new_figure()
         self.plot_function(dataframe, ax)
         ax.set_xlabel(self.xlabel)
         ax.set_ylabel(self.ylabel)
         return plot_to_response(fig)
     else:
         raise Http404("Scenario contains no agriculture data.")
Ejemplo n.º 2
0
 def get(self, request, scenario_id):
     scenario = get_object_or_404(Scenario, pk=scenario_id)
     plt.style.use(DEFAULT_PLOT_STYLE)
     # Crop data.
     if scenario.crop_mix:
         crop_mix, data, years, commodities = read_crop_mix(scenario.crop_mix.id)
         groups = [g.as_cropgroup() for g in crop_mix.cropmixgroup_set.all()]
         dataframe = self.data_function(crop_mix, data, groups)
         if isinstance(dataframe, pd.DataFrame):
             dataframe_reduced = waterkit.econ.analysis.select_top_n_columns(dataframe, 6)
         else:
             dataframe_reduced = dataframe
         fig, ax = new_figure()
         ax.set_xlabel(self.xlabel)
         ax.set_ylabel(self.ylabel)
         self.plot_function(dataframe_reduced, ax)
         return plot_to_response(fig)
     else:
         raise Http404("Scenario contains no agriculture data.")
 def _plot_crop_mix(self, crop_mix):
     crop_mix, data, years, commodities = read_crop_mix(crop_mix.id)
     groups = [g.as_cropgroup() for g in crop_mix.cropmixgroup_set.all()]
     if groups:
         revenue_table = data.get_derived_table("Revenue", groups)
         revenue_table_cpi = econ_analysis.adjust_cpi(
             revenue_table, get_bls_key(), crop_mix.cpi_adjustment_year,
             ConsumerPriceIndexData.as_dataframe())
         niwr_table = data.get_derived_table("NIWR", groups)
         labor_table = data.get_derived_table("Labor", groups)
         revenue_af_plot = econ.plots.plot_revenue_af_table(
             revenue_table_cpi, niwr_table)
         labor_plot = econ.plots.plot_labor_table(labor_table)
         return self.EconPlots(crop_mix.name, revenue_af_plot, labor_plot)
     else:
         # Just do the best we can with what we have and return only the
         # acreages.
         acre_plot = econ.plots.plot_acres(data, groups)
         acre_fraction_plot = econ.plots.plot_acre_fractions(data, groups)
         return self.EconPlots(crop_mix.name, acre_plot, acre_fraction_plot)
Ejemplo n.º 4
0
 def _plot_crop_mix(self, crop_mix):
     crop_mix, data, years, commodities = read_crop_mix(crop_mix.id)
     groups = [g.as_cropgroup() for g in crop_mix.cropmixgroup_set.all()]
     if groups:
         revenue_table = data.get_derived_table("Revenue", groups)
         revenue_table_cpi = econ_analysis.adjust_cpi(
             revenue_table,
             get_bls_key(),
             crop_mix.cpi_adjustment_year,
             ConsumerPriceIndexData.as_dataframe()
         )
         niwr_table = data.get_derived_table("NIWR", groups)
         labor_table = data.get_derived_table("Labor", groups)
         revenue_af_plot = econ.plots.plot_revenue_af_table(revenue_table_cpi, niwr_table)
         labor_plot = econ.plots.plot_labor_table(labor_table)
         return self.EconPlots(crop_mix.name, revenue_af_plot, labor_plot)
     else:
         # Just do the best we can with what we have and return only the
         # acreages.
         acre_plot = econ.plots.plot_acres(data, groups)
         acre_fraction_plot = econ.plots.plot_acre_fractions(data, groups)
         return self.EconPlots(crop_mix.name, acre_plot, acre_fraction_plot)