import streamlit as st import pandas as pd import time from App.class_input_box.input_box import * from App.functions_rupture.functions_gestion import * from App.utils.divers_function import * from App.utils.filter_dataframe import * from App.utils.filter_dataframe import * # Page configuration st.set_page_config( page_title="Gestion des ruptures", page_icon="images/Carrefour_logo.png", layout="wide" ) hide_streamlit_style = """ """ st.markdown(hide_streamlit_style, unsafe_allow_html=True) def app(): st.title("Gestion des ruptures ") input_box = InputsBox() data = input_box.get_data() try: if data.shape[0] != 0 : st.header("Data") st.dataframe(filter_dataframe(data)) "## Parameters" col1, col2 = st.columns(2) with col1 : product_id = input_box.get_product_id() with col2 : class_id = input_box.get_class_id() '## Filters' col1, col2 = st.columns(2) with col1 : min_product_id = input_box.valid_produict_id() with col2 : vaind_class_id = input_box.valid_class_id() conditions = input_box.conditions() if st.button("RUN ", key="run_button"): data = valide_key(data, product_id, class_id, min_product_id, vaind_class_id ) Country, merged = nouvelle_data(data, str(product_id), str(class_id)) merged_final = finale_merged(merged, Country, product_id, class_id) if conditions["Show data with ratios"]: st.subheader("Show data with ratios") merged_final.loc[:, "Evaluation"]= True merged_final = st.data_editor(merged_final) csv = convert_df(merged_final) st.download_button(label="Download data as CSV", data=csv, file_name='sample_df.csv', mime='text/csv',) data_countries_ratio = cond_pays_proportion(merged_final, conditions["Number of countries"], conditions["Proportion"], product_id) df = supprime_country(data_countries_ratio) csv = convert_df(df) """## The data below is filtered as follows: """ "- Number of countries greater than or equal to ", conditions["Number of countries"] "- The proportion with the highest ", class_id ," is greater than or equal to ",conditions["Proportion"] DF = df[((df.Proportion >= conditions["Proportion"]) & (df.total_by_ligne >= conditions["Number of countries"]))] finale_df = Merger(data, DF, product_id, class_id) tab1, tab2 = st.tabs(["Data without decision-making", "Data with proposed changes"]) with tab1 : st.subheader("Data without decision-making") df.loc[:, "Evaluation"] = True df = st.data_editor(df) st.download_button(label="Download data as CSV", data=csv, file_name='sample_df.csv', mime='text/csv',) with tab2 : st.subheader("Data with proposed changes") finale_df.loc[:, "Evaluation"] = True finale_df = st.data_editor(finale_df) csv_f = convert_df(finale_df) st.download_button(label="Download data as CSV", data=csv_f, file_name='sample_df.csv', mime='text/csv',) "## Country priority " priority_data, df_equa, df_nequa = cond_pays_priorite(merged_final, product_id) tab1, tab2, tab3, tab4 = st.tabs(["Data without decision-making", "Equality case and mt1", "Cases of inequality", "Data with proposed changes mt2"]) with tab1 : st.subheader("Data without decision-making") priority_data.loc[:, "Evaluation"] = True priority_data = st.data_editor(priority_data) csv_f = convert_df(priority_data) st.download_button(label="Download data as CSV", data=csv_f, file_name='sample_df.csv', mime='text/csv',) with tab2 : st.subheader("Equality case") df_equa.loc[:, "Evaluation"]= True df_equa = st.data_editor(df_equa) csv_f = convert_df(df_equa) st.download_button(label="Download data as CSV", data=csv_f, file_name='sample_df.csv', mime='text/csv',) with tab3 : st.subheader("Cases of inequality") df_nequa_ = df_nequa[(df_nequa.total_by_ligne.apply(lambda x: int(x) > 2))] df_nequa_.loc[:, "Evaluation"]= True df_nequa_ = st.data_editor(df_nequa_) csv_f = convert_df(df_nequa_) st.download_button(label="Download data as CSV", data=csv_f, file_name='sample_df.csv', mime='text/csv',) max_poids_index = df_nequa_.groupby('BARCODE')['Poids'].idxmax() df_max_poids = df_nequa_.loc[max_poids_index] df_max_poids.drop(["COUNTRY_KEY"], axis = 1, inplace= True) finale_df_ = Merger(data,df_max_poids, product_id, class_id) with tab4 : st.subheader("Cases of inequality") finale_df_.loc[:, "Evaluation"]= True finale_df_ = st.data_editor(finale_df_) csv_f = convert_df(finale_df_) st.download_button(label="Download data as CSV", data=csv_f, file_name='sample_df.csv', mime='text/csv',) st.subheader(" One vs One with similarity score") df_nequa_1 = df_nequa[(df_nequa.total_by_ligne.apply(lambda x: int(x) == 2))] max_poids_index1 = df_nequa_1.groupby('BARCODE')['Poids'].idxmax() # Récupérer les lignes correspondantes df_max_poids1 = df_nequa_1.loc[max_poids_index1] df_max_poids1.drop(["COUNTRY_KEY"], axis = 1, inplace= True) finale_df_1 = ajout_simularite(Merger(data,df_max_poids1, product_id, class_id)) finale_df_1.loc[:, "Evaluation"]= True finale_df_1 = st.data_editor(finale_df_1) csv_f = convert_df(finale_df_1) st.download_button(label="Download data as CSV", data=csv_f, file_name='sample_df.csv', mime='text/csv',) st.success('Done!', icon="✅") st.balloons() except: pass #st.error('This is an error', icon="🚨") st.info('Ensure that column names are capitalized and that product_id and class_id descriptions are present, as well as a country column.', icon="ℹ️") if __name__ == "__main__": lien_label = "# Example of input" lien_url = "https://docs.google.com/spreadsheets/d/123hVTOFpBT-C6mCnrOBh8fFIhSi8FxiuyHZJAQu8bDc/edit#gid=1220891905" lien_html = f'{lien_label}' st.sidebar.markdown(lien_html, unsafe_allow_html=True) app()