def generate_web_summary(web_object, community):
    """generate html summary for a community.
    generates web_object.directory/community/<component>.html and
    associated csv files.

    Parameters
    ----------
    web_object: WebSummary
        a WebSummary object
    community: str
        community name

    See also
    --------
    aaem.web :
        WebSummary object definition
    """
    ## get the template
    template = web_object.component_html

    ## get the component (the modeled one)

    modeled = web_object.results[community][COMPONENT_NAME]
    #~ start_year = modeled.start_year
    #~ end_year = modeled.actual_end_year

    ## get the component (for projects)
    ## also figure out the needed start/end years
    projects, s1, e1 = wl.get_projects(web_object, community, COMPONENT_NAME,
                                       'wind')

    start_year, end_year = wl.correct_dates(modeled.start_year, s1,
                                            modeled.actual_end_year, e1)

    order = projects.keys()
    projects['Modeled ' + COMPONENT_NAME] = modeled
    order = ['Modeled ' + COMPONENT_NAME] + order

    ## get forecast stuff (consumption, generation, etc)
    fc = modeled.forecast


    generation = fc.generation['generation diesel'].\
                                        ix[start_year:end_year]

    ## get the diesel prices
    diesel_price = web_object.results[community]['community data'].\
                            get_item('community','diesel prices').\
                            ix[start_year: end_year]#values
    diesel_price = diesel_price[diesel_price.columns[0]]

    ## get diesel generator efficiency
    eff = modeled.cd['diesel generation efficiency']

    ## get generation fuel costs per year (modeled)
    base_cost = generation / eff * diesel_price
    base_cost.name = 'Base Cost'

    table1 = wl.make_costs_table(community, COMPONENT_NAME, projects,
                                 base_cost, web_object.directory)

    ## get generation fuel used (modeled)
    base_con = generation / eff
    base_con.name = 'Base Consumption'

    table2 = wl.make_consumption_table(community, COMPONENT_NAME, projects,
                                       base_con, web_object.directory,
                                       'electric_diesel_reduction')
    ## info for modeled

    #~ print web_object.results[community]
    current = wl.create_electric_system_summary(web_object, community)

    #~ info = create_project_details_list(modeled)

    ## info table (list to send to template)
    info_for_projects = [{'name': 'Current System', 'info': current}]
    #~ {'name': 'Modeled Wind Project', 'info': info}]

    ## get info for projects (updates info_for_projects )
    for p in order:
        project = projects[p]
        try:
            name = project.comp_specs['project details']['name']
        except KeyError:
            name = 'nan'
        if name == 'nan':
            name = p.replace('+', ' ').replace('_', ' ')
        info = create_project_details_list(project)

        info_for_projects.append({'name': name, 'info': info})

    ## create list of charts
    charts = [{
        'name': 'costs',
        'data': str(table1).replace('nan', 'null'),
        'title': 'Estimated Electricity Generation Costs per Year',
        'type': "'$'",
        'plot': True,
    }, {
        'name': 'consumption',
        'data': str(table2).replace('nan', 'null'),
        'title': 'Diesel Consumed for Electricity Generation ',
        'type': "'other'",
        'plot': True,
    }]

    ## generate html
    msg = None
    if community in web_object.bad_data_coms:
        msg = web_object.bad_data_msg

    pth = os.path.join(web_object.directory, community.replace("'", ''),
                       COMPONENT_NAME.replace(' ', '_').lower() + '.html')
    with open(pth, 'w') as html:
        html.write(
            template.render(info=info_for_projects,
                            type=COMPONENT_NAME,
                            com=community.replace("'", ''),
                            charts=charts,
                            summary_pages=['Summary'] + comp_order,
                            sections=web_object.get_summary_pages(),
                            description=DESCRIPTION,
                            metadata=web_object.metadata,
                            message=msg))
Exemplo n.º 2
0
def generate_web_summary(web_object, community):
    """generate html summary for a community.
    generates web_object.directory/community/<component>.html and
    associated csv files.

    Parameters
    ----------
    web_object: WebSummary
        a WebSummary object
    community: str
        community name

    See also
    --------
    aaem.web :
        WebSummary object definition
    """
    ## get the template
    template = web_object.component_html

    ## get the component (the modeled one)

    modeled = web_object.results[community][COMPONENT_NAME]
    start_year = modeled.start_year
    end_year = modeled.actual_end_year

    ## for make table functions
    projects = {'Modeled ' + COMPONENT_NAME + ' (PV)': modeled}

    ## get forecast stuff (consumption, generation, etc)
    fc = modeled.forecast

    generation = fc.generation['generation diesel'].\
                                        ix[start_year:end_year]

    ## get the diesel prices
    diesel_price = web_object.results[community]['community data'].\
                            get_item('community','diesel prices').\
                            ix[start_year: end_year]#values
    diesel_price = diesel_price[diesel_price.columns[0]]

    ## get diesel generator efficiency
    eff = modeled.cd['diesel generation efficiency']

    ## get generation fuel costs per year (modeled)
    base_cost = generation / eff * diesel_price
    base_cost.name = 'Base Cost'

    table1 = wl.make_costs_table(community, COMPONENT_NAME, projects,
                                 base_cost, web_object.directory)

    ## get generation fuel used (modeled)
    base_con = generation / eff
    base_con.name = 'Base Consumption'
    table2 = wl.make_consumption_table(community, COMPONENT_NAME, projects,
                                       base_con, web_object.directory,
                                       'get_fuel_total_saved()')

    current = wl.create_electric_system_summary(web_object, community)

    ## info for modeled
    info = create_project_details_list(modeled)

    ## info table (list to send to template)
    info_for_projects = [{
        'name': 'Current System',
        'info': current
    }, {
        'name': 'Modeled Solar Project',
        'info': info
    }]

    ## create list of charts
    charts = [{
        'name': 'costs',
        'data': str(table1).replace('nan', 'null'),
        'title': 'Estimated Electricity Generation Costs per Year',
        'type': "'$'",
        'plot': True,
    }, {
        'name': 'consumption',
        'data': str(table2).replace('nan', 'null'),
        'title': 'Diesel Consumed for Electricity Generation ',
        'type': "'other'",
        'plot': True,
    }]

    ## generate html
    ## generate html
    msg = None
    if community in web_object.bad_data_coms:
        msg = web_object.bad_data_msg

    pth = os.path.join(web_object.directory, community.replace("'", ''),
                       COMPONENT_NAME.replace(' ', '_').lower() + '.html')
    with open(pth, 'w') as html:
        html.write(
            template.render(info=info_for_projects,
                            type=COMPONENT_NAME,
                            com=community.replace("'", ''),
                            charts=charts,
                            summary_pages=['Summary'] + comp_order,
                            sections=web_object.get_summary_pages(),
                            description=DESCRIPTION,
                            metadata=web_object.metadata,
                            message=msg))