DavMelchi commited on
Commit
f447c88
·
1 Parent(s): 123d5ff

adding physical db management

Browse files
README.md CHANGED
@@ -34,10 +34,11 @@ You can access the hosted version of the app at [https://davmelchi-db-query.hf.s
34
 
35
  ## TODO
36
 
37
- - [*] check if required sheets exist in the dump file
38
- - [*] Add a download button for all databases
39
- - [*] Add option to download Neighbors database
40
  - [ ] Add dashboards for each database (Count of NE)
41
  - [ ] Add the ability to select columns
42
  - [ ] Error handling
43
- - [ ] Add option to update physical db
 
 
34
 
35
  ## TODO
36
 
37
+ - [x] check if required sheets exist in the dump file
38
+ - [x] Add a download button for all databases
39
+ - [x] Add option to download Neighbors database
40
  - [ ] Add dashboards for each database (Count of NE)
41
  - [ ] Add the ability to select columns
42
  - [ ] Error handling
43
+ - [x] Add page to update physical db
44
+ - [x] Add Core dump checking App
app.py CHANGED
@@ -4,6 +4,7 @@ pages = {
4
  "Apps": [
5
  st.Page("apps/database_page.py", title="Generate Databases"),
6
  st.Page("apps/core_dump_page.py", title="Check dump core"),
 
7
  ],
8
  "Documentations": [
9
  st.Page("documentations/database_doc.py", title="Databases Documentation"),
 
4
  "Apps": [
5
  st.Page("apps/database_page.py", title="Generate Databases"),
6
  st.Page("apps/core_dump_page.py", title="Check dump core"),
7
+ st.Page("apps/import_physical_db.py", title="Physical Database Management"),
8
  ],
9
  "Documentations": [
10
  st.Page("documentations/database_doc.py", title="Databases Documentation"),
apps/import_physical_db.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import pandas as pd
4
+ import streamlit as st
5
+
6
+ # Define the folder path where the physical database will be stored
7
+ physical_db_folder = "physical_db"
8
+ physical_db_file = os.path.join(physical_db_folder, "physical_database.csv")
9
+
10
+ # Ensure the folder exists
11
+ if not os.path.exists(physical_db_folder):
12
+ os.makedirs(physical_db_folder)
13
+
14
+ # Streamlit app title
15
+ st.title("Physical Database Management")
16
+
17
+ # Step 1: Upload a new CSV file
18
+ uploaded_file = st.file_uploader(
19
+ "Upload a CSV file of new physical database", type="csv"
20
+ )
21
+
22
+ if uploaded_file is not None:
23
+ # Step 2: Check if the file contains the required columns
24
+ df = pd.read_csv(uploaded_file)
25
+ required_columns = [
26
+ "CODE",
27
+ "sector",
28
+ "Code_Sector",
29
+ "Azimut",
30
+ "Longitude",
31
+ "Latitude",
32
+ "Hauteur",
33
+ ]
34
+
35
+ if not all(col in df.columns for col in required_columns):
36
+ st.error(
37
+ f"Error: The file must contain the following columns: {', '.join(required_columns)}"
38
+ )
39
+ elif len(df) <= 500:
40
+ st.error("Error: The file must contain more than 500 rows.")
41
+ else:
42
+ st.success("File successfully validated.")
43
+
44
+ # Display the DataFrame
45
+ st.write(df)
46
+
47
+ # Step 6: Add button to save the new file
48
+ if st.button("Save the new physical database file", type="primary"):
49
+ # Step 4: Remove everything in the folder physical_db/
50
+ for file in os.listdir(physical_db_folder):
51
+ os.remove(os.path.join(physical_db_folder, file))
52
+
53
+ # Step 5: Rename and save the new file
54
+ df.to_csv(physical_db_file, index=False)
55
+ st.success(f"New physical database saved Successfully.")
56
+
57
+
58
+ # # Step 7: Add button to download the existing physical_database.csv file
59
+ # if os.path.exists(physical_db_file):
60
+ # st.subheader("Download the existing physical_database.csv file")
61
+ # with open(physical_db_file, "rb") as f:
62
+ # st.download_button(
63
+ # label="Download physical_database.csv",
64
+ # data=f,
65
+ # file_name="physical_database.csv",
66
+ # )
67
+
68
+ # Step 8: Add button to show the existing physical_database.csv file
69
+ if os.path.exists(physical_db_file):
70
+ st.subheader("Show the existing physical_database file")
71
+ if st.button("Show actual physical database"):
72
+ df_existing = pd.read_csv(physical_db_file)
73
+ st.dataframe(df_existing)
74
+ else:
75
+ st.warning("No physical_database.csv file found in the physical_db/ folder.")
physical_db/physical_database.csv CHANGED
The diff for this file is too large to render. See raw diff