import time import json import gzip import os import shutil import boto3 import botocore.exceptions import pandas as pd import matplotlib.pyplot as plt from tqdm.auto import trange def plot_forecasts(fcsts, exact, freq = '1H', forecastHorizon=24, time_back = 80): p10 = pd.DataFrame(fcsts['Forecast']['Predictions']['p10']) p50 = pd.DataFrame(fcsts['Forecast']['Predictions']['p50']) p90 = pd.DataFrame(fcsts['Forecast']['Predictions']['p90']) pred_int = p50['Timestamp'].apply(lambda x: pd.Timestamp(x)) fcst_start_date = pred_int.iloc[0] fcst_end_date = pred_int.iloc[-1] time_int = exact['timestamp'].apply(lambda x: pd.Timestamp(x)) plt.plot(time_int[-time_back:],exact['target'].values[-time_back:], color = 'r') plt.plot(pred_int, p50['Value'].values, color = 'k') plt.fill_between(pred_int, p10['Value'].values, p90['Value'].values, color='b', alpha=0.3); plt.axvline(x=pd.Timestamp(fcst_start_date), linewidth=3, color='g', ls='dashed') plt.axvline(x=pd.Timestamp(fcst_end_date), linewidth=3, color='g', ls='dashed') plt.xticks(rotation=30) plt.legend(['Target', 'Forecast'], loc = 'lower left') def extract_gz( src, dst ): print( f"Extracting {src} to {dst}" ) with open(dst, 'wb') as fd_dst: with gzip.GzipFile( src, 'rb') as fd_src: data = fd_src.read() fd_dst.write(data) print("Done.")