def static_stacked_trend_graph(stack=False): """ Returns scatter line plot of all power sources and power load. If `stack` is `True`, the 4 power sources are stacked together to show the overall power production. """ df = fetch_all_bpa_as_df() if df is None: return go.Figure() sources = ['Wind', 'Hydro', 'Fossil/Biomass', 'Nuclear'] x = df['Datetime'] fig = go.Figure() for i, s in enumerate(sources): fig.add_trace(go.Scatter(x=x, y=df[s], mode='lines', name=s, line={'width': 2, 'color': COLORS[i]}, stackgroup='stack' if stack else None)) fig.add_trace(go.Scatter(x=x, y=df['Load'], mode='lines', name='Load', line={'width': 2, 'color': 'orange'})) title = 'Energy Production & Consumption under BPA Balancing Authority' if stack: title += ' [Stacked]' fig.update_layout(template='plotly_dark', title=title, plot_bgcolor='#23272c', paper_bgcolor='#23272c', yaxis_title='MW', xaxis_title='Date/Time') return fig
def what_if_handler(wind, hydro): """Changes the display graph of supply-demand""" df = fetch_all_bpa_as_df(allow_cached=True) x = df['Datetime'] supply = df['Wind'] * wind + df['Hydro'] * hydro + df['Fossil/Biomass'] + df['Nuclear'] load = df['Load'] fig = go.Figure() fig.add_trace(go.Scatter(x=x, y=supply, mode='none', name='supply', line={'width': 2, 'color': 'pink'}, fill='tozeroy')) fig.add_trace(go.Scatter(x=x, y=load, mode='none', name='demand', line={'width': 2, 'color': 'orange'}, fill='tonexty')) fig.update_layout(template='plotly_dark', title='Supply/Demand after Power Scaling', plot_bgcolor='#23272c', paper_bgcolor='#23272c', yaxis_title='MW', xaxis_title='Date/Time') return fig