File size: 4,368 Bytes
a61aa1b
 
 
 
 
983896a
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
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.")