From 6a89fc4e0cb40c4cfd9e4c09143379facf87f662 Mon Sep 17 00:00:00 2001 From: Nathan Jager <84308084+NaJager@users.noreply.github.com> Date: Thu, 18 May 2023 14:23:41 +0200 Subject: [PATCH] Fix infinite loading if streamer hasn't been streaming Current behavior for the Analytics dashboard when a streamer hasn't gone live within the selected timeframe is an infinitely loading graph. To fix this, I propose the following change which will instead try to fetch the last known point balance and display a straight line as the graph. --- .../classes/AnalyticsServer.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/TwitchChannelPointsMiner/classes/AnalyticsServer.py b/TwitchChannelPointsMiner/classes/AnalyticsServer.py index b77eb25..3a08b11 100644 --- a/TwitchChannelPointsMiner/classes/AnalyticsServer.py +++ b/TwitchChannelPointsMiner/classes/AnalyticsServer.py @@ -51,6 +51,8 @@ def filter_datas(start_date, end_date, datas): else datetime.now() ).replace(hour=23, minute=59, second=59).timestamp() * 1000 + original_series = datas["series"] + if "series" in datas: df = pd.DataFrame(datas["series"]) df["datetime"] = pd.to_datetime(df.x // 1000, unit="s") @@ -66,6 +68,20 @@ def filter_datas(start_date, end_date, datas): else: datas["series"] = [] + # If no data is found within the timeframe, that usually means the streamer hasn't streamed within that timeframe + # We create a series that shows up as a straight line on the dashboard, with 'No Stream' as labels + if len(datas["series"]) == 0: + new_end_date = start_date; + new_start_date = 0; + df = pd.DataFrame(original_series) + df["datetime"] = pd.to_datetime(df.x // 1000, unit="s") + + # Attempt to get the last known balance from before the provided timeframe + df = df[(df.x >= new_start_date) & (df.x <= new_end_date)] + last_balance = df.drop(columns="datetime").sort_values(by=["x", "y"], ascending=True).to_dict("records")[-1]['y'] + + datas["series"] = [{'x': start_date, 'y': last_balance, 'z': 'No Stream'}, {'x': end_date, 'y': last_balance, 'z': 'No Stream'}]; + if "annotations" in datas: df = pd.DataFrame(datas["annotations"]) df["datetime"] = pd.to_datetime(df.x // 1000, unit="s")