Spaces:
Sleeping
Sleeping
File size: 9,656 Bytes
a61aa1b d6a3367 39149ca d6a3367 a61aa1b d6a3367 a61aa1b 39149ca a61aa1b 39149ca a61aa1b 39149ca a61aa1b 39149ca a61aa1b 39149ca a61aa1b 39149ca a61aa1b 39149ca a61aa1b 39149ca a61aa1b 39149ca a61aa1b 2789115 a61aa1b d6a3367 a61aa1b d6a3367 a61aa1b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
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 = """
<style>
footer {visibility: hidden;}
</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'<a href="{lien_url}">{lien_label}</a>'
st.sidebar.markdown(lien_html, unsafe_allow_html=True)
app()
|