From aebcae2bc6300c85f5aa3957ec849e39a2f09435 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 4 Mar 2025 10:18:32 +0100 Subject: [PATCH 1/7] Fix for plotly 6.0.0 --- scripts/plotly_streamlit.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index b1227038e..f606b9340 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -254,14 +254,14 @@ def hms_to_str(t): # Plot seen species for selected date range and number of species - fig.add_trace(go.Bar(y=top_N_species.index, x=top_N_species, orientation='h', marker_color='seagreen'), row=1, col=1) + fig.add_trace(go.Bar(y=top_N_species.index.tolist(), x=top_N_species.values.tolist(), orientation='h', marker_color='seagreen'), row=1, col=1) fig.update_layout( margin=dict(l=0, r=0, t=50, b=0), yaxis={'categoryorder': 'total ascending'}) # Set 360 degrees, 24 hours for polar plot - theta = np.linspace(0.0, 360, 24, endpoint=False) + theta = np.linspace(0.0, 360, 24, endpoint=False).tolist() specie_filt = df5 == specie df3 = df5[specie_filt] @@ -271,7 +271,7 @@ def hms_to_str(t): d = pd.DataFrame(np.zeros((23, 1))).squeeze() detections = hourly.loc[specie] detections = (d + detections).fillna(0) - fig.add_trace(go.Barpolar(r=detections, theta=theta, marker_color='seagreen'), row=1, col=2) + fig.add_trace(go.Barpolar(r=detections.tolist(), theta=theta, marker_color='seagreen'), row=1, col=2) fig.update_layout( autosize=False, width=1000, @@ -299,7 +299,7 @@ def hms_to_str(t): ) daily = pd.crosstab(df5, df5.index.date, dropna=True, margins=True) - fig.add_trace(go.Bar(x=daily.columns[:-1], y=daily.loc[specie][:-1], marker_color='seagreen'), row=3, col=2) + fig.add_trace(go.Bar(x=daily.columns[:-1].tolist(), y=daily.loc[specie][:-1].tolist(), marker_color='seagreen'),row=3, col=2) st.plotly_chart(fig, use_container_width=True) # , config=config) else: @@ -310,7 +310,7 @@ def hms_to_str(t): specs=[[{"type": "polar", "rowspan": 2}], [{"rowspan": 1}], [{"type": "xy", "rowspan": 1}]] ) # Set 360 degrees, 24 hours for polar plot - theta = np.linspace(0.0, 360, 24, endpoint=False) + theta = np.linspace(0.0, 360, 24, endpoint=False).tolist() specie_filt = df5 == specie df3 = df5[specie_filt] @@ -320,7 +320,7 @@ def hms_to_str(t): d = pd.DataFrame(np.zeros((23, 1))).squeeze() detections = hourly.loc[specie] detections = (d + detections).fillna(0) - fig.add_trace(go.Barpolar(r=detections, theta=theta, marker_color='seagreen'), row=1, col=1) + fig.add_trace(go.Barpolar(r=detections.tolist(), theta=theta, marker_color='seagreen'), row=1, col=1) fig.update_layout( autosize=False, width=1000, @@ -348,7 +348,7 @@ def hms_to_str(t): ) daily = pd.crosstab(df5, df5.index.date, dropna=True, margins=True) - fig.add_trace(go.Bar(x=daily.columns[:-1], y=daily.loc[specie][:-1], marker_color='seagreen'), row=3, col=1) + fig.add_trace(go.Bar(x=daily.columns[:-1].tolist(), y=daily.loc[specie][:-1].tolist(), marker_color='seagreen'), row=3, col=1) st.plotly_chart(fig, use_container_width=True) # , config=config) df_counts = int(hourly[hourly.index == specie]['All'].iloc[0]) st.subheader('Total Detect:' + str('{:,}'.format(df_counts)) @@ -378,7 +378,7 @@ def hms_to_str(t): index=0) df_counts = int(hourly[hourly.index == specie]['All']) - fig = st.container() + fig = make_subplots(rows=1, cols=1) df4 = df2['Com_Name'][df2['Com_Name'] == specie].resample('15min').count() @@ -397,7 +397,7 @@ def hms_to_str(t): heatmap = go.Heatmap( x=fig_x, - y=day_hour_freq.columns, + y=day_hour_freq.columns.tolist(), z=fig_z, # heat.values, showscale=False, texttemplate="%{text}", autocolorscale=False, colorscale=selected_pal @@ -438,7 +438,7 @@ def hms_to_str(t): plt_topN_today = (df6['Com_Name'].value_counts()[:readings]) freq_order = pd.value_counts(df6['Com_Name']).iloc[:readings].index - fig.add_trace(go.Bar(y=plt_topN_today.index, x=plt_topN_today, marker_color='seagreen', orientation='h'), row=1, + fig.add_trace(go.Bar(y=plt_topN_today.index.tolist(), x=plt_topN_today.values.tolist(), marker_color='seagreen', orientation='h'), row=1, col=1) df6['Hour of Day'] = [r.hour for r in df6.index.time] @@ -447,6 +447,7 @@ def hms_to_str(t): heat.index = pd.CategoricalIndex(heat.index, categories=freq_order) heat.sort_index(level=0, inplace=True) + heat.index = heat.index.astype(str) heat_plot_values = ma.log(heat.values).filled(0) hours_in_day = pd.Series(data=range(0, 24)) @@ -457,7 +458,7 @@ def hms_to_str(t): labels = heat.values.astype(int).astype('str') labels[labels == '0'] = "" - fig.add_trace(go.Heatmap(x=heat.columns, y=heat.index, z=heat_values_normalized, # heat.values, + fig.add_trace(go.Heatmap(x=heat.columns.tolist(), y=heat.index.tolist(), z=heat_values_normalized, # heat.values, showscale=False, text=labels, texttemplate="%{text}", colorscale='Blugrn' ), row=1, col=2) From 26557a244015a6979fba4a6d7efb0b8ffac87869 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 4 Mar 2025 10:30:31 +0100 Subject: [PATCH 2/7] Lint --- scripts/plotly_streamlit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index f606b9340..3907bd202 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -299,7 +299,7 @@ def hms_to_str(t): ) daily = pd.crosstab(df5, df5.index.date, dropna=True, margins=True) - fig.add_trace(go.Bar(x=daily.columns[:-1].tolist(), y=daily.loc[specie][:-1].tolist(), marker_color='seagreen'),row=3, col=2) + fig.add_trace(go.Bar(x=daily.columns[:-1].tolist(), y=daily.loc[specie][:-1].tolist(), marker_color='seagreen'), row=3, col=2) st.plotly_chart(fig, use_container_width=True) # , config=config) else: From 1e2ee5bff9050acad9ab270102278aa9ed1e9a70 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 5 Mar 2025 07:23:18 +0100 Subject: [PATCH 3/7] Fix error "Calling int on a single element Series is deprecated" --- scripts/plotly_streamlit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index 3907bd202..b626756bd 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -377,7 +377,7 @@ def hms_to_str(t): species[1:], index=0) - df_counts = int(hourly[hourly.index == specie]['All']) + df_counts = int(hourly.loc[hourly.index == specie, 'All'].iloc[0]) fig = make_subplots(rows=1, cols=1) From 8a4b54c26f692e6d9d29d09e1a14151151ec9695 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 5 Mar 2025 08:40:11 +0100 Subject: [PATCH 4/7] Fix daily resample --- scripts/plotly_streamlit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index b626756bd..9f12f77c3 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -382,8 +382,8 @@ def hms_to_str(t): fig = make_subplots(rows=1, cols=1) df4 = df2['Com_Name'][df2['Com_Name'] == specie].resample('15min').count() - df4.index = [df4.index.date, df4.index.time] - day_hour_freq = df4.unstack().fillna(0) + df4.index = pd.MultiIndex.from_arrays([df4.index.date, df4.index.time], names=['date', 'time']) + day_hour_freq = df4.unstack(level='time').fillna(0) saved_time_labels = [hms_to_str(h) for h in day_hour_freq.columns.tolist()] fig_dec_y = [hms_to_dec(h) for h in day_hour_freq.columns.tolist()] From a6d0c3f6d7a2cad5b6198b8ca81df7c0c71c5c62 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 5 Mar 2025 11:29:50 +0100 Subject: [PATCH 5/7] Fix daily resample --- scripts/plotly_streamlit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index 9f12f77c3..35a7b4371 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -382,15 +382,15 @@ def hms_to_str(t): fig = make_subplots(rows=1, cols=1) df4 = df2['Com_Name'][df2['Com_Name'] == specie].resample('15min').count() - df4.index = pd.MultiIndex.from_arrays([df4.index.date, df4.index.time], names=['date', 'time']) - day_hour_freq = df4.unstack(level='time').fillna(0) + df4.index = [df4.index.date, df4.index.time] + day_hour_freq = df4.unstack().fillna(0) saved_time_labels = [hms_to_str(h) for h in day_hour_freq.columns.tolist()] fig_dec_y = [hms_to_dec(h) for h in day_hour_freq.columns.tolist()] fig_x = [d.strftime('%d-%m-%Y') for d in day_hour_freq.index.tolist()] fig_y = [h.strftime('%H:%M') for h in day_hour_freq.columns.tolist()] day_hour_freq.columns = fig_dec_y - fig_z = day_hour_freq.values.transpose() + fig_z = day_hour_freq.values.transpose().tolist() color_pals = px.colors.named_colorscales() selected_pal = st.sidebar.selectbox('Select Color Pallet for Daily Detections', color_pals) From eac6ab66efb61a840462523b3c1b63b89f1b330f Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 5 Mar 2025 11:30:35 +0100 Subject: [PATCH 6/7] Force readonly mode --- scripts/plotly_streamlit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index 35a7b4371..5822470f7 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -54,7 +54,8 @@ @st.cache_resource() def get_connection(path: str): - return sqlite3.connect(path, check_same_thread=False) + uri = f"file:{path}?mode=ro&cache=shared" + return sqlite3.connect(uri, uri=True, check_same_thread=False) def get_data(_conn: Connection): From 121c72d3c917ff1fd15a2564b7b91c6c8c7f9131 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Sat, 8 Mar 2025 11:23:59 +0100 Subject: [PATCH 7/7] Remove cache=shared --- scripts/plotly_streamlit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py index 5822470f7..cf4a0fa45 100755 --- a/scripts/plotly_streamlit.py +++ b/scripts/plotly_streamlit.py @@ -54,7 +54,7 @@ @st.cache_resource() def get_connection(path: str): - uri = f"file:{path}?mode=ro&cache=shared" + uri = f"file:{path}?mode=ro" return sqlite3.connect(uri, uri=True, check_same_thread=False)