Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| 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 streamlit_extras.chart_container import chart_container | |
| st.title("Gestion des ruptures ") | |
| input_box = InputsBox() | |
| data = input_box.get_data() | |
| try: | |
| if data.shape[0] != 0 : | |
| st.header("Data") | |
| st.dataframe(data) | |
| "## Filters" | |
| col1, col2 = st.columns(2) | |
| with col1 : | |
| product_id = input_box.get_product_id() | |
| with col2 : | |
| class_id = input_box.get_class_id() | |
| 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") | |
| st.dataframe(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"] | |
| 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") | |
| st.dataframe(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") | |
| st.dataframe(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 = cond_pays_priorite(merged_final, product_id) | |
| tab1, tab2 = st.tabs(["Data without decision-making", "Data with proposed changes"]) | |
| with tab1 : | |
| st.subheader("Data without decision-making") | |
| st.dataframe(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 : | |
| "to do" | |
| except: | |
| pass | |
| st.write("An error occured. Please check your inputs.") | |