Example #1
0
def plot_labor_table(labor_table):
    return plotting.bar_plot_table(
        labor_table.div(2080),
        title='Labor (FTEs 2,080 hours/year)',
        palette=Spectral9,
        legend='bottom_right',
        xlabel='Year',
        ylabel='FTEs 2,080 hours/year',
        tools=DEFAULT_TOOLS,
        logo=None,
        responsive=True,
        number_of_categories=8,
        yaxis_formatter=NumeralTickFormatter(format='0,0')
    )
Example #2
0
def plot_acre_fractions(econ_data, groups):
    return plotting.bar_plot_table(
        econ_data.get_ratio_table('ACRES', groups),
        xlabel='Year',
        ylabel='',
        title='% Acres by crop type',
        palette=Spectral9,
        legend='bottom_right',
        tools=DEFAULT_TOOLS,
        logo=None,
        responsive=True,
        number_of_categories=8,
        yaxis_formatter=NumeralTickFormatter(format='00%'),
        y_range=Range1d(0.0, 1.0)
    )
Example #3
0
def crop_mix_detail(request, crop_mix_id):
    crop_mix, data, years, commodities = read_crop_mix(crop_mix_id)
    bls_key = get_bls_key()

    groups = map(lambda g: g.as_cropgroup(), crop_mix.cropmixgroup_set.all())

    context = {
        'id': crop_mix_id,
        'crop_mix': crop_mix,
        'title': crop_mix.name,
        'description': crop_mix.description,
        'state': crop_mix.state,
        'county': crop_mix.county,
        'years': ', '.join(map(str, years)),
        'commodities': ', '.join(commodities),
        'year': datetime.now().year,
        'source': crop_mix.source,
    }


    # We take the top 8 columns of all charts below because we're going to use
    # a 9 color palette to display the data.

    acre_plot = plots.plot_acres(data, groups)
    acre_script, acre_div = components(acre_plot, CDN)
    context.update({
        'acre_script': acre_script,
        'acre_div': acre_div,
    })

    acre_pct_plot = plots.plot_acre_fractions(data, groups)
    acre_pct_script, acre_pct_div = components(acre_pct_plot, CDN)
    context.update({
        'acre_pct_script': acre_pct_script,
        'acre_pct_div': acre_pct_div,
    })

    if groups:
        group_map, uncategorized = data.get_group_map(groups)
        group_values = {g.title: g for g in groups}
        context.update({
            'group_map': {
                key: (group_values[key], ', '.join(value))
                for key, value in group_map.items()
            },
            'uncategorized': ", ".join(uncategorized),
        })
        revenue_table = data.get_derived_table("Revenue", groups)

        niwr_table = data.get_derived_table("NIWR", groups)
        niwr_plot = plotting.bar_plot_table(
            niwr_table,
            title='Water Use (acre-feet)',
            palette=Spectral9,
            legend='bottom_right',
            xlabel='Year',
            ylabel='Acre-Feet',
            tools=DEFAULT_TOOLS,
            logo=None,
            responsive=True,
            number_of_categories=8,
            yaxis_formatter=NumeralTickFormatter(format='0,0')
        )
        niwr_script, niwr_div = components(niwr_plot, CDN)
        context.update({
            'niwr_script': niwr_script,
            'niwr_div': niwr_div,
        })

        labor_table = data.get_derived_table("Labor", groups)
        labor_plot = plots.plot_labor_table(labor_table)
        labor_script, labor_div = components(labor_plot, CDN)
        context.update({
            'labor_script': labor_script,
            'labor_div': labor_div,
        })

        revenue_af_plot = plots.plot_revenue_af_table(revenue_table, niwr_table)
        revenue_af_script, revenue_af_div = components(revenue_af_plot, CDN)
        context.update({
            'revenue_af_script': revenue_af_script,
            'revenue_af_div': revenue_af_div,
        })
    else:
        revenue_table = data.get_table("$")

    revenue_plot = plotting.bar_plot_table(
        revenue_table,
        title='Gross Revenue ($)',
        palette=Spectral9,
        legend='bottom_right',
        xlabel='Year',
        ylabel='',
        tools=DEFAULT_TOOLS,
        logo=None,
        responsive=True,
        number_of_categories=8,
        yaxis_formatter=NumeralTickFormatter(format='$0,0')
    )
    revenue_script, revenue_div = components(revenue_plot, CDN)
    context.update({
        'revenue_script': revenue_script,
        'revenue_div': revenue_div,
    })

    cpi_data = ConsumerPriceIndexData.as_dataframe()
    revenue_table_cpi = analysis.adjust_cpi(
        revenue_table,
        bls_key,
        crop_mix.cpi_adjustment_year,
        cpi_data
    )
    revenue_cpi_plot = plotting.bar_plot_table(
        revenue_table_cpi,
        title='Gross Revenue (%s $)' % crop_mix.cpi_adjustment_year,
        palette=Spectral9,
        legend='bottom_right',
        xlabel='Year',
        ylabel='',
        tools=DEFAULT_TOOLS,
        logo=None,
        responsive=True,
        number_of_categories=8,
        yaxis_formatter=NumeralTickFormatter(format='$0,0')
    )
    revenue_cpi_script, revenue_cpi_div = components(revenue_cpi_plot, CDN)
    context.update({
        'revenue_cpi_script': revenue_cpi_script,
        'revenue_cpi_div': revenue_cpi_div,
    })

    return render(request, 'econ/crop_mix_detail.django.html', context)