File size: 3,908 Bytes
7e0e68d
3c38b6d
7e0e68d
f8d3386
d264bde
ec609f8
d264bde
 
083d2f8
d34ef4e
 
 
d264bde
d34ef4e
d264bde
d34ef4e
d264bde
ec609f8
d34ef4e
 
 
2f93a62
d34ef4e
2f93a62
d34ef4e
2f93a62
 
 
 
3e55118
 
 
 
2f93a62
 
3e55118
2f93a62
3e55118
2f93a62
3c38b6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f93a62
 
50dbf21
3e55118
2f93a62
50dbf21
3e55118
2f93a62
 
 
3e55118
2f93a62
3e55118
3c38b6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd

st.set_page_config(layout="wide")
st.markdown("<h1 style='text-align: center;'>حسن xxx دحوم</h1>", unsafe_allow_html=True)

def header(text,h='h2'):
    return st.markdown(f"<{h} style='text-align: center;'>{text}</{h}>", unsafe_allow_html=True)
    
# First row with three text components
col1, col2, col3 = st.columns(3)
with col1:
    header('Premiums','h3')
with col2:
    header("Incurred Claims & Recoveries Data",'h3')
with col3:
    header("Claims Count",'h3')

# Second row with three file upload buttons
upload_col1, upload_col2, upload_col3 = st.columns(3)
with upload_col1:
    uploaded_file_premiums = st.file_uploader("", key="premiums")
with upload_col2:
    uploaded_file_claims_recoveries = st.file_uploader("", key="claims_recoveries")
with upload_col3:
    uploaded_file_claims_count = st.file_uploader("", key="claims_count")

# Third row with three buttons, enabled only if the corresponding file is uploaded
button_col1, button_col2, button_col3 = st.columns(3)
premiumlabel = "Select Premiums columns"
incurredlabel = "Select Incurred claims columns"
recoverlabel = "Select Recoveries columns"
claimscount = "Select Claims count columns"
with button_col1:
    if uploaded_file_premiums is not None:
        st.button(premiumlabel)
    else:
        st.button(premiumlabel, disabled=True)

def process_premiums_file(uploaded_file):
    # Read the CSV file into a DataFrame
    df = pd.read_csv(uploaded_file)
    
    # Store the DataFrame in the session state
    st.session_state['premiums_df'] = df

    # Indicate that the CSV has been processed and we're ready to select columns
    st.session_state['select_columns'] = True

# Button to select premiums, only enabled if a file has been uploaded
with button_col1:
    if uploaded_file_premiums is not None:
        if st.button(premiumlabel):
            process_premiums_file(uploaded_file_premiums)
    else:
        st.button(premiumlabel, disabled=True)

with button_col2:
    if uploaded_file_claims_recoveries is not None:
        st.button(incurredlabel)
        st.button(recoverlabel)
    else:
        st.button(incurredlabel, disabled=True)
        st.button(recoverlabel, disabled=True)

with button_col3:
    if uploaded_file_claims_count is not None:
        st.button(claimscount)
    else:
        st.button(claimscount, disabled=True)


# If the CSV has been processed, display the column selection UI
if st.session_state.get('select_columns', False):
    st.write("Please choose the 'lob' column and the values to filter by:")

    # Dropdown to select the 'lob' column
    lob_column = st.selectbox('Choose the column for "lob":', st.session_state['premiums_df'].columns)

    # Multiselect to choose values from the 'lob' column to filter the DataFrame
    selected_lob_values = st.multiselect('Choose values from the "lob" column:', 
                                         st.session_state['premiums_df'][lob_column].unique())

    # Filter the DataFrame based on selected 'lob' values
    if selected_lob_values:
        filtered_df = st.session_state['premiums_df'][st.session_state['premiums_df'][lob_column].isin(selected_lob_values)]
        st.session_state['filtered_premiums_df'] = filtered_df

        # Display other column selections after 'lob' has been selected and DataFrame has been filtered
        st.write("Now, select the columns for other parameters:")
        valuation_as_at = st.selectbox('Valuation As At:', filtered_df.columns)
        quarter_bracket = st.selectbox('Quarter Bracket:', filtered_df.columns)
        # Continue with other selections as required...

        # Store the column selections in the session state
        st.session_state['column_selections'] = {
            'valuation_as_at': valuation_as_at,
            'quarter_bracket': quarter_bracket,
            # ... include other selections as well
        }