COULIBALY BOURAHIMA commited on
Commit
2d1cd4f
·
1 Parent(s): 3558843
App/class_input_box/__pycache__/input_box.cpython-311.pyc CHANGED
Binary files a/App/class_input_box/__pycache__/input_box.cpython-311.pyc and b/App/class_input_box/__pycache__/input_box.cpython-311.pyc differ
 
App/class_input_box/input_box.py CHANGED
@@ -60,3 +60,25 @@ class InputsBox:
60
  conditions["Show data with ratios"] = countries
61
 
62
  return conditions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  conditions["Show data with ratios"] = countries
61
 
62
  return conditions
63
+
64
+
65
+ def conditions_(self):
66
+ col1, col2, col3 = st.columns(3)
67
+ conditions = {}
68
+
69
+ with col1:
70
+ nb_countries = st.number_input("Number of countries", min_value=1, max_value=20, value=1, key="Number of countries")
71
+ conditions['Number of countries'] = nb_countries
72
+
73
+ with col2 :
74
+ proportion = st.number_input("Proportion", min_value=0.10, max_value=1.00, value=0.75, key="proportion")
75
+ conditions['Proportion'] = proportion
76
+
77
+ with col3 :
78
+ countries = st.multiselect("Zone : ", options=("FRA", "BEL" ,"ESP","ITA", "BRA","ATA","ARG", "POL", "ROU", "BIG","SAM",
79
+ "UAE","SAU","KWT","OMN","BHR","QAT","JOR","EGY","ARM","UZB","IRN","KEN","GEO","LEB","UGA","PAK","IRQ",
80
+ "MTQ","GLP","REU","GUA","MTS","GLS","GUF","MTA","GLA","GUS","SXM","DOM",
81
+ "MAR","AMA","TUN","DZA","TUR","IAP","IET","TWN"), key="countries")
82
+ conditions["Countries"] = countries
83
+
84
+ return conditions
app.py CHANGED
@@ -1,213 +1,33 @@
1
  import streamlit as st
2
- import pandas as pd
3
- import time
4
- from App.class_input_box.input_box import *
5
- from App.functions_rupture.functions_gestion import *
6
- from App.utils.divers_function import *
7
- from App.utils.filter_dataframe import *
8
- from App.utils.filter_dataframe import *
9
 
10
-
11
- # Page configuration
12
  st.set_page_config(
13
- page_title="Gestion des ruptures",
14
- page_icon="images/Carrefour_logo.png",
15
- layout="wide"
 
 
16
  )
17
- hide_streamlit_style = """
18
  <style>
 
19
  footer {visibility: hidden;}
20
  </style>
21
  """
