Linting scripts/plotly.streamlit.py
This commit is contained in:
+24
-15
@@ -4,8 +4,7 @@ import pandas as pd
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import plotly.graph_objects as go
|
import plotly.graph_objects as go
|
||||||
from plotly.subplots import make_subplots
|
from plotly.subplots import make_subplots
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta
|
||||||
from pathlib import Path
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from sqlite3 import Connection
|
from sqlite3 import Connection
|
||||||
import plotly.express as px
|
import plotly.express as px
|
||||||
@@ -43,6 +42,7 @@ def get_data(conn: Connection):
|
|||||||
df1 = pd.read_sql("SELECT * FROM detections", con=conn)
|
df1 = pd.read_sql("SELECT * FROM detections", con=conn)
|
||||||
return df1
|
return df1
|
||||||
|
|
||||||
|
|
||||||
conn = get_connection(URI_SQLITE_DB)
|
conn = get_connection(URI_SQLITE_DB)
|
||||||
# Read in the cereal data
|
# Read in the cereal data
|
||||||
# df = load_data()
|
# df = load_data()
|
||||||
@@ -52,7 +52,6 @@ df2['DateTime']=pd.to_datetime(df2['Date'] + " " + df2['Time'])
|
|||||||
df2 = df2.set_index('DateTime')
|
df2 = df2.set_index('DateTime')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Filter on date range
|
# Filter on date range
|
||||||
# Date as calendars
|
# Date as calendars
|
||||||
# Start_Date = pd.to_datetime(st.sidebar.date_input('Which date do you want to start?', value = df2.index.min()))
|
# Start_Date = pd.to_datetime(st.sidebar.date_input('Which date do you want to start?', value = df2.index.min()))
|
||||||
@@ -70,14 +69,22 @@ Date_Slider = cols1.slider('Date Range',
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
filt = (df2.index >= pd.Timestamp(Date_Slider[0])) & (df2.index <= pd.Timestamp(Date_Slider[1] + timedelta(days=1)))
|
filt = (df2.index >= pd.Timestamp(Date_Slider[0])) & (df2.index <= pd.Timestamp(Date_Slider[1] + timedelta(days=1)))
|
||||||
df2 = df2[filt]
|
df2 = df2[filt]
|
||||||
|
|
||||||
st.write('<style>div.row-widget.stRadio > div{flex-direction:row;justify-content: left;} </style>', unsafe_allow_html=True)
|
st.write('<style>div.row-widget.stRadio > div{flex-direction:row;justify-content: left;} </style>', unsafe_allow_html=True)
|
||||||
st.write('<style>div.st-bf{flex-direction:column;} div.st-ag{font-weight:bold;padding-left:2px;}</style>', unsafe_allow_html=True)
|
st.write('<style>div.st-bf{flex-direction:column;} div.st-ag{font-weight:bold;padding-left:2px;}</style>', unsafe_allow_html=True)
|
||||||
|
|
||||||
resample_sel=cols2.radio("Select Resample Resolution - To downsample and make run faster select longer period, Daily provides a view on detections at 15 min intervals through the day", ('1 minute', '5 minutes', '10 minutes', 'Hourly', 'Daily'))
|
resample_sel = cols2.radio(
|
||||||
|
'''
|
||||||
|
Select Resample Resolution - To downsample and make run faster select longer period,
|
||||||
|
Daily provides a view on detections at 15 min intervals through the day
|
||||||
|
''',
|
||||||
|
('1 minute',
|
||||||
|
'5 minutes',
|
||||||
|
'10 minutes',
|
||||||
|
'Hourly',
|
||||||
|
'Daily'))
|
||||||
|
|
||||||
resample_times = {'1 minute': '1min',
|
resample_times = {'1 minute': '1min',
|
||||||
'5 minutes': '5min',
|
'5 minutes': '5min',
|
||||||
@@ -124,13 +131,20 @@ filt=df2['Com_Name']==specie
|
|||||||
df_counts = sum(df5 == specie)
|
df_counts = sum(df5 == specie)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if resample_time != '1D':
|
if resample_time != '1D':
|
||||||
fig = make_subplots(
|
fig = make_subplots(
|
||||||
rows=3, cols=2,
|
rows=3, cols=2,
|
||||||
specs=[[{"type": "xy", "rowspan": 3}, {"type": "polar", "rowspan": 2}], [{"rowspan": 1}, {"rowspan": 1}], [None, {"type": "xy", "rowspan": 1}]],
|
specs=[[{"type": "xy", "rowspan": 3}, {"type": "polar", "rowspan": 2}], [{"rowspan": 1}, {"rowspan": 1}], [None, {"type": "xy", "rowspan": 1}]],
|
||||||
subplot_titles=('<b>Top '+ str(top_N) + ' Species in Date Range '+str(Date_Slider[0])+' to '+str(Date_Slider[1])+' for '+str(resample_sel)+' sampling interval.'+'</b>',
|
subplot_titles=('<b>Top ' +
|
||||||
|
str(top_N) +
|
||||||
|
' Species in Date Range ' +
|
||||||
|
str(Date_Slider[0]) +
|
||||||
|
' to ' +
|
||||||
|
str(Date_Slider[1]) +
|
||||||
|
' for ' +
|
||||||
|
str(resample_sel) +
|
||||||
|
' sampling interval.' +
|
||||||
|
'</b>',
|
||||||
'Total Detect:' + str('{:,}'.format(df_counts)) +
|
'Total Detect:' + str('{:,}'.format(df_counts)) +
|
||||||
' Confidence Max:' + str('{:.2f}%'.format(max(df2[df2['Com_Name'] == specie]['Confidence']) * 100)) +
|
' Confidence Max:' + str('{:.2f}%'.format(max(df2[df2['Com_Name'] == specie]['Confidence']) * 100)) +
|
||||||
' ' + ' Median:' + str('{:.2f}%'.format(np.median(df2[df2['Com_Name'] == specie]['Confidence']) * 100))
|
' ' + ' Median:' + str('{:.2f}%'.format(np.median(df2[df2['Com_Name'] == specie]['Confidence']) * 100))
|
||||||
@@ -145,7 +159,6 @@ if resample_time != '1D':
|
|||||||
margin=dict(l=0, r=0, t=50, b=0),
|
margin=dict(l=0, r=0, t=50, b=0),
|
||||||
yaxis={'categoryorder': 'total ascending'})
|
yaxis={'categoryorder': 'total ascending'})
|
||||||
|
|
||||||
|
|
||||||
# Set 360 degrees, 24 hours for polar plot
|
# 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)
|
||||||
|
|
||||||
@@ -154,9 +167,6 @@ if resample_time != '1D':
|
|||||||
|
|
||||||
detections2 = pd.crosstab(df3, df3.index.hour)
|
detections2 = pd.crosstab(df3, df3.index.hour)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
d = pd.DataFrame(np.zeros((23, 1))).squeeze()
|
d = pd.DataFrame(np.zeros((23, 1))).squeeze()
|
||||||
detections = hourly.loc[specie]
|
detections = hourly.loc[specie]
|
||||||
detections = (d + detections).fillna(0)
|
detections = (d + detections).fillna(0)
|
||||||
@@ -178,14 +188,13 @@ if resample_time != '1D':
|
|||||||
direction='clockwise',
|
direction='clockwise',
|
||||||
tickmode='array',
|
tickmode='array',
|
||||||
tickvals=[0, 15, 35, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345],
|
tickvals=[0, 15, 35, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345],
|
||||||
ticktext=['12am','1am','2am','3am','4am','5am', '6am','7am','8am','9am','10am','11am','12pm','1pm','2pm','3pm','4pm','5pm', '6pm','7pm','8pm','9pm','10pm','11pm'],
|
ticktext=['12am', '1am', '2am', '3am', '4am', '5am', '6am', '7am', '8am', '9am', '10am', '11am',
|
||||||
|
'12pm', '1pm', '2pm', '3pm', '4pm', '5pm', '6pm', '7pm', '8pm', '9pm', '10pm', '11pm'],
|
||||||
hoverformat="#%{theta}: <br>Popularity: %{percent} </br> %{r}"
|
hoverformat="#%{theta}: <br>Popularity: %{percent} </br> %{r}"
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
daily = pd.crosstab(df5, df5.index.date, dropna=False)
|
daily = pd.crosstab(df5, df5.index.date, dropna=False)
|
||||||
|
|
||||||
fig.add_trace(go.Bar(x=daily.columns, y=daily.loc[specie]), row=3, col=2)
|
fig.add_trace(go.Bar(x=daily.columns, y=daily.loc[specie]), row=3, col=2)
|
||||||
|
|||||||
Reference in New Issue
Block a user