| | |
| |
|
| | |
| | __all__ = ['df', 'get_data', 'get_df_extra', 'kpi', 'get_floating_count', 'get_model_count'] |
| |
|
| | |
| | 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 |
| |
|
| | |
| | st.set_page_config( |
| | page_title="Andon", |
| | layout='wide' |
| | ) |
| |
|
| | |
| | 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 |
| | |
| |
|
| | |
| | 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)))) |
| | |
| |
|
| | colors2 = dict(zip(col_order, ['blue', 'red', 'green', 'yellow', 'cyan', 'violet', 'pink', 'magenta'])) |
| | return df, col_order, colors, colors2 |
| |
|
| | |
| | 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) |
| |
|
| | |
| | def get_floating_count(df, col_order, colors): |
| | fig, ax = plt.subplots() |
| | |
| | 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) |
| | |
| | return fig |
| |
|
| | |
| | def get_model_count(df,col_order, colors): |
| | fig, ax = plt.subplots() |
| | |
| | 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) |
| | |
| | return fig |
| |
|
| | |
| | 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) |
| |
|