22
- st.markdown(hide_streamlit_style, unsafe_allow_html=True)
23
-
24
-
25
- def app():
26
- st.title("Gestion des ruptures ")
27
-
28
- input_box = InputsBox()
29
-
30
- data = input_box.get_data()
31
-
32
- try:
33
- if data.shape[0] != 0 :
34
- st.header("Data")
35
-
36
- st.dataframe(filter_dataframe(data))
37
-
38
- "## Parameters"
39
-
40
- col1, col2 = st.columns(2)
41
-
42
- with col1 :
43
- product_id = input_box.get_product_id()
44
-
45
- with col2 :
46
- class_id = input_box.get_class_id()
47
-
48
- '## Filters'
49
- col1, col2 = st.columns(2)
50
-
51
- with col1 :
52
- min_product_id = input_box.valid_produict_id()
53
-
54
- with col2 :
55
- vaind_class_id = input_box.valid_class_id()
56
-
57
- conditions = input_box.conditions()
58
-
59
- if st.button("RUN ", key="run_button"):
60
- data = valide_key(data, product_id, class_id, min_product_id, vaind_class_id )
61
- Country, merged = nouvelle_data(data,
62
- str(product_id),
63
- str(class_id))
64
-
65
- merged_final = finale_merged(merged,
66
- Country,
67
- product_id,
68
- class_id)
69
-
70
- if conditions["Show data with ratios"]:
71
- st.subheader("Show data with ratios")
72
- merged_final.loc[:, "Evaluation"]= True
73
- merged_final = st.data_editor(merged_final)
74
-
75
-
76
- csv = convert_df(merged_final)
77
- st.download_button(label="Download data as CSV",
78
- data=csv,
79
- file_name='sample_df.csv',
80
- mime='text/csv',)
81
-
82
- data_countries_ratio = cond_pays_proportion(merged_final,
83
- conditions["Number of countries"],
84
- conditions["Proportion"],
85
- product_id)
86
-
87
- df = supprime_country(data_countries_ratio)
88
- csv = convert_df(df)
89
-
90
- """## The data below is filtered as follows: """
91
- "- Number of countries greater than or equal to ", conditions["Number of countries"]
92
- "- The proportion with the highest ", class_id ," is greater than or equal to ",conditions["Proportion"]
93
-
94
- DF = df[((df.Proportion >= conditions["Proportion"]) & (df.total_by_ligne >= conditions["Number of countries"]))]
95
-
96
- finale_df = Merger(data,
97
- DF,
98
- product_id,
99
- class_id)
100
-
101
- tab1, tab2 = st.tabs(["Data without decision-making", "Data with proposed changes"])
102
-
103
- with tab1 :
104
- st.subheader("Data without decision-making")
105
- df.loc[:, "Evaluation"] = True
106
- df = st.data_editor(df)
107
-
108
- st.download_button(label="Download data as CSV",
109
- data=csv,
110
- file_name='sample_df.csv',
111
- mime='text/csv',)
112
-
113
- with tab2 :
114
- st.subheader("Data with proposed changes")
115
- finale_df.loc[:, "Evaluation"] = True
116
- finale_df = st.data_editor(finale_df)
117
-
118
- csv_f = convert_df(finale_df)
119
- st.download_button(label="Download data as CSV",
120
- data=csv_f,
121
- file_name='sample_df.csv',
122
- mime='text/csv',)
123
-
124
- "## Country priority "
125
-
126
- priority_data, df_equa, df_nequa = cond_pays_priorite(merged_final, product_id)
127
- tab1, tab2, tab3, tab4 = st.tabs(["Data without decision-making", "Equality case and mt1", "Cases of inequality", "Data with proposed changes mt2"])
128
-
129
- with tab1 :
130
- st.subheader("Data without decision-making")
131
- priority_data.loc[:, "Evaluation"] = True
132
- priority_data = st.data_editor(priority_data)
133
-
134
- csv_f = convert_df(priority_data)
135
- st.download_button(label="Download data as CSV",
136
- data=csv_f,
137
- file_name='sample_df.csv',
138
- mime='text/csv',)
139
-
140
- with tab2 :
141
- st.subheader("Equality case")
142
- df_equa.loc[:, "Evaluation"]= True
143
- df_equa = st.data_editor(df_equa)
144
-
145
- csv_f = convert_df(df_equa)
146
- st.download_button(label="Download data as CSV",
147
- data=csv_f,
148
- file_name='sample_df.csv',
149
- mime='text/csv',)
150
-
151
- with tab3 :
152
- st.subheader("Cases of inequality")
153
- df_nequa_ = df_nequa[(df_nequa.total_by_ligne.apply(lambda x: int(x) > 2))]
154
- df_nequa_.loc[:, "Evaluation"]= True
155
- df_nequa_ = st.data_editor(df_nequa_)
156
-
157
- csv_f = convert_df(df_nequa_)
158
- st.download_button(label="Download data as CSV",
159
- data=csv_f,
160
- file_name='sample_df.csv',
161
- mime='text/csv',)
162
-
163
-
164
-
165
- max_poids_index = df_nequa_.groupby('BARCODE')['Poids'].idxmax()
166
-
167
-
168
- df_max_poids = df_nequa_.loc[max_poids_index]
169
- df_max_poids.drop(["COUNTRY_KEY"], axis = 1, inplace= True)
170
- finale_df_ = Merger(data,df_max_poids, product_id, class_id)
171
- with tab4 :
172
- st.subheader("Cases of inequality")
173
- finale_df_.loc[:, "Evaluation"]= True
174
- finale_df_ = st.data_editor(finale_df_)
175
-
176
- csv_f = convert_df(finale_df_)
177
- st.download_button(label="Download data as CSV",
178
- data=csv_f,
179
- file_name='sample_df.csv',
180
- mime='text/csv',)
181
-
182
- st.subheader(" One vs One with similarity score")
183
- df_nequa_1 = df_nequa[(df_nequa.total_by_ligne.apply(lambda x: int(x) == 2))]
184
-
185
- max_poids_index1 = df_nequa_1.groupby('BARCODE')['Poids'].idxmax()
186
-
187
- # Récupérer les lignes correspondantes
188
- df_max_poids1 = df_nequa_1.loc[max_poids_index1]
189
- df_max_poids1.drop(["COUNTRY_KEY"], axis = 1, inplace= True)
190
- finale_df_1 = ajout_simularite(Merger(data,df_max_poids1, product_id, class_id))
191
- finale_df_1.loc[:, "Evaluation"]= True
192
- finale_df_1 = st.data_editor(finale_df_1)
193
- csv_f = convert_df(finale_df_1)
194
- st.download_button(label="Download data as CSV",
195
- data=csv_f,
196
- file_name='sample_df.csv',
197
- mime='text/csv',)
198
- st.success('Done!', icon="✅")
199
- st.balloons()
200
-
201
- except:
202
- pass
203
- #st.error('This is an error', icon="🚨")
204
- 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="ℹ️")
205
-
206
-
207
- if __name__ == "__main__":
208
- lien_label = "# Example of input"
209
- lien_url = "https://docs.google.com/spreadsheets/d/123hVTOFpBT-C6mCnrOBh8fFIhSi8FxiuyHZJAQu8bDc/edit#gid=1220891905"
210
- lien_html = f'<a href="{lien_url}">{lien_label}</a>'
211
-
212
- st.sidebar.markdown(lien_html, unsafe_allow_html=True)
213
- app()
 
