def building_selector_callback( selected_building_id, n_clicks, price_of_initial_installation, marginal_price_of_peak_power, price_of_purchased_electricity, grid_output_percentage, investment_years ): print('callback') datasets = dict( yearly_solar_radiation_ratio=calculate_percentage_of_yearly_radiation(), electricity_supply_emission_factor=calculate_electricity_supply_emission_factor()['EmissionFactor'], electricity_spot_price=fingrid_price.purchase_price_of_production_imbalance_power, ) variables = dict( price_of_initial_installation=price_of_initial_installation, marginal_price_of_peak_power=marginal_price_of_peak_power, price_of_purchased_electricity=price_of_purchased_electricity / 100, grid_output_percentage=grid_output_percentage / 100, investment_years=investment_years, ) if selected_building_id is None: perc_sol = datasets['yearly_solar_radiation_ratio'] trace = go.Scatter(y=perc_sol, x=perc_sol.index, mode='lines') layout = make_layout(title='Aurinkosäteily Kumpulassa') fig = go.Figure(data=[trace], layout=layout) card = GraphCard(id='solar_radiation') card.set_figure(fig) return html.Div([ dbc.Row([ dbc.Col([card.render()]), ]), ]) building = buildings_with_pv.loc[selected_building_id] df = pd.read_parquet('data/nuuka/%s.parquet' % selected_building_id) el_samples = df[df.sensor_id.isin(electricity_sensors.index)] el_samples = el_samples.groupby(['building_id', 'time']).value.sum().reset_index() sim = analyze_building(building, el_samples, None, variables, datasets) if sim is not None: out = html.Div([ visualize_building_pv_summary(building, sim, variables) ]) else: out = html.Div() return out
def render_result_graphs(df): hc_cols = ( ('available_hospital_beds', _('Hospital beds')), ('available_icu_units', _('ICU units')), ) traces = [] for col, name in hc_cols: t = dict( type='scatter', name=name, x=df.index, y=df[col], mode='lines', hovertemplate='%{y:d}', hoverlabel=dict(namelength=-1), ) traces.append(t) card = GraphCard('healthcare', graph=dict(config=dict(responsive=False))) layout = make_layout( title=_('Free capacity in the healthcare system'), height=250, showlegend=True, margin=dict(r=250) ) fig = dict(data=traces, layout=layout) card.set_figure(fig) c2 = card.render() df['ifr'] = df.dead.divide(df.all_infected.replace(0, np.inf)) * 100 df['cfr'] = df.dead.divide(df.all_detected.replace(0, np.inf)) * 100 df['r'] = df['r'].rolling(window=7).mean() param_cols = ( ('r', _('Reproductive number (Rₜ)')), ('ifr', _('Infection fatality ratio (IFR, %')), ('cfr', _('Case fatality ratio (CFR, %')), ) card = GraphCard('params', graph=dict(config=dict(responsive=False))) traces = [] for col, name in param_cols: t = dict( type='scatter', name=name, x=df.index, y=df[col], mode='lines', hovertemplate='%{y:.2f}', hoverlabel=dict(namelength=-1), ) traces.append(t) layout = make_layout( title=_('Epidemic parameters'), height=250, showlegend=True, margin=dict(r=250) ) fig = dict(data=traces, layout=layout) card.set_figure(fig) c3 = card.render() return dbc.Row([ dbc.Col(render_population_card(df), md=12), dbc.Col(c2, md=12), dbc.Col(c3, md=12), dbc.Col(render_validation_card(df), md=12), ])
def render_validation_card(df): det = get_detected_cases() det = det[det['confirmed'] > 0] det.index = pd.DatetimeIndex(det.index) max_date = det.index.max() df = df[df.index <= max_date] traces = [] for col_name in ('all_detected', 'hospitalized', 'in_icu', 'dead'): col = [x for x in POP_COLS if x[0] == col_name][0] traces.append( dict( type='scatter', mode='lines', line=dict(color=COLUMN_COLORS[col_name]), name=col[2] + ' ' + _('(simulated)'), x=df.index, y=df[col_name], hovertemplate='%{y:d}', hoverlabel=dict(namelength=-1), )) col_name_map = { 'all_detected': 'confirmed', } det_col_name = col_name_map.get(col_name, col_name) traces.append( dict( type='scatter', mode='markers', line=dict(color=COLUMN_COLORS[col_name]), name=col[2] + ' ' + _('(real)'), x=det.index, y=det[det_col_name], hovertemplate='%{y:d}', hoverlabel=dict(namelength=-1), )) card = GraphCard('validation', graph=dict(config=dict( responsive=False, displayModeBar=True, ))) layout = make_layout(title=_('Validation'), height=250, showlegend=True, margin=dict(r=250), xaxis=dict(fixedrange=False)) fig = dict(data=traces, layout=layout) card.set_figure(fig) return card.render()
def render_population_card(df): traces = generate_population_traces(df) card = GraphCard('population', graph=dict(config=dict(responsive=False))) shapes, annotations, bar_count = make_intervention_shapes(df) layout = make_layout(title=_('Population'), height=250 + bar_count * IV_BAR_PIXELS, showlegend=True, margin=dict(r=250, b=50 + bar_count * IV_BAR_PIXELS), shapes=shapes, annotations=annotations) fig = dict(data=traces, layout=layout) card.set_figure(fig) return card.render()
def render_page(): fig = generate_buildings_forecast_graph() ret = dbc.Row([ dbc.Col([GraphCard(id='buildings', graph=dict(figure=fig)).render()], md=8) ]) return ret
def render_page(): slider = dict( min=-20, max=20, step=5, value=get_variable('population_forecast_correction'), marks={x: '%d %%' % x for x in range(-20, 20 + 1, 5)}, ) card = GraphCard(id='population', slider=slider).render() return dbc.Row(dbc.Col(card, md=6))
def get_content(self): lang = get_active_locale() main_sector_name = self.emission_sector[0] main_sector_metadata = SECTORS[main_sector_name] cols = [] edf = predict_emissions().dropna(axis=1, how='all') forecast = edf.pop('Forecast') edf = edf[main_sector_name] subsectors = main_sector_metadata['subsectors'] colors = generate_color_scale(main_sector_metadata['color'], len(subsectors)) graph = PredictionFigure(sector_name=main_sector_name, unit_name='kt', title=_('Total emissions'), smoothing=True, fill=True, stacked=True, legend=True, legend_x=0.8) for idx, (sector_name, sector_metadata) in enumerate(subsectors.items()): df = pd.DataFrame(edf[sector_name]) df['Forecast'] = forecast fig = self.make_sector_fig(df, sector_name, sector_metadata, colors[idx]) sector_page = get_page_for_emission_sector(main_sector_name, sector_name) card = GraphCard(id='emissions-%s-%s' % (main_sector_name, sector_name), graph=dict(figure=fig), link_to_page=sector_page) cols.append(dbc.Col(card.render(), md=6)) # Add the summed sector to the all emissions graph df = df.drop(columns=['Forecast']) s = df.sum(axis=1) s.name = 'Emissions' df = pd.DataFrame(s) df['Forecast'] = forecast graph.add_series(df=df, trace_name=sector_metadata.get( 'name_%s' % lang, sector_metadata['name']), column_name='Emissions', historical_color=colors[idx]) self.total_emissions = edf.iloc[-1].sum() card = GraphCard(id='%s-emissions-total' % main_sector_name, graph=dict(figure=graph.get_figure())) return html.Div([ dbc.Row(dbc.Col(card.render())), dbc.Row(cols), ])
def render_page(): cols = [] edf = predict_emissions().dropna(axis=1, how='all') forecast = edf.pop('Forecast') graph = PredictionFigure(sector_name=None, unit_name='kt', title='Päästöt yhteensä', smoothing=True, fill=True, stacked=True, legend=True, legend_x=0.8) for sector_name, sector_metadata in SECTORS.items(): df = pd.DataFrame(edf[sector_name]) df['Forecast'] = forecast fig = make_sector_fig(df, sector_name, sector_metadata) sector_page = get_page_for_emission_sector(sector_name, None) card = GraphCard(id='emissions-%s' % sector_name, graph=dict(figure=fig), link_to_page=sector_page) cols.append(dbc.Col(card.render(), md=6)) # Add the summed sector to the all emissions graph df = df.drop(columns=['Forecast']) s = df.sum(axis=1) s.name = 'Emissions' df = pd.DataFrame(s) df['Forecast'] = forecast graph.add_series(df=df, trace_name=sector_metadata['name'], column_name='Emissions', historical_color=sector_metadata['color']) target_year = get_variable('target_year') ref_year = get_variable('ghg_reductions_reference_year') perc_off = get_variable('ghg_reductions_percentage_in_target_year') last_hist_year = edf.loc[~forecast].index.max() last_hist = edf.loc[last_hist_year].sum() end_emissions = edf.loc[target_year].sum() ref_emissions = edf.loc[ref_year].sum() target_emissions = ref_emissions * (1 - perc_off / 100) target_year_emissions = edf.loc[target_year].sum() sticky = StickyBar( label='Päästövähennykset yhteensä', goal=last_hist - target_emissions, value=last_hist - end_emissions, unit='kt', below_goal_good=False, ) card = GraphCard(id='emissions-total', graph=dict(figure=graph.get_figure())) return html.Div( [dbc.Row(dbc.Col(card.render())), dbc.Row(cols), sticky.render()])
def render_page(): cols = [] edf = predict_emissions().set_index('Year') forecast = edf.groupby('Year')['Forecast'].first() graph = PredictionGraph(sector_name=None, unit_name='kt', title='Päästöt yhteensä', smoothing=True, fill=True, stacked=True) for sector_name, sector_metadata in SECTORS.items(): df = edf.loc[edf.Sector1 == sector_name, ['Sector2', 'Forecast', 'Emissions']] df = df.pivot(columns='Sector2', values='Emissions') df['Forecast'] = forecast fig = make_sector_fig(df, sector_name, sector_metadata) sector_page = get_page_for_emission_sector(sector_name, None) card = GraphCard(id='emissions-%s' % sector_name, graph=dict(figure=fig), link_to_page=sector_page) cols.append(dbc.Col(card.render(), md=6)) # Add the summed sector to the all emissions graph df = df.drop(columns=['Forecast']) s = df.sum(axis=1) s.name = 'Emissions' df = pd.DataFrame(s) df['Forecast'] = forecast graph.add_series(df=df, trace_name=sector_metadata['name'], column_name='Emissions', historical_color=sector_metadata['color']) target_year = get_variable('target_year') ref_year = get_variable('ghg_reductions_reference_year') perc_off = get_variable('ghg_reductions_percentage_in_target_year') ref_emissions = edf.loc[ref_year].Emissions.sum() target_emissions = ref_emissions * (1 - perc_off / 100) target_year_emissions = edf.loc[target_year].Emissions.sum() sticky = StickyBar( label='Päästöt yhteensä', goal=target_emissions, value=target_year_emissions, unit='kt', below_goal_good=True, ) card = GraphCard(id='emissions-total', graph=dict(figure=graph.get_figure())) return html.Div( [dbc.Row(cols), dbc.Row(dbc.Col(card.render())), sticky.render()])
def render_page(): els = [] els.append( dbc.Row([ dbc.Col([ dbc.Row(children=[ dbc.Col(m.render(), md=6, className='mb-4') for m in production_methods ]), dbc.Row( dbc.Col( GraphCard( id='district-heating-emission-factor').render())), dbc.Row( dbc.Col( GraphCard(id='district-heating-production').render())), dbc.Row( dbc.Col(html.Div(id='district-heating-table-container'))), ], md=8), ])) els.append( html.Div(id='district-heating-prod-sticky-page-summary-container')) return html.Div(els)
def render_page(): content = dbc.Row([ dbc.Col([ GraphCard(id='district-heating-production').render(), html.Div(id='district-heating-table-container'), ], md=8), dbc.Col([ html.H5('Biopolttoaineen päästökerroin'), html.Small('(suhteessa fysikaaliseen päästökertoimeen)'), dcc.Slider(id='bio-emission-factor', value=get_variable('bio_emission_factor'), min=0, max=150, step=10, marks={x: '%d %%' % x for x in range(0, 150 + 1, 25)}), *generate_ratio_sliders(), html.H5('Tuotantotapaosuudet 2035', className='mt-4'), dcc.Graph(id='district-heating-production-source-graph'), ], md=4), ]) return content
def render_page(): grid = ConnectedCardGrid() per_capita_card = GraphCard( id='electricity-consumption-per-capita', slider=dict( min=-50, max=20, step=5, value=int( get_variable('electricity_consumption_per_capita_adjustment') * 10), marks={x: '%d %%' % (x / 10) for x in range(-50, 20 + 1, 10)}, )) solar_card = GraphCard(id='electricity-consumption-solar-production', link_to_page=('ElectricityConsumption', 'SolarProduction')) grid.make_new_row() grid.add_card(per_capita_card) grid.add_card(solar_card) consumption_card = GraphCard(id='electricity-consumption') emission_factor_card = GraphCard( id='electricity-consumption-emission-factor') per_capita_card.connect_to(consumption_card) solar_card.connect_to(consumption_card) grid.make_new_row() grid.add_card(consumption_card) grid.add_card(emission_factor_card) emission_card = GraphCard(id='electricity-consumption-emissions') consumption_card.connect_to(emission_card) emission_factor_card.connect_to(emission_card) grid.make_new_row() grid.add_card(emission_card) return html.Div(children=[ grid.render(), html.Div(id='electricity-consumption-summary-bar') ])
def render_model_param_graphs(age): PERIOD_PARAMS = ( ('incubation_period', _('Incubation period')), ('illness_period', _('Illness period')), ('hospitalization_period', _('Duration of regular hospital treatment')), ('icu_period', _('Duration of ICU treatment')), ) period_cards = [] for param, label in PERIOD_PARAMS: card = GraphCard(param, graph=dict(config=dict(responsive=False))) layout = make_layout( title=label, height=250, yaxis=dict(title='%'), xaxis=dict(title=_('days')), ) traces = [] if param == 'incubation_period': sample = sample_model_parameters(param, age) sample = sample * 100 / sample.sum() trace = dict( type='bar', x=sample.index, y=sample.values, hovertemplate='%{y} %', name='', ) traces.append(trace) else: for severity in ('ASYMPTOMATIC', 'MILD', 'SEVERE', 'CRITICAL', 'FATAL'): if param == 'icu_period' and severity in ('ASYMPTOMATIC', 'MILD', 'SEVERE'): continue if param == 'hospitalization_period' and severity in ( 'ASYMPTOMATIC', 'MILD'): continue sample = sample_model_parameters(param, age, severity) sample = sample * 100 / sample.sum() trace = go.Bar(type='bar', x=sample.index, y=sample.values, hovertemplate='%{y} %', name=str(SYMPTOM_MAP[severity]), marker_color=SYMPTOM_COLOR_MAP[severity]) traces.append(trace) layout['barmode'] = 'group' layout['showlegend'] = True fig = dict(layout=layout, data=traces) card.set_figure(fig) period_cards.append(card.render()) sample = sample_model_parameters('symptom_severity', age) sample.index = sample.index.map(SYMPTOM_MAP) card = GraphCard('symptom-severity', graph=dict(config=dict(responsive=False))) layout = make_layout( title=_('Symptom severity'), height=250, showlegend=False, yaxis=dict(title='%'), ) sample = sample * 100 / sum(sample) trace = dict(type='bar', x=sample.index, y=sample.values) fig = dict(layout=layout, data=[trace]) card.set_figure(fig) c2 = card.render() sample = sample_model_parameters('contacts_per_day', age) card = GraphCard('contacts_per_day', graph=dict(config=dict(responsive=False))) layout = make_layout( title=_('Contacts per day'), height=250, showlegend=False, yaxis=dict(title='%', ), xaxis=dict(title=_('number of contacts')), ) sample = sample.reindex(range(0, 100), fill_value=0) sample = sample * 100 / sum(sample) trace = dict(type='bar', x=sample.index, y=sample.values) fig = dict(layout=layout, data=[trace]) card.set_figure(fig) c3 = card.render() sample = sample_model_parameters('infectiousness', age) sample *= 100 card = GraphCard('infectiousness', graph=dict(config=dict(responsive=False))) layout = make_layout( title=_('Infectiousness over time'), height=250, showlegend=False, yaxis=dict(title='%', ), xaxis=dict( title=_('Day of illness'), range=[-2, 14], ), ) trace = dict( type='lines', x=sample.index, y=sample.values, line=dict(shape='spline', smoothing=0.3), ) fig = dict(layout=layout, data=[trace]) card.set_figure(fig) c4 = card.render() return html.Div([ dbc.Row([ dbc.Col(c2, md=6), dbc.Col(c3, md=6), dbc.Col(c4, md=6), *[dbc.Col(c, md=6) for c in period_cards] ], className='mt-4') ])
def generate_page(): grid = ConnectedCardGrid() existing_card = GraphCard( id='district-heating-existing-building-unit-heat-factor', slider=dict( min=-60, max=20, step=5, value=get_variable( 'district_heating_existing_building_efficiency_change') * 10, marks={x: '%.1f %%' % (x / 10) for x in range(-60, 20 + 1, 10)}, )) new_card = GraphCard( id='district-heating-new-building-unit-heat-factor', slider=dict( min=-60, max=20, step=5, value=get_variable( 'district_heating_new_building_efficiency_change') * 10, marks={x: '%.1f %%' % (x / 10) for x in range(-60, 20 + 1, 10)}, ), ) geo_card = GraphCard(id='district-heating-geothermal-production', link_to_page=('BuildingHeating', 'GeothermalHeating')) row = grid.make_new_row() row.add_card(existing_card) row.add_card(new_card) row.add_card(geo_card) consumption_card = GraphCard( id='district-heating-consumption', extra_content=html.Div(id='district-heating-unit-emissions-card')) existing_card.connect_to(consumption_card) new_card.connect_to(consumption_card) geo_card.connect_to(consumption_card) row = grid.make_new_row() row.add_card(consumption_card) emissions_card = GraphCard(id='district-heating-consumption-emissions') consumption_card.connect_to(emissions_card) row = grid.make_new_row() row.add_card(emissions_card) return html.Div([ grid.render(), html.Div(id='district-heating-sticky-page-summary-container') ])
def visualize_building_pv_summary(building, df, variables): x = df.SolarPeakPower t1 = go.Scatter( x=x, y=df.InstallationPrice / variables['investment_years'] / 1000, mode='lines', name='Investointikustannukset (per vuosi, %d v)' % variables['investment_years'], marker=dict(color='red') ) t2 = go.Scatter( x=x, y=(df.EnergyCostSavings + df.EnergySalesIncome) / 1000, mode='lines', name='Säästö (per vuosi)', marker=dict(color='green'), ) t3 = go.Scatter( x=x, y=df.EmissionReductionCost, mode='lines', name='Päästövähennyksen hinta', yaxis='y2', marker=dict(color='grey'), ) layout = make_layout( title='Aurinkopaneelien tuottoennuste: %s' % ' '.join(building.description.split(' ')[1:]), yaxis=dict( title='1 000 €', hoverformat='.3r', rangemode='tozero', separatethousands=True, ), yaxis2=dict( overlaying='y', side='right', title='€ / (kg / a)', rangemode='tozero', hoverformat='.2r', showgrid=False, ), xaxis=dict( title='kWp', hoverformat='.2r', ), separators=', ', margin=go.layout.Margin( t=30, r=60, l=60, ), showlegend=True, legend=dict(x=0, y=1), ) fig = go.Figure(data=[t1, t2, t3], layout=layout) card = GraphCard(id='pv-summary') card.set_figure(fig) return html.Div([ dbc.Row([ dbc.Col([ card.render() ], md=12), ]), dcc.Loading(id="loading-2", children=[ html.Div(id="pv-details-placeholder") ], type="default") ])
def generate_page(): grid = ConnectedCardGrid() bev_perc_card = GraphCard( id='cars-bev-percentage', slider=dict( min=0, max=100, step=5, value=get_variable('cars_bev_percentage'), marks={x: '%d %%' % x for x in range(0, 100 + 1, 10)}, ), ) per_resident_card = GraphCard( id='cars-mileage-per-resident', slider=dict( min=-60, max=20, step=5, value=get_variable('cars_mileage_per_resident_adjustment'), marks={x: '%d %%' % (x) for x in range(-60, 20 + 1, 10)}, ), ) mileage_card = GraphCard( id='cars-total-mileage', ) emission_factor_card = GraphCard( id='cars-emission-factor', ) emissions_card = GraphCard( id='cars-emissions', ) """ biofuel_card = GraphCard( id='cars-biofuel-percentage', ) """ grid.make_new_row() grid.add_card(bev_perc_card) #grid.add_card(biofuel_card) grid.add_card(per_resident_card) grid.make_new_row() grid.add_card(emission_factor_card) grid.add_card(mileage_card) grid.make_new_row() grid.add_card(emissions_card) bev_perc_card.connect_to(emission_factor_card) #biofuel_card.connect_to(emission_factor_card) emission_factor_card.connect_to(emissions_card) per_resident_card.connect_to(mileage_card) mileage_card.connect_to(emissions_card) return html.Div([ grid.render(), html.Div(id='cars-sticky-page-summary-container') ])
def render_page(): grid = ConnectedCardGrid() per_capita_card = GraphCard( id='electricity-consumption-per-capita', slider=dict( min=-50, max=20, step=5, value=get_variable( 'electricity_consumption_per_capita_adjustment'), marks={x: '%d %%' % (x / 10) for x in range(-50, 20 + 1, 10)}, )) grid.make_new_row() grid.add_card(per_capita_card) consumption_card = GraphCard(id='electricity-consumption') emission_factor_card = GraphCard( id='electricity-consumption-emission-factor') per_capita_card.connect_to(consumption_card) grid.make_new_row() grid.add_card(consumption_card) grid.add_card(emission_factor_card) emission_card = GraphCard(id='electricity-consumption-emissions') consumption_card.connect_to(emission_card) emission_factor_card.connect_to(emission_card) grid.make_new_row() grid.add_card(emission_card) return grid.render()
def add_graph_card(self, id, **kwargs): card_id = self.make_id(id) assert card_id not in self.graph_cards card = GraphCard(id=card_id, **kwargs) self.graph_cards[card_id] = card return card
def building_base_info_callback(selected_building_id): datasets = dict( electricity_supply_emission_factor=calculate_electricity_supply_emission_factor()['EmissionFactor'], ) if selected_building_id is None: el_s = datasets['electricity_supply_emission_factor'] el_s = el_s.loc[el_s.index >= '2016'] el_s = el_s.groupby(pd.Grouper(freq='d')).mean() trace = go.Scatter( y=el_s, x=el_s.index, mode='lines', ) layout = make_layout(title='Sähkönhankinnan päästökerroin') fig = go.Figure(data=[trace], layout=layout) card = GraphCard(id='electricity-supply-unit-emissions') card.set_figure(fig) return html.Div([ dbc.Row([ dbc.Col([card.render()]), ]), ]) building = buildings_with_pv.loc[selected_building_id] samples = pd.read_parquet('data/nuuka/%s.parquet' % selected_building_id) samples = samples.query('time < "2019-01-01T00:00:00Z"') el_samples = samples[samples.sensor_id.isin(electricity_sensors.index)] el_samples = el_samples.groupby(['building_id', 'time']).value.sum().reset_index() el_samples = el_samples.set_index('time') el_samples['emissions'] = el_samples['value'].mul(datasets['electricity_supply_emission_factor'], axis=0, fill_value=0) / 1000 dh_samples = samples[samples.sensor_id.isin(heating_sensors.index)].query('value < 30000') dh_samples = dh_samples.groupby(['building_id', 'time']).value.sum().reset_index() dh_samples = dh_samples.set_index('time') dh_samples['emissions'] = dh_samples['value'] * 200 / 1000 group_freq = 'd' el_emissions = el_samples.emissions.groupby(pd.Grouper(freq=group_freq)).sum() t1 = go.Scatter( x=el_emissions.index, y=el_emissions, mode='lines', line=dict(width=0), stackgroup='one', name='Sähkönkulutuksen päästöt', ) traces = [t1] if not dh_samples.empty: dh_emissions = dh_samples.emissions.groupby(pd.Grouper(freq=group_freq)).sum() t2 = go.Scatter( x=dh_emissions.index, y=dh_emissions, mode='lines', line=dict(width=0), stackgroup='one', name='Lämmönkulutuksen päästöt' ) traces.append(t2) fig = go.Figure(data=traces, layout=make_layout( title='Kiinteistön energiankulutuksen päästöt: %s' % ' '.join(building.description.split(' ')[1:]), yaxis=dict( rangemode='normal', title='kg (CO₂e.)' ), margin=go.layout.Margin( t=30, r=60, l=60, ), showlegend=True, legend=dict( x=0, y=1, bgcolor='#E2E2E2', ), )) card = GraphCard(id='building-all-emissions') card.set_figure(fig) return card.render()
def generate_page(): grid = ConnectedCardGrid() existing_card = GraphCard( id='solar-power-existing-buildings', slider=dict( min=0, max=90, step=5, value=get_variable('solar_power_existing_buildings_percentage'), marks={x: '%d %%' % x for x in range(0, 90 + 1, 10)}, ), extra_content=html.Div(id='solar-power-existing-kwpa'), ) new_card = GraphCard( id='solar-power-new-buildings', slider=dict( min=20, max=100, step=5, value=get_variable('solar_power_new_buildings_percentage'), marks={x: '%d %%' % x for x in range(20, 100 + 1, 10)}, ), extra_content=html.Div(id='solar-power-new-kwpa'), ) grid.make_new_row() grid.add_card(existing_card) grid.add_card(new_card) production_card = GraphCard(id='solar-power-production') existing_card.connect_to(production_card) new_card.connect_to(production_card) grid.make_new_row() grid.add_card(production_card) emission_card = GraphCard(id='solar-power-emission-reductions') production_card.connect_to(emission_card) grid.make_new_row() grid.add_card(emission_card) return html.Div([ grid.render(), html.Div(id='solar-power-sticky-page-summary-container') ])
def pv_summary_graph_click( click_data, selected_building_id, price_of_initial_installation, marginal_price_of_peak_power, price_of_purchased_electricity, grid_output_percentage, investment_years ): print(click_data) if not click_data: return html.Div() perc = click_data['points'][0]['pointNumber'] datasets = dict( yearly_solar_radiation_ratio=calculate_percentage_of_yearly_radiation(), electricity_supply_emission_factor=calculate_electricity_supply_emission_factor()['EmissionFactor'], electricity_spot_price=fingrid_price.purchase_price_of_production_imbalance_power, ) variables = dict( price_of_initial_installation=price_of_initial_installation, marginal_price_of_peak_power=marginal_price_of_peak_power, price_of_purchased_electricity=price_of_purchased_electricity / 100, grid_output_percentage=grid_output_percentage / 100, investment_years=investment_years, ) building = buildings_with_pv.loc[selected_building_id] df = pd.read_parquet('data/nuuka/%s.parquet' % selected_building_id) el_samples = df[df.sensor_id.isin(electricity_sensors.index)] el_samples = el_samples.groupby(['building_id', 'time']).value.sum().reset_index() res = analyze_building(building, el_samples, perc, variables, datasets) summary = res['summary'] DIV_1000_COLS = ( 'SolarEnergyProduction', 'BuildingEnergyConsumption', 'GridInputReduction', 'GridEnergyOutput', 'EnergySalesIncome', 'EnergyCostSavings', 'InstallationPrice', 'NetCosts', ) for col in DIV_1000_COLS: summary[col] /= 1000 tbl = dash_table.DataTable( id='pv-details-table', columns=[{"name": [translate_sum_col(i), translate_sum_col(i, True)], "id": i} for i in summary.index], data=[summary.to_dict()], style_table={'overflowX': 'scroll'}, ) def fmt_val(x): s = '{0:.3}'.format(x) if 'e' in s: return '%d' % int(float(s)) else: return s tbl = dash_table.DataTable( id='pv-details-table', columns=[{'name': '', 'id': 'name'}, {'name': '', 'id': 'value'}, {'name': 'Yksikkö', 'id': 'unit'}], data=[dict(name=translate_sum_col(key), value=fmt_val(val), unit=translate_sum_col(key, True)) for key, val in summary.items()], ) df = res['simulated'] t1 = dict( x=df.index, y=-df.Consumption, mode='lines', line=dict(width=0), stackgroup='one', name='Kiinteistön sähkönkulutus', type='scatter', ) t2 = dict( x=df.index, y=df.PanelProduction, mode='lines', line=dict(width=0), stackgroup='one', name='Aurinkosähköjärjestelmän tuotanto', type='scatter', ) fig = dict(data=[t1, t2], layout=make_layout( title='Simuloitu aurinkosähköjärjestelmä', yaxis=dict( rangemode='normal', title='kWh' ), xaxis=dict( fixedrange=False ), margin=dict( t=30, r=60, l=60, ), showlegend=True, legend=dict( x=0, y=1, bgcolor='#E2E2E2', ), )) card = GraphCard(id='simulated-pv-time-series', graph=dict(config=dict(displayModeBar='hover'))) card.set_figure(fig) return html.Div(children=[ html.Div(children=tbl, className='mb-4'), html.Div(children=card.render()), ])