Spaces:
Sleeping
Sleeping
Upload floating.py
Browse filesAdded floating file update
- floating.py +24 -6
floating.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/book/LabellingTracker/13_Floating.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
-
__all__ = ['df', 'get_floating_grp_data', 'get_floating_summary', 'get_floating_hist', 'get_step_df', 'get_gantt']
|
5 |
|
6 |
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 2
|
7 |
import streamlit as st
|
@@ -20,9 +20,23 @@ st.set_page_config(
|
|
20 |
layout='wide'
|
21 |
)
|
22 |
|
23 |
-
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb
|
24 |
# st.sidebar.success("Select a demo above.")
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 11
|
27 |
def get_floating_grp_data(df):
|
28 |
grp_df = df.loc[df['TAG']=='FLOATING', ['Trial_Num', 'AccountNumber', 'AccountName', 'CattleFolder/Frame', 'TAG', 'Assigned',
|
@@ -61,9 +75,10 @@ def get_floating_summary(df):
|
|
61 |
states = ['Recording','Waiting4Video', 'Waiting4Assignment', 'Labelling', 'Waiting4Labels', 'Waiting4Verification','Waiting4Completion']
|
62 |
colors = dict(zip(states, ['blue', 'red', 'green', 'yellow', 'cyan', 'violet', 'pink']))
|
63 |
grp_df[['AccountNumber','Assigned_sum', 'AccountName', 'CattleFolder/Frame','Recording','Waiting4Video', 'Waiting4Assignment', 'Labelling', 'Waiting4Labels', 'Waiting4Verification','Waiting4Completion']].set_index(['AccountNumber', 'AccountName', 'CattleFolder/Frame']).plot(kind='barh', stacked=True, ax=ax, color=colors);
|
|
|
64 |
return fig
|
65 |
|
66 |
-
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb
|
67 |
def get_floating_hist(df, col):
|
68 |
grp_df = get_floating_grp_data(df)
|
69 |
fig, ax = plt.subplots()
|
@@ -75,7 +90,7 @@ def get_floating_hist(df, col):
|
|
75 |
return fig
|
76 |
# get_floating_hist(df, 'Recording_Duration')
|
77 |
|
78 |
-
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb
|
79 |
def get_step_df(grp_df, start_step, end_step, step_name):
|
80 |
df_e = grp_df[['AccountNumber', 'AccountName','Assigned_sum', 'CattleFolder/Frame']].copy()
|
81 |
df_e['Start'] = grp_df[start_step]
|
@@ -84,7 +99,7 @@ def get_step_df(grp_df, start_step, end_step, step_name):
|
|
84 |
return df_e
|
85 |
|
86 |
|
87 |
-
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb
|
88 |
def get_gantt(df):
|
89 |
steps = [
|
90 |
{'start_step': 'Recording_Date_min', 'end_step' :'Recording_Date_max', 'step_name' : 'Recording'},
|
@@ -111,7 +126,8 @@ def get_gantt(df):
|
|
111 |
# ))
|
112 |
return fig
|
113 |
|
114 |
-
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb
|
|
|
115 |
df = None
|
116 |
st.write("# Floating Details")
|
117 |
if 'processed_df' not in st.session_state:
|
@@ -122,7 +138,9 @@ else:
|
|
122 |
colors = st.session_state['colors']
|
123 |
colors2= st.session_state['colors2']
|
124 |
st.markdown("## Summary Floating Durations")
|
|
|
125 |
with st.container(border=True):
|
|
|
126 |
st.pyplot(get_floating_summary(df))
|
127 |
ncols = 3
|
128 |
dcols = st.columns(ncols)
|
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/book/LabellingTracker/13_Floating.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
+
__all__ = ['df', 'kpi', 'get_floating_grp_data', 'get_floating_summary', 'get_floating_hist', 'get_step_df', 'get_gantt']
|
5 |
|
6 |
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 2
|
7 |
import streamlit as st
|
|
|
20 |
layout='wide'
|
21 |
)
|
22 |
|
23 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 7
|
24 |
# st.sidebar.success("Select a demo above.")
|
25 |
|
26 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 10
|
27 |
+
def kpi(df):
|
28 |
+
cattle_days = df.loc[df['TAG']=='FLOATING', ['CattleFolder/Frame', 'SubFolder']].groupby('CattleFolder/Frame').count().sum().values[0]
|
29 |
+
cattle_floating = df.loc[df['TAG']=='FLOATING', ['CattleFolder/Frame']].nunique().values[0]
|
30 |
+
accounts_floating = df.loc[df['TAG']=='FLOATING', 'AccountNumber'].nunique()
|
31 |
+
count_user_floating = len(set(df.loc[df['TAG']=='FLOATING', 'Assigned'].dropna().str.split('/').sum()))
|
32 |
+
count_valid_floating = (df.loc[df['TAG']=='FLOATING', ['CattleFolder/Frame', 'SubFolder']].groupby('CattleFolder/Frame').count() > 1)['SubFolder'].sum()
|
33 |
+
count_exceptional_floating =(df.loc[df['TAG']=='FLOATING', ['CattleFolder/Frame', 'SubFolder']].groupby('CattleFolder/Frame').count() > 10)['SubFolder'].sum()
|
34 |
+
col1, col2, col3, col4 = st.columns(4)
|
35 |
+
col1.metric('Floating Days/Cattle', f'{cattle_days}/{cattle_floating}[{accounts_floating}]')
|
36 |
+
col2.metric('Labellers Floating', count_user_floating)
|
37 |
+
col3.metric('Valid Cattles', f'{count_valid_floating}/{cattle_floating}')
|
38 |
+
col4.metric('Exceptional Cattles', f'{count_exceptional_floating}/{cattle_floating}')
|
39 |
+
|
40 |
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 11
|
41 |
def get_floating_grp_data(df):
|
42 |
grp_df = df.loc[df['TAG']=='FLOATING', ['Trial_Num', 'AccountNumber', 'AccountName', 'CattleFolder/Frame', 'TAG', 'Assigned',
|
|
|
75 |
states = ['Recording','Waiting4Video', 'Waiting4Assignment', 'Labelling', 'Waiting4Labels', 'Waiting4Verification','Waiting4Completion']
|
76 |
colors = dict(zip(states, ['blue', 'red', 'green', 'yellow', 'cyan', 'violet', 'pink']))
|
77 |
grp_df[['AccountNumber','Assigned_sum', 'AccountName', 'CattleFolder/Frame','Recording','Waiting4Video', 'Waiting4Assignment', 'Labelling', 'Waiting4Labels', 'Waiting4Verification','Waiting4Completion']].set_index(['AccountNumber', 'AccountName', 'CattleFolder/Frame']).plot(kind='barh', stacked=True, ax=ax, color=colors);
|
78 |
+
fig.tight_layout()
|
79 |
return fig
|
80 |
|
81 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 15
|
82 |
def get_floating_hist(df, col):
|
83 |
grp_df = get_floating_grp_data(df)
|
84 |
fig, ax = plt.subplots()
|
|
|
90 |
return fig
|
91 |
# get_floating_hist(df, 'Recording_Duration')
|
92 |
|
93 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 17
|
94 |
def get_step_df(grp_df, start_step, end_step, step_name):
|
95 |
df_e = grp_df[['AccountNumber', 'AccountName','Assigned_sum', 'CattleFolder/Frame']].copy()
|
96 |
df_e['Start'] = grp_df[start_step]
|
|
|
99 |
return df_e
|
100 |
|
101 |
|
102 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 19
|
103 |
def get_gantt(df):
|
104 |
steps = [
|
105 |
{'start_step': 'Recording_Date_min', 'end_step' :'Recording_Date_max', 'step_name' : 'Recording'},
|
|
|
126 |
# ))
|
127 |
return fig
|
128 |
|
129 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 23
|
130 |
+
#|eval: false
|
131 |
df = None
|
132 |
st.write("# Floating Details")
|
133 |
if 'processed_df' not in st.session_state:
|
|
|
138 |
colors = st.session_state['colors']
|
139 |
colors2= st.session_state['colors2']
|
140 |
st.markdown("## Summary Floating Durations")
|
141 |
+
kpi(df)
|
142 |
with st.container(border=True):
|
143 |
+
|
144 |
st.pyplot(get_floating_summary(df))
|
145 |
ncols = 3
|
146 |
dcols = st.columns(ncols)
|