1
  import streamlit as st
2
+ import requests
 
 
 
 
 
 
3
 
4
+ # Configuration
 
5
  st.set_page_config(
6
+ page_title="Recherche",
7
+ page_icon="images/logo.png",
8
+ layout="wide",
9
+ initial_sidebar_state="auto"
10
+
11
  )
12
+ change_footer_style = """
13
  <style>
14
+ #MainMenu {visibility: hidden;}
15
  footer {visibility: hidden;}
16
  </style>
17
  """
18
+ st.markdown(change_footer_style, unsafe_allow_html=True)
19
+
20
+
21
+ def get_product_info(EAN):
22
+ url = f"https://world.openfoodfacts.org/api/v0/product/{EAN}.json"
23
+ response = requests.get(url)
24
+ if response.status_code == 200:
25
+ return response.json()
26
+ else:
27
+ return {"error": "Product not found"}
28
+
29
+ # Test de la fonction
30
+ EAN =st.text_input("EAN", '0737628064502') # remplacer par l'EAN du produit
31
+ if EAN :
32
+ product_info = get_product_info(EAN)
33
+ st.json(product_info)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.yaml DELETED
@@ -1,2 +0,0 @@
1
- runtime: python310
2
- service: default
 
 
 
pages/recherche.py DELETED
@@ -1,33 +0,0 @@
1
- import streamlit as st
2
- import requests
3
-
4
- # Configuration
5
- st.set_page_config(
6
- page_title="Recherche",
7
- page_icon="logo.png",
8
- layout="wide",
9
- initial_sidebar_state="auto"
10
-
11
- )
12
- change_footer_style = """
13
- <style>
14
- #MainMenu {visibility: hidden;}
15
- footer {visibility: hidden;}
16
- </style>
17
- """
18
- st.markdown(change_footer_style, unsafe_allow_html=True)
19
-
20
-
21
- def get_product_info(EAN):
22
- url = f"https://world.openfoodfacts.org/api/v0/product/{EAN}.json"
23
- response = requests.get(url)
24
- if response.status_code == 200:
25
- return response.json()
26
- else:
27
- return {"error": "Product not found"}
28
-
29
- # Test de la fonction
30
- EAN =st.text_input("EAN", '0737628064502') # remplacer par l'EAN du produit
31
- if EAN :
32
- product_info = get_product_info(EAN)
33
- st.json(product_info)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/{Gestion_de_rupture_famille.py → 🤖_Gestion_de_rupture_famille.py} RENAMED
File without changes
pages/🦾_Gestion_de_rupture_sous_famille.py ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import time
4
+ from App.class_input_box.input_box import *
5
+ from App.functions_rupture.functions_gestion import *
6
+ from App.utils.divers_function import *
7
+ from App.utils.filter_dataframe import *
8
+ from App.utils.filter_dataframe import *
9
+
10
+
11
+ # Page configuration
12
+ st.set_page_config(
13
+ page_title="Gestion des ruptures",
14
+ page_icon="images/Carrefour_logo.png",
15
+ layout="wide"
16
+ )
17
+ hide_streamlit_style = """
18
+ <style>
19
+ footer {visibility: hidden;}
20
+ </style>
21
+ """
22
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
23
+
24
+
25
+ def app():
26
+ st.title("Gestion des ruptures sous famille")
27
+
28
+ input_box = InputsBox()
29
+
30
+ data = input_box.get_data()
31
+
32
+ try:
33
+ if data.shape[0] != 0 :
34
+ st.header("Data")
35
+
36
+ st.dataframe(filter_dataframe(data))
37
+
38
+ "## Parameters"
39
+
40
+ col1, col2 = st.columns(2)
41
+
42
+ with col1 :
43
+ product_id = input_box.get_product_id()
44
+
45
+ with col2 :
46
+ class_id = input_box.get_class_id()
47
+
48
+ '## Filters'
49
+ col1, col2 = st.columns(2)
50
+
51
+ with col1 :
52
+ min_product_id = input_box.valid_produict_id()
53
+
54
+ with col2 :
55
+ vaind_class_id = input_box.valid_class_id()
56
+
57
+ conditions = input_box.conditions_()
58
+
59
+ if st.button("RUN ", key="run_button"):
60
+ data = valide_key(data, product_id, class_id, min_product_id, vaind_class_id )
61
+ data = data[data.COUNTRY_KEY.isin(conditions["Countries"])]
62
+ Country, merged = nouvelle_data(data,
63
+ str(product_id),
64
+ str(class_id))
65
+
66
+ merged_final = finale_merged(merged,
67
+ Country,
68
+ product_id,
69
+ class_id)
70
+
71
+
72
+ data_countries_ratio = cond_pays_proportion(merged_final,
73
+ conditions["Number of countries"],
74
+ conditions["Proportion"],
75
+ product_id)
76
+
77
+ df = supprime_country(data_countries_ratio)
78
+ csv = convert_df(df)
79
+
80
+ """## The data below is filtered as follows: """
81
+ "- Number of countries greater than or equal to ", conditions["Number of countries"]
82
+ "- The proportion with the highest ", class_id ," is greater than or equal to ",conditions["Proportion"]
83
+
84
+ DF = df[((df.Proportion >= conditions["Proportion"]) & (df.total_by_ligne >= conditions["Number of countries"]))]
85
+
86
+ finale_df = Merger(data,
87
+ DF,
88
+ product_id,
89
+ class_id)
90
+
91
+ tab1, tab2 = st.tabs(["Data without decision-making", "Data with proposed changes"])
92
+
93
+ with tab1 :
94
+ st.subheader("Data without decision-making")
95
+ df.loc[:, "Evaluation"] = True
96
+ df = st.data_editor(df)
97
+
98
+ st.download_button(label="Download data as CSV",
99
+ data=csv,
100
+ file_name='sample_df.csv',
101
+ mime='text/csv',)
102
+
103
+ with tab2 :
104
+ st.subheader("Data with proposed changes")
105
+ finale_df.loc[:, "Evaluation"] = True
106
+ finale_df = st.data_editor(finale_df)
107
+
108
+ csv_f = convert_df(finale_df)
109
+ st.download_button(label="Download data as CSV",
110
+ data=csv_f,
111
+ file_name='sample_df.csv',
112
+ mime='text/csv',)
113
+
114
+ "## Country priority "
115
+
116
+ priority_data, df_equa, df_nequa = cond_pays_priorite(merged_final, product_id)
117
+ tab1, tab2, tab3, tab4 = st.tabs(["Data without decision-making", "Equality case and mt1", "Cases of inequality", "Data with proposed changes mt2"])
118
+
119
+ with tab1 :
120
+ st.subheader("Data without decision-making")
121
+ priority_data.loc[:, "Evaluation"] = True
122
+ priority_data = st.data_editor(priority_data)
123
+
124
+ csv_f = convert_df(priority_data)
125
+ st.download_button(label="Download data as CSV",
126
+ data=csv_f,
127
+ file_name='sample_df.csv',
128
+ mime='text/csv',)
129
+
130
+ with tab2 :
131
+ st.subheader("Equality case")
132
+ df_equa.loc[:, "Evaluation"]= True
133
+ df_equa = st.data_editor(df_equa)
134
+
135
+ csv_f = convert_df(df_equa)
136
+ st.download_button(label="Download data as CSV",
137
+ data=csv_f,
138
+ file_name='sample_df.csv',
139
+ mime='text/csv',)
140
+
141
+ with tab3 :
142
+ st.subheader("Cases of inequality")
143
+ df_nequa_ = df_nequa[(df_nequa.total_by_ligne.apply(lambda x: int(x) > 2))]
144
+ df_nequa_.loc[:, "Evaluation"]= True
145
+ df_nequa_ = st.data_editor(df_nequa_)
146
+
147
+ csv_f = convert_df(df_nequa_)
148
+ st.download_button(label="Download data as CSV",
149
+ data=csv_f,
150
+ file_name='sample_df.csv',
151
+ mime='text/csv',)
152
+
153
+
154
+
155
+ max_poids_index = df_nequa_.groupby('BARCODE')['Poids'].idxmax()
156
+
157
+
158
+ df_max_poids = df_nequa_.loc[max_poids_index]
159
+ df_max_poids.drop(["COUNTRY_KEY"], axis = 1, inplace= True)
160
+ finale_df_ = Merger(data,df_max_poids, product_id, class_id)
161
+ with tab4 :
162
+ st.subheader("Cases of inequality")
163
+ finale_df_.loc[:, "Evaluation"]= True
164
+ finale_df_ = st.data_editor(finale_df_)
165
+
166
+ csv_f = convert_df(finale_df_)
167
+ st.download_button(label="Download data as CSV",
168
+ data=csv_f,
169
+ file_name='sample_df.csv',
170
+ mime='text/csv',)
171
+
172
+ st.subheader(" One vs One with similarity score")
173
+ df_nequa_1 = df_nequa[(df_nequa.total_by_ligne.apply(lambda x: int(x) == 2))]
174
+
175
+ max_poids_index1 = df_nequa_1.groupby('BARCODE')['Poids'].idxmax()
176
+
177
+ # Récupérer les lignes correspondantes
178
+ df_max_poids1 = df_nequa_1.loc[max_poids_index1]
179
+ df_max_poids1.drop(["COUNTRY_KEY"], axis = 1, inplace= True)
180
+ finale_df_1 = ajout_simularite(Merger(data,df_max_poids1, product_id, class_id))
181
+ finale_df_1.loc[:, "Evaluation"]= True
182
+ finale_df_1 = st.data_editor(finale_df_1)
183
+ csv_f = convert_df(finale_df_1)
184
+ st.download_button(label="Download data as CSV",
185
+ data=csv_f,
186
+ file_name='sample_df.csv',
187
+ mime='text/csv',)
188
+ st.success('Done!', icon="✅")
189
+ st.balloons()
190
+
191
+ except:
192
+ pass
193
+ #st.error('This is an error', icon="🚨")
194
+ 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="ℹ️")
195
+
196
+
197
+ if __name__ == "__main__":
198
+ lien_label = "# Example of input"
199
+ lien_url = "https://docs.google.com/spreadsheets/d/123hVTOFpBT-C6mCnrOBh8fFIhSi8FxiuyHZJAQu8bDc/edit#gid=1220891905"
200
+ lien_html = f'<a href="{lien_url}">{lien_label}</a>'
201
+
202
+ st.sidebar.markdown(lien_html, unsafe_allow_html=True)
203
+ app()