From 0c206975a4980c776539bf0ad415c03153b81127 Mon Sep 17 00:00:00 2001 From: Mateus Coelho Date: Sun, 27 Aug 2023 00:39:10 -0300 Subject: [PATCH 1/2] Fix traffic count initialization, bug in date parsing by altair --- streamlit_analytics/display.py | 3 +++ streamlit_analytics/main.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/streamlit_analytics/display.py b/streamlit_analytics/display.py index 9a8cbbb..5c45c72 100644 --- a/streamlit_analytics/display.py +++ b/streamlit_analytics/display.py @@ -60,7 +60,10 @@ def show_results(counts, reset_callback, unsafe_password=None): alt.themes.enable("streamlit") except: pass # probably old Streamlit version + df = pd.DataFrame(counts["per_day"]) + df["days"] = df["days"] + "T00:00:00" + base = alt.Chart(df).encode( x=alt.X("monthdate(days):O", axis=alt.Axis(title="", grid=True)) ) diff --git a/streamlit_analytics/main.py b/streamlit_analytics/main.py index 442b5ec..2ba17d8 100644 --- a/streamlit_analytics/main.py +++ b/streamlit_analytics/main.py @@ -20,11 +20,11 @@ def reset_counts(): # Use yesterday as first entry to make chart look better. - yesterday = str(datetime.date.today() - datetime.timedelta(days=1)) + today = datetime.date.today() counts["total_pageviews"] = 0 counts["total_script_runs"] = 0 counts["total_time_seconds"] = 0 - counts["per_day"] = {"days": [str(yesterday)], "pageviews": [0], "script_runs": [0]} + counts["per_day"] = {"days": [str(today)], "pageviews": [0], "script_runs": [0]} counts["widgets"] = {} counts["start_time"] = datetime.datetime.now().strftime("%d %b %Y, %H:%M:%S") From 021c65f3043187a5362c28f27f108687e3dd8ca9 Mon Sep 17 00:00:00 2001 From: Mateus Coelho Date: Sun, 27 Aug 2023 00:43:23 -0300 Subject: [PATCH 2/2] Adding clarification about date formatting --- streamlit_analytics/display.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/streamlit_analytics/display.py b/streamlit_analytics/display.py index 5c45c72..04bf1bd 100644 --- a/streamlit_analytics/display.py +++ b/streamlit_analytics/display.py @@ -62,8 +62,9 @@ def show_results(counts, reset_callback, unsafe_password=None): pass # probably old Streamlit version df = pd.DataFrame(counts["per_day"]) + # Formatting date by ISO-8601 to fix altair's date parsing bug df["days"] = df["days"] + "T00:00:00" - + base = alt.Chart(df).encode( x=alt.X("monthdate(days):O", axis=alt.Axis(title="", grid=True)) )