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.
This commit is contained in:
Nathan Jager
2023-05-18 14:23:41 +02:00
committed by GitHub
parent 6341bb88ad
commit 6a89fc4e0c

View File

@@ -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")