|
import os |
|
|
|
import pandas as pd |
|
import streamlit as st |
|
|
|
|
|
physical_db_folder = "physical_db" |
|
physical_db_file = os.path.join(physical_db_folder, "physical_database.csv") |
|
|
|
|
|
if not os.path.exists(physical_db_folder): |
|
os.makedirs(physical_db_folder) |
|
|
|
|
|
st.title("Physical Database Management") |
|
|
|
|
|
uploaded_file = st.file_uploader( |
|
"Upload a CSV file of new physical database", type="csv" |
|
) |
|
|
|
if uploaded_file is not None: |
|
|
|
df = pd.read_csv(uploaded_file) |
|
required_columns = [ |
|
"CODE", |
|
"sector", |
|
"Code_Sector", |
|
"Azimut", |
|
"Longitude", |
|
"Latitude", |
|
"Hauteur", |
|
] |
|
|
|
if not all(col in df.columns for col in required_columns): |
|
st.error( |
|
f"Error: The file must contain the following columns: {', '.join(required_columns)}" |
|
) |
|
elif len(df) <= 500: |
|
st.error("Error: The file must contain more than 500 rows.") |
|
else: |
|
st.success( |
|
"File successfully validated. Click on the Save button to save the new physical database file." |
|
) |
|
|
|
|
|
st.write(df) |
|
|
|
|
|
if st.button("Save the new physical database file", type="primary"): |
|
|
|
for file in os.listdir(physical_db_folder): |
|
os.remove(os.path.join(physical_db_folder, file)) |
|
|
|
|
|
df.to_csv(physical_db_file, index=False) |
|
st.success(f"New physical database saved Successfully.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists(physical_db_file): |
|
st.subheader("Show the existing physical_database file") |
|
if st.button("Show actual physical database"): |
|
df_existing = pd.read_csv(physical_db_file) |
|
st.dataframe(df_existing) |
|
else: |
|
st.warning("No physical_database.csv file found in the physical_db/ folder.") |
|
|