LabellingTracker / andon.py
rahuketu86's picture
Upload 6 files
7b444b5 verified
raw
history blame
No virus
5.87 kB
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/book/LabellingTracker/11_Andon.ipynb.
# %% auto 0
__all__ = ['df', 'get_data', 'get_df_extra', 'kpi', 'get_floating_count', 'get_model_count']
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 2
import streamlit as st
import pandas as pd
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 6
st.set_page_config(
page_title="Andon",
layout='wide'
)
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 9
def get_data(fname="Labelling_Tracking_v28.06.24.xlsx",
sheet_name='MASTER',
date_cols=['Recording_Date', 'Assignment_Date', 'Video_Reception_Date','Target_Date', 'Labelling_Received_Date', 'Verification_Date', 'Completion/Rejection_Date']):
df = pd.read_excel(fname, sheet_name=sheet_name,
parse_dates=date_cols)
df['Assigned']=df['Assigned'].str.split(".").str.join(" ").str.upper()
return df
# colors
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 10
def get_df_extra(fname):
df = get_data(fname=fname,
sheet_name='MASTER',
date_cols=['Recording_Date', 'Assignment_Date', 'Video_Reception_Date','Target_Date', 'Labelling_Received_Date', 'Verification_Date', 'Completion/Rejection_Date'])
col_order= pd.read_excel(fname, sheet_name='STATUS')
col_order = col_order['STATUS STATES'].tolist()
colors = dict(zip(col_order, sns.color_palette("Set2", len(col_order))))
# col_order
colors2 = dict(zip(col_order, ['blue', 'red', 'green', 'yellow', 'cyan', 'violet', 'pink', 'magenta']))
return df, col_order, colors, colors2
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 13
def kpi(df):
cattle_days = df.loc[df['TAG']=='FLOATING', ['CattleFolder/Frame', 'SubFolder']].groupby('CattleFolder/Frame').count().sum().values[0]
model_days = df.loc[df['TAG']=='MODEL', ['CattleFolder/Frame', 'SubFolder']].groupby('CattleFolder/Frame').count().sum().values[0]
cattle_floating = df.loc[df['TAG']=='FLOATING', ['CattleFolder/Frame']].nunique().values[0]
accounts_floating = df.loc[df['TAG']=='FLOATING', 'AccountNumber'].nunique()
frames_model = df.loc[df['TAG']=='MODEL', ['AccountNumber', 'CattleFolder/Frame']].groupby('AccountNumber').nunique().sum().values[0]
accounts_model = df.loc[df['TAG']=='MODEL', 'AccountNumber'].nunique()
count_user_floating = len(set(df.loc[df['TAG']=='FLOATING', 'Assigned'].dropna().str.split('/').sum()))
count_model_floating = len(set(df.loc[df['TAG']=='MODEL', 'Assigned'].dropna().str.split('/').sum()))
col1, col2, col3, col4 = st.columns(4)
col1.metric('Floating Days/Cattle', f'{cattle_days}/{cattle_floating}[{accounts_floating}]')
col2.metric('Labellers Floating', count_user_floating)
col3.metric('Model Days/Frame',f'{model_days}/{frames_model}[{accounts_model}]')
col4.metric('Labellers Model', count_model_floating)
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 14
def get_floating_count(df, col_order, colors):
fig, ax = plt.subplots()
# 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)
data = df.loc[df['TAG']=='FLOATING', ['AccountNumber', 'AccountName', 'Status', 'CattleFolder/Frame']].drop_duplicates()
o = data.groupby(['AccountNumber','AccountName', 'Status'])['CattleFolder/Frame'].count().unstack('Status').fillna(0).sort_values(by='AccountName')
sel_cols = [x for x in col_order if x in o.columns]
sel_colors = {k:colors[k] for k in sel_cols}
o[sel_cols].plot(kind='barh', stacked=True, ax=ax, color=sel_colors)
# ax.bar_label(ax.containers[-1])
return fig
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 16
def get_model_count(df,col_order, colors):
fig, ax = plt.subplots()
# 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)
data = df.loc[df['TAG']=='MODEL', ['AccountNumber', 'AccountName', 'Status', 'CattleFolder/Frame', 'SubFolder']].drop_duplicates()
o = data.groupby(['AccountNumber','AccountName', 'Status'])['CattleFolder/Frame'].count().unstack('Status').fillna(0).sort_values(by='AccountName')
sel_cols = [x for x in col_order if x in o.columns]
sel_colors = {k:colors[k] for k in sel_cols}
o[sel_cols].plot(kind='barh', stacked=True, ax=ax, color=colors)
# ax.bar_label(ax.containers[0])
return fig
# %% ../../nbs/book/LabellingTracker/11_Andon.ipynb 18
df = None
st.write("# Labelling Andon Board")
if 'processed_df' not in st.session_state:
uploaded_file = st.file_uploader("Choose a file", type = 'xlsx')
if uploaded_file is not None:
df, col_order, colors, colors2=get_df_extra(uploaded_file)
st.session_state['processed_df'] = df
st.session_state['col_order'] = col_order
st.session_state['colors'] = colors
st.session_state['colors2'] = colors2
else:
df = st.session_state['processed_df']
col_order = st.session_state['col_order']
colors = st.session_state['colors']
colors2= st.session_state['colors2']
if df is not None:
kpi(df)
st.write("## Total Available")
col1, col2 = st.columns(2)
with col1:
st.markdown("Number of Cattles per Floating Account")
fig = get_floating_count(df, col_order, colors)
st.pyplot(fig)
with col2:
st.markdown("Frame-Dates per Model Account")
fig2 = get_model_count(df, col_order, colors)
st.pyplot(fig2)