#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on 2024-07-19 20:27:12 Friday @author: Nikhil Kapila """ import plotly.express as px import pandas as pd def standard_plotter(timestamp, true, predicted): return standard_plotly_maker(pd.DataFrame({ 'Date': timestamp, 'Actual Values': true.flatten(), 'Predicted Values': predicted.flatten() })) def upgrade_plotter(hourly_data, df): # min_length = min(len(df.index), len(df.values.flatten()), len(hourly_data.values.flatten())) plot_data = pd.DataFrame({ 'Time': df.index, 'Upgrade': df.values.flatten(), 'Input': hourly_data.values.flatten() }) fig = px.line(plot_data, x='Time', y=['Upgrade', 'Input'], labels={ 'value': 'Electricity Usage', 'Time': 'Date and Time' }, title='Comparison of Electricity Usage') fig.data[1].opacity = 0.5 fig.update_traces(mode='lines') return fig def lookback_plotter(hourly_data, predicted): df = pd.concat([pd.DataFrame({'Time': hourly_data.index, 'Values': hourly_data.values.flatten(), 'Type': 'Original Data'}), pd.DataFrame({'Time': predicted.index, 'Values': predicted.values.flatten(), 'Type': 'Prediction'})]) fig = px.line(df, x='Time', y='Values', color='Type', line_dash='Type', labels={ 'Values': 'Values', 'Time': 'Time', 'Type': 'Series Type' }, title='Forecasted Predictions') # fig.update_xaxes(range=[hourly_data.index[-100], predicted.index[-1]]) fig.update_xaxes(range=[hourly_data.index[-10], predicted.index[-2]]) return fig def standard_plotly_maker(df): fig = px.line(df, x='Date', y=['Actual Values', 'Predicted Values'], labels={'value': 'Values', 'variable': 'Series'}, title='Actual vs Predicted Values') fig.update_traces(mode='lines', line=dict(dash='solid', width=2), selector=dict(name='Actual Values')) fig.update_traces(line=dict(dash='dash', width=2),selector=dict(name='Predicted Values'),) return fig