Пример #1
0
def generate_web_summary(web_object, community):
    """generate html summary for a community.
    generates web_object.directory/community/biomass_pellet.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.env.get_template('component.html')

    ## get the component (the modeled one)

    modeled = web_object.results[community][COMPONENT_NAME]
    if modeled.reason != 'OK':
        raise RuntimeError, modeled.reason
    start_year = modeled.start_year
    end_year = modeled.actual_end_year

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

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

    #~ ires = web_object.results[community]['Residential Energy Efficiency']
    icom = web_object.results[community]['Non-residential Energy Efficiency']
    #~ iwat = web_object.results[community]['Water and Wastewater Efficiency']

    data = DataFrame(fc.population['population'])
    #~ df = DataFrame(ires.baseline_fuel_Hoil_consumption,
    #~ columns =['col'],
    #~ index = range(ires.start_year, ires.end_year+1))
    #~ data['heating_fuel_residential_consumed [gallons/year]'] = \
    #~ df['col'].round()

    df = DataFrame(icom.baseline_HF_consumption * constants.mmbtu_to_gal_HF,
                   columns=['col'],
                   index=range(icom.start_year, icom.end_year + 1))
    data['heating_fuel_non-residential_consumed [gallons/year]'] = \
        df['col'].round()

    #~ df = DataFrame(
    #~ iwat.baseline_HF_consumption * constants.mmbtu_to_gal_HF,
    #~ columns =['col'],
    #~ index = range(iwat.start_year, iwat.end_year+1))
    #~ data['heating_fuel_water-wastewater_consumed [gallons/year]'] = \
    #~ df['col'].round()

    data['heating_fuel_total_consumed [gallons/year]'] = \
        data[[
            #~ 'heating_fuel_residential_consumed [gallons/year]',
            'heating_fuel_non-residential_consumed [gallons/year]',
            #~ 'heating_fuel_water-wastewater_consumed [gallons/year]',
        ]].sum(1)


    fuel_consumed = data['heating_fuel_total_consumed [gallons/year]']\
        .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] + \
                        web_object.results[community]['community data'].\
                            get_item('community','heating fuel premium')
    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 = fuel_consumed * 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 = fuel_consumed
    base_con.name = 'Base Consumption'
    table2 = wl.make_consumption_table(community, COMPONENT_NAME, projects,
                                       base_con, web_object.directory,
                                       'heat_diesel_displaced')

    ## info for modeled
    info = create_project_details_list(modeled)

    ## info table (list to send to template)
    info_for_projects = [{
        'name': 'Modeled biomass pellet project',
        'info': info
    }]

    ## create list of charts
    charts = [{
        'name': 'costs',
        'data': str(table1).replace('nan', 'null'),
        'title': 'Estimated Heating Fuel Costs for non-residential sector',
        'type': "'$'",
        'plot': True,
    }, {
        'name': 'consumption',
        'data': str(table2).replace('nan', 'null'),
        'title': 'Heating Fuel Consumed for non-residential sector',
        '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(' ', '_').replace(' ', '_').replace(
            '(', '').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(),
                message=msg,
                description=DESCRIPTION,
                metadata=web_object.metadata,
            ))
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))
Пример #3
0
def generate_web_summary (web_object, community):
    """generate html summary for a community.
    generates web_object.directory/community/ashp_residential.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:  modeled}

    ## get forecast stuff (consumption, generation, etc)
    r_comp = web_object.results[community]["Residential Energy Efficiency"]
    fuel_consumed = DataFrame(
        r_comp.baseline_HF_consumption,
        columns=['fuel consumed'],
        index = range(r_comp.start_year, r_comp.end_year+1)
    )['fuel consumed'].ix[start_year:end_year]

    fuel_consumed = fuel_consumed * constants.mmbtu_to_gal_HF

    ## get the diesel prices
    diesel_price = \
        modeled.cd['diesel prices'] + modeled.cd['heating fuel premium']
    #~ print diesel_price
    diesel_price = diesel_price[diesel_price.columns[0]].ix[start_year:end_year]

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


    ## get generation fuel costs per year (modeled)
    #~ print diesel_price
    base_cost = fuel_consumed  * 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 = (base_cost - base_cost) + fuel_consumed
    base_con.name = 'Base Consumption'
    table2 = wl.make_consumption_table(community, COMPONENT_NAME,
                                    projects, base_con,
                                    web_object.directory,
                                    'get_fuel_total_saved()')

    ## info for modeled
    info = create_project_details_list (modeled)


    ## info table (list to send to template)
    info_for_projects = [{'name':'Modeled residential air source heat pump project',
                            'info':info}]


    ## create list of charts
    charts = [
        {'name':'costs', 'data': str(table1).replace('nan','null'),
         'title': 'Estimated Heating Fuel Costs for residential sector',
         'type': "'$'",'plot': True,},
        {'name':'consumption', 'data': str(table2).replace('nan','null'),
         'title':'Heating Fuel Consumed by residential sector',
         '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(' ','_').replace('(','').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
                                    ))
Пример #4
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))
Пример #5
0
def generate_web_summary(web_object, community):
    """generate html summary for a community.
    generates web_object.directory/community/heat_recovery.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.env.get_template('component.html')

    ## get the component (the modeled one)

    modeled = web_object.results[community][COMPONENT_NAME]

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

    #~ print projects

    if projects == {}:
        raise RuntimeError, "no projects or modeling info"

    sy = modeled.start_year
    ey = modeled.actual_end_year
    if np.isnan(modeled.get_net_benefit()).all():
        sy = np.nan
        ey = np.nan

    start_year, end_year = wl.correct_dates(sy, s1, ey, e1)

    order = projects.keys()
    if not np.isnan(modeled.get_net_benefit()).all():
        projects['Modeled ' + COMPONENT_NAME] = modeled
        order = ['Modeled ' + COMPONENT_NAME] + order

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

    nr_comp = web_object.results[community][
        "Non-residential Energy Efficiency"]
    fuel_consumed = DataFrame(
        nr_comp.baseline_HF_consumption,
        columns=['fuel consumed'],
        index=range(nr_comp.start_year, nr_comp.end_year +
                    1))['fuel consumed'].ix[start_year:end_year]
    fuel_consumed = fuel_consumed * constants.mmbtu_to_gal_HF

    ## get the diesel prices
    diesel_price = web_object.results[community]['community data'].\
                            get_item('community','diesel prices').\
                            ix[start_year: end_year] + \
                        web_object.results[community]['community data'].\
                            get_item('community','heating fuel premium')

    diesel_price = diesel_price[diesel_price.columns[0]]
    ## get generation fuel costs per year (modeled)
    base_cost = fuel_consumed * 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 = fuel_consumed
    base_con.name = 'Base Consumption'
    table2 = wl.make_consumption_table(community, COMPONENT_NAME, projects,
                                       base_con, web_object.directory,
                                       'proposed_heat_recovery')

    ## info for modeled
    #~ ests = modeled.comp_specs['estimate data']
    try:
        current_hr = float(
            modeled.
            comp_specs['est. current annual heating fuel gallons displaced'])
        if not modeled.cd['heat recovery operational'].lower == 'no' and\
           not np.isnan(current_hr):
            current_hr = '{:,.0f}'.format(modeled.comp_specs[
                'est. current annual heating fuel gallons displaced'])
        elif modeled.comp_specs['heat recovery operational'].lower == 'no':
            current_hr = 0
        else:
            current_hr = "unknown"
    except ValueError:
        current_hr = "unknown"

    current = [
        {
            'words': 'Waste Heat Recovery Operational',
            'value': modeled.cd['heat recovery operational']
        },
        {
            'words': 'Identified as priority by HR working group',
            'value': modeled.comp_specs['identified as priority']
        },
        {
            'words': 'Est. current annual heating fuel gallons displaced',
            'value': current_hr
        },
    ]

    #~ info = create_project_details_list(modeled)

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

    if not np.isnan(modeled.get_net_benefit()).all():
        info_for_projects.append({
            'name': 'Modeled ' + COMPONENT_NAME + ' Project',
            'info': info
        })

    ## get info for projects (updates info_for_projects )
    for p in order:
        project = projects[p]
        name = project.comp_specs['name']
        info = create_project_details_list(project)
        #~ print info
        info_for_projects.append({'name': name, 'info': info})

    ## create list of charts
    charts = [{
        'name': 'costs',
        'data': str(table1).replace('nan', 'null'),
        'title': 'Estimated Heating Fuel Costs for non-residential buildings',
        'type': "'$'",
        'plot': True,
    }, {
        'name': 'consumption',
        'data': str(table2).replace('nan', 'null'),
        'title': 'Heating Fuel Consumed for non-residential buildings',
        '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))
Пример #6
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: 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]

    ## 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'
    base_cost = DataFrame(base_cost)
    base_cost['Base Cost'] = (
        modeled.baseline_HF_cost +
        modeled.baseline_kWh_cost)[:modeled.actual_project_life]
    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'
    base_con = DataFrame(base_con)
    #~ base_con['Base Consumption'] = modeled.baseline_kWh_consumption
    #~ table2 = wl.make_consumption_table(community, COMPONENT_NAME,
    #~ projects, base_con,
    #~ web_object.directory,
    #~ 'proposed_kWh_consumption')

    base_con[
        'Base Consumption'] = modeled.baseline_fuel_Hoil_consumption[:modeled.
                                                                     actual_project_life]
    table3 = wl.make_consumption_table(community, COMPONENT_NAME, projects,
                                       base_con, web_object.directory,
                                       'savings_HF')
    #~ table3[0][-1]
    year = modeled.comp_specs['data']['Year']
    current = [
        {'words':'Households ('+ str(int(year)) + ')' ,
                'value': int(modeled.comp_specs['data']['Total Occupied'])},

        {'words':'Households with BEES certification' + \
                ' ('+ str(int(year)) +')',
            'value': str(modeled.comp_specs['data']['BEES Number'])},
        {'words':
            'Households participating in weatherization of home ' + \
            'energy rebate programs ('+ str(int(year)) +')',
         'value': str(modeled.comp_specs['data']['Post-Retrofit Number'])},

         {'words':'Estimated Total Households (' +\
            str(int(modeled.start_year)) +')',
            'value': modeled.init_HH},

                ]

    ## 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 Efficiency Project',
        'info': info
    }]

    ## create list of charts
    charts = [
        {
            'name': 'costs',
            'data': str(table1).replace('nan', 'null'),
            'title':
            'Estimated Heating Fuel + Electricity Costs for residential sector',
            'type': "'$'",
            'plot': True,
        },
        #~ {'name':'E_consumption', 'data': str(table2).replace('nan','null'),
        #~ 'title':'Electricity Consumed',
        #~ 'type': "'other'",'plot': True,},
        {
            'name': 'H_consumption',
            'data': str(table3).replace('nan', 'null'),
            'title': 'Heating Oil Consumed by residential sector',
            '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))
Пример #7
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: 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'
    base_cost = DataFrame(base_cost)
    base_cost['Base Cost'] = (
        modeled.baseline_HF_cost +
        modeled.baseline_kWh_cost)[:modeled.actual_project_life]
    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'
    base_con = DataFrame(base_con)
    base_con[
        'Base Consumption'] = modeled.baseline_kWh_consumption[:modeled.
                                                               actual_project_life]
    table2 = wl.make_consumption_table(community, COMPONENT_NAME, projects,
                                       base_con, web_object.directory,
                                       'savings_kWh_consumption')

    base_con[
        'Base Consumption'] = modeled.baseline_fuel_Hoil_consumption[:modeled.
                                                                     actual_project_life]
    table3 = wl.make_consumption_table(community, COMPONENT_NAME, projects,
                                       base_con, web_object.directory,
                                       'savings_fuel_Hoil_consumption')
    table3[0][-1]



    current = [
        {'words':'System type',
            "value":str(modeled.comp_specs['data']['System Type'])},
        {'words':'Current system heating fuels',
            "value": 'Modeled' \
            if np.isnan(float(modeled.comp_specs['data']['HF Used']))\
            else 'Reported'},
        {'words':'Current system electricity reported',
            "value": 'Modeled' \
            if np.isnan(float(modeled.comp_specs['data']['kWh/yr']))\
            else 'Reported'},

        {'words':'Uses biomass',
            "value":'Yes' if modeled.comp_specs['data']['Biomass'] else 'No'},
        {'words':'Uses recovered heat',
        "value":'Yes' if modeled.comp_specs['data']['HR Installed'] else 'No'},
            ]
    ## 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 Efficiency Project',
        'info': info
    }]

    ## create list of charts
    charts = [{
        'name': 'costs',
        'data': str(table1).replace('nan', 'null'),
        'title':
        'Estimated Heating Fuel + Electricity Costs for water/wastewater sector',
        'type': "'$'",
        'plot': True,
    }, {
        'name': 'E_consumption',
        'data': str(table2).replace('nan', 'null'),
        'title': 'Electricity Consumed by water/wastewater sector',
        'type': "'kWh'",
        'plot': True,
    }, {
        'name': 'H_consumption',
        'data': str(table3).replace('nan', 'null'),
        'title': 'Heating Oil Consumed by water/wastewater sector',
        '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))
Пример #8
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: 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'
    base_cost = DataFrame(base_cost)
    base_cost['Base Cost'] = (
        modeled.baseline_HF_cost +
        modeled.baseline_kWh_cost)[:modeled.actual_project_life]
    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'
    base_con = DataFrame(base_con)
    base_con['Base Consumption'] = modeled.baseline_kWh_consumption
    table2 = wl.make_consumption_table(
        community, COMPONENT_NAME, projects, base_con, web_object.directory,
        'baseline_kWh_consumption -\
                                     project.proposed_kWh_consumption')

    base_con['Base Consumption'] = modeled.baseline_fuel_Hoil_consumption
    table3 = wl.make_consumption_table(
        community, COMPONENT_NAME, projects, base_con, web_object.directory,
        'baseline_fuel_Hoil_consumption -\
                                     project.proposed_fuel_Hoil_consumption')
    table3[0][-1]

    buildings = modeled.comp_specs['building inventory']
    sqft = buildings['Square Feet'].sum()
    current = [
        {'words':"Estimated square feet", 'value':'{:,.0f}'.format(sqft)},
        {'words':"See",
            'value':"<a href='./consumption.html'>consumption </a> "+\
                "for more details of the current non-residential buildings"},
    ]

    ## 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 Efficiency Project',
        'info': info
    }]

    ## create list of charts
    charts = [{
        'name': 'costs',
        'data': str(table1).replace('nan', 'null'),
        'title':
        'Estimated Heating Fuel + Electricity Costs for non-residential sector',
        'type': "'$'",
        'plot': True,
    }, {
        'name': 'E_consumption',
        'data': str(table2).replace('nan', 'null'),
        'title': 'Electricity Consumed by non-residential sector',
        'type': "'other'",
        'plot': True,
    }, {
        'name': 'H_consumption',
        'data': str(table3).replace('nan', 'null'),
        'title': 'Heating Oil Consumed by non-residential sector',
        '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))