Spaces:
Sleeping
Sleeping
Upload 6 files
Browse filesAdded application
- andon.py +118 -0
- app.py +27 -0
- floating.py +135 -0
- master.py +34 -0
- model.py +140 -0
- requirements.txt +4 -0
andon.py
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/book/LabellingTracker/11_Andon.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['df', 'get_data', 'get_df_extra', 'kpi', 'get_floating_count', 'get_model_count']
|
5 |
+
|
6 |
+
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 2
|
7 |
+
import streamlit as st
|
8 |
+
import pandas as pd
|
9 |
+
import numpy as np
|
10 |
+
import pandas as pd
|
11 |
+
import matplotlib.pyplot as plt
|
12 |
+
import seaborn as sns
|
13 |
+
import plotly.express as px
|
14 |
+
|
15 |
+
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 6
|
16 |
+
st.set_page_config(
|
17 |
+
page_title="Andon",
|
18 |
+
layout='wide'
|
19 |
+
)
|
20 |
+
|
21 |
+
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 9
|
22 |
+
def get_data(fname="Labelling_Tracking_v28.06.24.xlsx",
|
23 |
+
sheet_name='MASTER',
|
24 |
+
date_cols=['Recording_Date', 'Assignment_Date', 'Video_Reception_Date','Target_Date', 'Labelling_Received_Date', 'Verification_Date', 'Completion/Rejection_Date']):
|
25 |
+
df = pd.read_excel(fname, sheet_name=sheet_name,
|
26 |
+
parse_dates=date_cols)
|
27 |
+
|
28 |
+
df['Assigned']=df['Assigned'].str.split(".").str.join(" ").str.upper()
|
29 |
+
return df
|
30 |
+
# colors
|
31 |
+
|
32 |
+
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 10
|
33 |
+
def get_df_extra(fname):
|
34 |
+
df = get_data(fname=fname,
|
35 |
+
sheet_name='MASTER',
|
36 |
+
date_cols=['Recording_Date', 'Assignment_Date', 'Video_Reception_Date','Target_Date', 'Labelling_Received_Date', 'Verification_Date', 'Completion/Rejection_Date'])
|
37 |
+
|
38 |
+
|
39 |
+
col_order= pd.read_excel(fname, sheet_name='STATUS')
|
40 |
+
col_order = col_order['STATUS STATES'].tolist()
|
41 |
+
|
42 |
+
colors = dict(zip(col_order, sns.color_palette("Set2", len(col_order))))
|
43 |
+
# col_order
|
44 |
+
|
45 |
+
colors2 = dict(zip(col_order, ['blue', 'red', 'green', 'yellow', 'cyan', 'violet', 'pink', 'magenta']))
|
46 |
+
return df, col_order, colors, colors2
|
47 |
+
|
48 |
+
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 13
|
49 |
+
def kpi(df):
|
50 |
+
cattle_days = df.loc[df['TAG']=='FLOATING', ['CattleFolder/Frame', 'SubFolder']].groupby('CattleFolder/Frame').count().sum().values[0]
|
51 |
+
model_days = df.loc[df['TAG']=='MODEL', ['CattleFolder/Frame', 'SubFolder']].groupby('CattleFolder/Frame').count().sum().values[0]
|
52 |
+
cattle_floating = df.loc[df['TAG']=='FLOATING', ['CattleFolder/Frame']].nunique().values[0]
|
53 |
+
accounts_floating = df.loc[df['TAG']=='FLOATING', 'AccountNumber'].nunique()
|
54 |
+
frames_model = df.loc[df['TAG']=='MODEL', ['AccountNumber', 'CattleFolder/Frame']].groupby('AccountNumber').nunique().sum().values[0]
|
55 |
+
accounts_model = df.loc[df['TAG']=='MODEL', 'AccountNumber'].nunique()
|
56 |
+
count_user_floating = len(set(df.loc[df['TAG']=='FLOATING', 'Assigned'].dropna().str.split('/').sum()))
|
57 |
+
count_model_floating = len(set(df.loc[df['TAG']=='MODEL', 'Assigned'].dropna().str.split('/').sum()))
|
58 |
+
col1, col2, col3, col4 = st.columns(4)
|
59 |
+
col1.metric('Floating Days/Cattle', f'{cattle_days}/{cattle_floating}[{accounts_floating}]')
|
60 |
+
col2.metric('Labellers Floating', count_user_floating)
|
61 |
+
col3.metric('Model Days/Frame',f'{model_days}/{frames_model}[{accounts_model}]')
|
62 |
+
col4.metric('Labellers Model', count_model_floating)
|
63 |
+
|
64 |
+
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 14
|
65 |
+
def get_floating_count(df, col_order, colors):
|
66 |
+
fig, ax = plt.subplots()
|
67 |
+
# df.loc[df['TAG']=='FLOATING', ['AccountNumber', 'AccountName','CattleFolder/Frame']].groupby(['AccountNumber', 'AccountName']).nunique().rename(columns={'CattleFolder/Frame':'Count'}).sort_values(by='Count').plot(kind='barh', ax=ax)
|
68 |
+
data = df.loc[df['TAG']=='FLOATING', ['AccountNumber', 'AccountName', 'Status', 'CattleFolder/Frame']].drop_duplicates()
|
69 |
+
o = data.groupby(['AccountNumber','AccountName', 'Status'])['CattleFolder/Frame'].count().unstack('Status').fillna(0).sort_values(by='AccountName')
|
70 |
+
sel_cols = [x for x in col_order if x in o.columns]
|
71 |
+
sel_colors = {k:colors[k] for k in sel_cols}
|
72 |
+
o[sel_cols].plot(kind='barh', stacked=True, ax=ax, color=sel_colors)
|
73 |
+
# ax.bar_label(ax.containers[-1])
|
74 |
+
return fig
|
75 |
+
|
76 |
+
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 16
|
77 |
+
def get_model_count(df,col_order, colors):
|
78 |
+
fig, ax = plt.subplots()
|
79 |
+
# df.loc[df['TAG']=='MODEL', ['AccountNumber', 'AccountName','CattleFolder/Frame']].groupby(['AccountNumber', 'AccountName']).count().rename(columns={'CattleFolder/Frame':'Count'}).sort_values(by='Count').plot(kind='barh', ax=ax)
|
80 |
+
data = df.loc[df['TAG']=='MODEL', ['AccountNumber', 'AccountName', 'Status', 'CattleFolder/Frame', 'SubFolder']].drop_duplicates()
|
81 |
+
o = data.groupby(['AccountNumber','AccountName', 'Status'])['CattleFolder/Frame'].count().unstack('Status').fillna(0).sort_values(by='AccountName')
|
82 |
+
sel_cols = [x for x in col_order if x in o.columns]
|
83 |
+
sel_colors = {k:colors[k] for k in sel_cols}
|
84 |
+
o[sel_cols].plot(kind='barh', stacked=True, ax=ax, color=colors)
|
85 |
+
# ax.bar_label(ax.containers[0])
|
86 |
+
return fig
|
87 |
+
|
88 |
+
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 18
|
89 |
+
df = None
|
90 |
+
st.write("# Labelling Andon Board")
|
91 |
+
if 'processed_df' not in st.session_state:
|
92 |
+
uploaded_file = st.file_uploader("Choose a file", type = 'xlsx')
|
93 |
+
if uploaded_file is not None:
|
94 |
+
df, col_order, colors, colors2=get_df_extra(uploaded_file)
|
95 |
+
st.session_state['processed_df'] = df
|
96 |
+
st.session_state['col_order'] = col_order
|
97 |
+
st.session_state['colors'] = colors
|
98 |
+
st.session_state['colors2'] = colors2
|
99 |
+
else:
|
100 |
+
df = st.session_state['processed_df']
|
101 |
+
col_order = st.session_state['col_order']
|
102 |
+
colors = st.session_state['colors']
|
103 |
+
colors2= st.session_state['colors2']
|
104 |
+
|
105 |
+
if df is not None:
|
106 |
+
kpi(df)
|
107 |
+
|
108 |
+
st.write("## Total Available")
|
109 |
+
col1, col2 = st.columns(2)
|
110 |
+
with col1:
|
111 |
+
st.markdown("Number of Cattles per Floating Account")
|
112 |
+
fig = get_floating_count(df, col_order, colors)
|
113 |
+
st.pyplot(fig)
|
114 |
+
|
115 |
+
with col2:
|
116 |
+
st.markdown("Frame-Dates per Model Account")
|
117 |
+
fig2 = get_model_count(df, col_order, colors)
|
118 |
+
st.pyplot(fig2)
|
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/book/LabellingTracker/10_App.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['andon_page', 'floating_page', 'model_page', 'master_page']
|
5 |
+
|
6 |
+
# %% ../../nbs/book/LabellingTracker/10_App.ipynb 3
|
7 |
+
import streamlit as st
|
8 |
+
|
9 |
+
# %% ../../nbs/book/LabellingTracker/10_App.ipynb 5
|
10 |
+
# def menu():
|
11 |
+
# st.sidebar.page_link(st.Page("andon.py", default=True), label="Andon")
|
12 |
+
# st.sidebar.page_link(st.Page("floating.py", url_path=".."), label="Floating")
|
13 |
+
# st.sidebar.page_link(st.Page("model.py", url_path=".."), label="Model")
|
14 |
+
# st.sidebar.page_link(st.Page("master.py", url_path=".."), label="Master")
|
15 |
+
# # st.sidebar.page_link("pages/2_mapping_demo.py", label="Mapping Demo")
|
16 |
+
# # st.sidebar.page_link("pages/3_dataframe_demo.py", label="Dataframe Demo")
|
17 |
+
|
18 |
+
|
19 |
+
andon_page = st.Page("andon.py", default=True, title="Andon")
|
20 |
+
floating_page = st.Page("floating.py", title="Floating")
|
21 |
+
model_page = st.Page("model.py", title="Model")
|
22 |
+
master_page = st.Page("master.py", title="Master")
|
23 |
+
|
24 |
+
from fastcore.basics import in_notebook
|
25 |
+
if not in_notebook():
|
26 |
+
pg = st.navigation([andon_page, floating_page, model_page, master_page])
|
27 |
+
pg.run()
|
floating.py
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
8 |
+
import pandas as pd
|
9 |
+
|
10 |
+
import numpy as np
|
11 |
+
import pandas as pd
|
12 |
+
import matplotlib.pyplot as plt
|
13 |
+
import plotly.express as px
|
14 |
+
import seaborn as sns
|
15 |
+
|
16 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 6
|
17 |
+
st.set_page_config(
|
18 |
+
page_title="Floating",
|
19 |
+
page_icon="👋",
|
20 |
+
layout='wide'
|
21 |
+
)
|
22 |
+
|
23 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 8
|
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',
|
29 |
+
'Recording_Date', 'Video_Reception_Date', 'Assignment_Date',
|
30 |
+
'Target_Date', 'Labelling_Received_Date','Verification_Date', 'Completion/Rejection_Date']].groupby(['Trial_Num',
|
31 |
+
'AccountNumber',
|
32 |
+
'AccountName',
|
33 |
+
'TAG',
|
34 |
+
'CattleFolder/Frame',
|
35 |
+
],
|
36 |
+
as_index=False).agg({'Recording_Date':['min','max'],
|
37 |
+
'Video_Reception_Date':'max',
|
38 |
+
'Assignment_Date':'min',
|
39 |
+
'Target_Date':'max',
|
40 |
+
'Labelling_Received_Date':'max',
|
41 |
+
'Verification_Date':'max',
|
42 |
+
'Completion/Rejection_Date':'max',
|
43 |
+
'Assigned': 'sum'})
|
44 |
+
|
45 |
+
flat_cols = ["_".join(i).rstrip('_') for i in grp_df.columns];# flat_cols
|
46 |
+
grp_df.columns = flat_cols
|
47 |
+
grp_df['Recording'] = (grp_df['Recording_Date_max'] - grp_df['Recording_Date_min']).dt.days+1
|
48 |
+
grp_df['Waiting4Video'] = (grp_df['Video_Reception_Date_max'] - grp_df['Recording_Date_max']).dt.days
|
49 |
+
grp_df['Waiting4Assignment'] = (grp_df['Assignment_Date_min'] - grp_df['Video_Reception_Date_max']).dt.days
|
50 |
+
grp_df['Labelling'] = (grp_df['Target_Date_max'] - grp_df['Assignment_Date_min']).dt.days
|
51 |
+
grp_df['Waiting4Labels'] = (grp_df['Labelling_Received_Date_max'] - grp_df['Target_Date_max']).dt.days
|
52 |
+
grp_df['Waiting4Verification'] = (grp_df['Verification_Date_max'] - grp_df['Labelling_Received_Date_max']).dt.days
|
53 |
+
grp_df['Waiting4Completion'] = (grp_df['Completion/Rejection_Date_max'] - grp_df['Verification_Date_max']).dt.days
|
54 |
+
grp_df['Labelling_Duration'] = grp_df['Labelling'] + grp_df['Waiting4Labels'].fillna(0)
|
55 |
+
return grp_df
|
56 |
+
|
57 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 13
|
58 |
+
def get_floating_summary(df):
|
59 |
+
fig, ax = plt.subplots()
|
60 |
+
grp_df = get_floating_grp_data(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 14
|
67 |
+
def get_floating_hist(df, col):
|
68 |
+
grp_df = get_floating_grp_data(df)
|
69 |
+
fig, ax = plt.subplots()
|
70 |
+
grp_df[col].plot(kind='hist', ax=ax, legend=True)
|
71 |
+
avg = grp_df[col].mean()
|
72 |
+
count = grp_df[col].count()
|
73 |
+
ax.axvline(avg, color='red', label=f'mean={avg}')
|
74 |
+
ax.set_title(f'{col}[ mean={avg:.2f}, count={count:.2f} ]')
|
75 |
+
return fig
|
76 |
+
# get_floating_hist(df, 'Recording_Duration')
|
77 |
+
|
78 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 15
|
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]
|
82 |
+
df_e['End'] = grp_df[end_step]
|
83 |
+
df_e['Step'] = step_name
|
84 |
+
return df_e
|
85 |
+
|
86 |
+
|
87 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 17
|
88 |
+
def get_gantt(df):
|
89 |
+
steps = [
|
90 |
+
{'start_step': 'Recording_Date_min', 'end_step' :'Recording_Date_max', 'step_name' : 'Recording'},
|
91 |
+
{'start_step': 'Recording_Date_max', 'end_step' :'Video_Reception_Date_max', 'step_name' : 'Waiting4Video'},
|
92 |
+
{'start_step': 'Video_Reception_Date_max', 'end_step' :'Assignment_Date_min', 'step_name' : 'Waiting4Assignment'},
|
93 |
+
{'start_step': 'Assignment_Date_min', 'end_step' :'Target_Date_max', 'step_name' : 'Labelling'},
|
94 |
+
{'start_step': 'Target_Date_max', 'end_step' :'Labelling_Received_Date_max', 'step_name' : 'Waiting4Labels'},
|
95 |
+
{'start_step': 'Labelling_Received_Date_max', 'end_step' :'Verification_Date_max', 'step_name' : 'Waiting4Verification'},
|
96 |
+
{'start_step': 'Verification_Date_max', 'end_step' :'Completion/Rejection_Date_max', 'step_name' : 'Waiting4Completion'},
|
97 |
+
]
|
98 |
+
grp_df = get_floating_grp_data(df)
|
99 |
+
df_concat = pd.concat(get_step_df(grp_df, start_step=step['start_step'], end_step=step['end_step'], step_name=step['step_name']) for step in steps)
|
100 |
+
df_concat['label'] = df['AccountName'] +"_"+ df['CattleFolder/Frame']
|
101 |
+
df_concat.loc[df_concat['Step']=='Recording', 'Start'] = df_concat.loc[df_concat['Step']=='Recording', 'Start'] - pd.Timedelta(days=1)
|
102 |
+
# # df_concat
|
103 |
+
|
104 |
+
states = [s['step_name'] for s in steps]; # states
|
105 |
+
colors = dict(zip(states, ['blue', 'red', 'green', 'yellow', 'cyan', 'violet', 'pink']))
|
106 |
+
|
107 |
+
fig = px.timeline(data_frame=df_concat, x_start='Start', x_end='End', y='CattleFolder/Frame', color='Step', color_discrete_map=colors, hover_data=['Assigned_sum', 'AccountName', 'AccountNumber'])
|
108 |
+
# fig.update_layout(legend=dict(
|
109 |
+
# orientation="h",
|
110 |
+
|
111 |
+
# ))
|
112 |
+
return fig
|
113 |
+
|
114 |
+
# %% ../../nbs/book/LabellingTracker/13_Floating.ipynb 21
|
115 |
+
df = None
|
116 |
+
st.write("# Floating Details")
|
117 |
+
if 'processed_df' not in st.session_state:
|
118 |
+
st.write("Please go to andon page and upload data")
|
119 |
+
else:
|
120 |
+
df = st.session_state['processed_df']
|
121 |
+
col_order = st.session_state['col_order']
|
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)
|
129 |
+
for i, col in enumerate(['Recording','Waiting4Video', 'Waiting4Assignment', 'Labelling_Duration', 'Waiting4Verification', 'Waiting4Completion']):
|
130 |
+
with dcols[i%ncols]:
|
131 |
+
st.pyplot(get_floating_hist(df, col), use_container_width=True)
|
132 |
+
|
133 |
+
st.markdown("## Timeline")
|
134 |
+
with st.container(border=True):
|
135 |
+
st.plotly_chart(get_gantt(df), theme="streamlit", use_container_width=True)
|
master.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/book/LabellingTracker/12_MasterTable.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['df']
|
5 |
+
|
6 |
+
# %% ../../nbs/book/LabellingTracker/12_MasterTable.ipynb 2
|
7 |
+
import streamlit as st
|
8 |
+
import pandas as pd
|
9 |
+
import numpy as np
|
10 |
+
import pandas as pd
|
11 |
+
import matplotlib.pyplot as plt
|
12 |
+
|
13 |
+
|
14 |
+
# %% ../../nbs/book/LabellingTracker/12_MasterTable.ipynb 6
|
15 |
+
st.set_page_config(
|
16 |
+
page_title="Master",
|
17 |
+
page_icon="👋",
|
18 |
+
layout='wide'
|
19 |
+
)
|
20 |
+
|
21 |
+
# %% ../../nbs/book/LabellingTracker/12_MasterTable.ipynb 8
|
22 |
+
# st.sidebar.success("Select a demo above.")
|
23 |
+
|
24 |
+
# %% ../../nbs/book/LabellingTracker/12_MasterTable.ipynb 10
|
25 |
+
df = None
|
26 |
+
st.write("# Master Table")
|
27 |
+
if 'processed_df' not in st.session_state:
|
28 |
+
st.write("Please go to andon page and upload data")
|
29 |
+
else:
|
30 |
+
df = st.session_state['processed_df']
|
31 |
+
col_order = st.session_state['col_order']
|
32 |
+
colors = st.session_state['colors']
|
33 |
+
colors2= st.session_state['colors2']
|
34 |
+
st.table(data=df)
|
model.py
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/book/LabellingTracker/14_Model.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['df', 'get_model_grp_data', 'get_model_summary', 'get_model_hist', 'get_step_df', 'get_gantt']
|
5 |
+
|
6 |
+
# %% ../../nbs/book/LabellingTracker/14_Model.ipynb 2
|
7 |
+
import streamlit as st
|
8 |
+
import pandas as pd
|
9 |
+
|
10 |
+
import numpy as np
|
11 |
+
import pandas as pd
|
12 |
+
import matplotlib.pyplot as plt
|
13 |
+
import plotly.express as px
|
14 |
+
import seaborn as sns
|
15 |
+
|
16 |
+
# %% ../../nbs/book/LabellingTracker/14_Model.ipynb 6
|
17 |
+
st.set_page_config(
|
18 |
+
page_title="Model",
|
19 |
+
page_icon="👋",
|
20 |
+
layout='wide'
|
21 |
+
)
|
22 |
+
|
23 |
+
# %% ../../nbs/book/LabellingTracker/14_Model.ipynb 8
|
24 |
+
# st.sidebar.success("Select a demo above.")
|
25 |
+
|
26 |
+
# %% ../../nbs/book/LabellingTracker/14_Model.ipynb 11
|
27 |
+
def get_model_grp_data(df):
|
28 |
+
grp_df = df.loc[df['TAG']=='MODEL', ['Trial_Num', 'AccountNumber', 'AccountName', 'CattleFolder/Frame','SubFolder', 'TAG', 'Assigned',
|
29 |
+
'Recording_Date', 'Video_Reception_Date', 'Assignment_Date',
|
30 |
+
'Target_Date', 'Labelling_Received_Date','Verification_Date', 'Completion/Rejection_Date']].groupby(['Trial_Num',
|
31 |
+
'AccountNumber',
|
32 |
+
'AccountName',
|
33 |
+
'TAG',
|
34 |
+
'CattleFolder/Frame',
|
35 |
+
'SubFolder'
|
36 |
+
],
|
37 |
+
as_index=False).agg({'Recording_Date':['min','max'],
|
38 |
+
'Video_Reception_Date':'max',
|
39 |
+
'Assignment_Date':'min',
|
40 |
+
'Target_Date':'max',
|
41 |
+
'Labelling_Received_Date':'max',
|
42 |
+
'Verification_Date':'max',
|
43 |
+
'Completion/Rejection_Date':'max',
|
44 |
+
'Assigned': 'sum'})
|
45 |
+
|
46 |
+
flat_cols = ["_".join(i).rstrip('_') for i in grp_df.columns];# flat_cols
|
47 |
+
grp_df.columns = flat_cols
|
48 |
+
grp_df['Recording'] = (grp_df['Recording_Date_max'] - grp_df['Recording_Date_min']).dt.days+1
|
49 |
+
grp_df['Waiting4Video'] = (grp_df['Video_Reception_Date_max'] - grp_df['Recording_Date_max']).dt.days
|
50 |
+
grp_df['Waiting4Assignment'] = (grp_df['Assignment_Date_min'] - grp_df['Video_Reception_Date_max']).dt.days
|
51 |
+
grp_df['Labelling'] = (grp_df['Target_Date_max'] - grp_df['Assignment_Date_min']).dt.days
|
52 |
+
grp_df['Waiting4Labels'] = (grp_df['Labelling_Received_Date_max'] - grp_df['Target_Date_max']).dt.days
|
53 |
+
grp_df['Waiting4Verification'] = (grp_df['Verification_Date_max'] - grp_df['Labelling_Received_Date_max']).dt.days
|
54 |
+
grp_df['Waiting4Completion'] = (grp_df['Completion/Rejection_Date_max'] - grp_df['Verification_Date_max']).dt.days
|
55 |
+
grp_df['Labelling_Duration'] = grp_df['Labelling'] + grp_df['Waiting4Labels'].fillna(0)
|
56 |
+
return grp_df
|
57 |
+
|
58 |
+
# %% ../../nbs/book/LabellingTracker/14_Model.ipynb 14
|
59 |
+
def get_model_summary(df, kind='sum'):
|
60 |
+
fig, ax = plt.subplots()
|
61 |
+
grp_df = get_model_grp_data(df)
|
62 |
+
states = ['Recording','Waiting4Video', 'Waiting4Assignment', 'Labelling', 'Waiting4Labels', 'Waiting4Verification','Waiting4Completion']
|
63 |
+
colors = dict(zip(states, ['blue', 'red', 'green', 'yellow', 'cyan', 'violet', 'pink']))
|
64 |
+
grp_df[['AccountNumber','AccountName', 'CattleFolder/Frame',
|
65 |
+
'Recording','Waiting4Video', 'Waiting4Assignment', 'Labelling', 'Waiting4Labels', 'Waiting4Verification','Waiting4Completion']].groupby(['AccountNumber', 'AccountName', 'CattleFolder/Frame'], as_index=False).agg(kind).set_index(['AccountNumber', 'AccountName', 'CattleFolder/Frame']).plot(kind='barh', stacked=True, ax=ax, color=colors, legend=False);
|
66 |
+
fig.legend(loc='upper right')
|
67 |
+
return fig
|
68 |
+
|
69 |
+
# %% ../../nbs/book/LabellingTracker/14_Model.ipynb 16
|
70 |
+
def get_model_hist(df, col):
|
71 |
+
grp_df = get_model_grp_data(df)
|
72 |
+
fig, ax = plt.subplots()
|
73 |
+
grp_df[col].plot(kind='hist', ax=ax, legend=True)
|
74 |
+
avg = grp_df[col].mean()
|
75 |
+
count = grp_df[col].count()
|
76 |
+
ax.axvline(avg, color='red', label=f'mean={avg}')
|
77 |
+
ax.set_title(f'{col}[ mean={avg:.2f}, count={count:.2f} ]')
|
78 |
+
return fig
|
79 |
+
# get_floating_hist(df, 'Recording_Duration')
|
80 |
+
|
81 |
+
# %% ../../nbs/book/LabellingTracker/14_Model.ipynb 17
|
82 |
+
def get_step_df(grp_df, start_step, end_step, step_name):
|
83 |
+
df_e = grp_df[['AccountNumber', 'AccountName','Assigned_sum', 'CattleFolder/Frame', 'SubFolder']].copy()
|
84 |
+
df_e['Start'] = grp_df[start_step]
|
85 |
+
df_e['End'] = grp_df[end_step]
|
86 |
+
df_e['Step'] = step_name
|
87 |
+
return df_e
|
88 |
+
|
89 |
+
|
90 |
+
# %% ../../nbs/book/LabellingTracker/14_Model.ipynb 19
|
91 |
+
def get_gantt(df):
|
92 |
+
steps = [
|
93 |
+
{'start_step': 'Recording_Date_min', 'end_step' :'Recording_Date_max', 'step_name' : 'Recording'},
|
94 |
+
{'start_step': 'Recording_Date_max', 'end_step' :'Video_Reception_Date_max', 'step_name' : 'Waiting4Video'},
|
95 |
+
{'start_step': 'Video_Reception_Date_max', 'end_step' :'Assignment_Date_min', 'step_name' : 'Waiting4Assignment'},
|
96 |
+
{'start_step': 'Assignment_Date_min', 'end_step' :'Target_Date_max', 'step_name' : 'Labelling'},
|
97 |
+
{'start_step': 'Target_Date_max', 'end_step' :'Labelling_Received_Date_max', 'step_name' : 'Waiting4Labels'},
|
98 |
+
{'start_step': 'Labelling_Received_Date_max', 'end_step' :'Verification_Date_max', 'step_name' : 'Waiting4Verification'},
|
99 |
+
{'start_step': 'Verification_Date_max', 'end_step' :'Completion/Rejection_Date_max', 'step_name' : 'Waiting4Completion'},
|
100 |
+
]
|
101 |
+
grp_df = get_model_grp_data(df)
|
102 |
+
df_concat = pd.concat(get_step_df(grp_df, start_step=step['start_step'], end_step=step['end_step'], step_name=step['step_name']) for step in steps)
|
103 |
+
df_concat['label'] = df_concat[['AccountNumber', 'AccountName', 'CattleFolder/Frame']].apply(lambda row: "_".join(row), axis=1)
|
104 |
+
df_concat.loc[df_concat['Step']=='Recording', 'Start'] = df_concat.loc[df_concat['Step']=='Recording', 'Start'] - pd.Timedelta(days=1)
|
105 |
+
# # df_concat
|
106 |
+
|
107 |
+
states = [s['step_name'] for s in steps]; # states
|
108 |
+
colors = dict(zip(states, ['blue', 'red', 'green', 'yellow', 'cyan', 'violet', 'pink']))
|
109 |
+
|
110 |
+
fig = px.timeline(data_frame=df_concat, x_start='Start', x_end='End', y='label', color='Step', color_discrete_map=colors, hover_data=['Assigned_sum', 'AccountName', 'AccountNumber'])
|
111 |
+
# fig.update_layout(legend=dict(
|
112 |
+
# orientation="h",
|
113 |
+
|
114 |
+
# ))
|
115 |
+
return fig
|
116 |
+
|
117 |
+
# %% ../../nbs/book/LabellingTracker/14_Model.ipynb 23
|
118 |
+
df = None
|
119 |
+
st.write("# Model Details")
|
120 |
+
if 'processed_df' not in st.session_state:
|
121 |
+
st.write("Please go to andon page and upload data")
|
122 |
+
else:
|
123 |
+
df = st.session_state['processed_df']
|
124 |
+
st.markdown("## Summary Model Durations")
|
125 |
+
st.markdown(" Below plot includes a summary of all the frames in different model farms. Process includes recording and sharing video everyday with non sequential sharing schedule")
|
126 |
+
with st.container(border=True):
|
127 |
+
tab_sum, tab_mean = st.tabs(['Sum', 'Mean'])
|
128 |
+
with tab_sum:
|
129 |
+
st.pyplot(get_model_summary(df))
|
130 |
+
with tab_mean:
|
131 |
+
st.pyplot(get_model_summary(df, kind='mean'))
|
132 |
+
ncols = 3
|
133 |
+
dcols = st.columns(ncols)
|
134 |
+
for i, col in enumerate(['Recording','Waiting4Video', 'Waiting4Assignment', 'Labelling_Duration', 'Waiting4Verification', 'Waiting4Completion']):
|
135 |
+
with dcols[i%ncols]:
|
136 |
+
st.pyplot(get_model_hist(df, col), use_container_width=True)
|
137 |
+
|
138 |
+
st.markdown("## Timeline")
|
139 |
+
with st.container(border=True):
|
140 |
+
st.plotly_chart(get_gantt(df), theme="streamlit", use_container_width=True)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastcore
|
2 |
+
pandas
|
3 |
+
matplotlib
|
4 |
+
plotly
|