File size: 1,647 Bytes
1e7ca72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import streamlit as st

from queries.process_ciq_3g import generate_ciq_3g_excel

st.title("CIQ 3G Generator")

ciq_file = st.file_uploader(
    "Upload CIQ brut 3G (Excel)", type=["xlsx", "xls"], key="ciq3g_ciq"
)

col1, col2 = st.columns(2)
with col1:
    year_suffix = st.text_input("Year suffix", value="25", key="ciq3g_year")
with col2:
    bands = st.text_input(
        "Bands string",
        value="G9G18U9U21L8L18L26",
        key="ciq3g_bands",
    )

if ciq_file is None:
    st.info("Upload CIQ brut 3G Excel to generate CIQ 3G (WBTS + WCEL).")
    st.stop()

if st.button("Generate", type="primary"):
    try:
        with st.spinner("Generating CIQ 3G..."):
            sheets, excel_bytes = generate_ciq_3g_excel(
                ciq_file, year_suffix=year_suffix.strip(), bands=bands.strip()
            )
            st.session_state["ciq3g_sheets"] = sheets
            st.session_state["ciq3g_excel_bytes"] = excel_bytes
        st.success("CIQ 3G generated")
    except Exception as e:
        st.error(f"Error: {e}")

sheets = st.session_state.get("ciq3g_sheets")
excel_bytes = st.session_state.get("ciq3g_excel_bytes")

if sheets:
    tab_names = list(sheets.keys())
    tabs = st.tabs(tab_names)
    for t, name in zip(tabs, tab_names):
        with t:
            df: pd.DataFrame = sheets[name]
            st.dataframe(df, use_container_width=True)

if excel_bytes:
    st.download_button(
        label="Download CIQ 3G Excel",
        data=excel_bytes,
        file_name="CIQ_3G.xlsx",
        mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        type="primary",
    )