adding distance calculator
Browse files- app.py +1 -0
- apps/distance.py +76 -0
- apps/gps_converter.py +0 -4
- requirements.txt +0 -0
app.py
CHANGED
@@ -17,6 +17,7 @@ pages = {
|
|
17 |
st.Page("apps/core_dump_page.py", title="Parse dump core"),
|
18 |
st.Page("apps/import_physical_db.py", title="Physical Database Management"),
|
19 |
st.Page("apps/gps_converter.py", title="GPS Converter"),
|
|
|
20 |
],
|
21 |
"Documentations": [
|
22 |
st.Page("documentations/database_doc.py", title="Databases Documentation"),
|
|
|
17 |
st.Page("apps/core_dump_page.py", title="Parse dump core"),
|
18 |
st.Page("apps/import_physical_db.py", title="Physical Database Management"),
|
19 |
st.Page("apps/gps_converter.py", title="GPS Converter"),
|
20 |
+
st.Page("apps/distance.py", title="Distance Calculator"),
|
21 |
],
|
22 |
"Documentations": [
|
23 |
st.Page("documentations/database_doc.py", title="Databases Documentation"),
|
apps/distance.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
from geopy.distance import geodesic
|
4 |
+
from st_aggrid import AgGrid
|
5 |
+
|
6 |
+
|
7 |
+
class DataFrames:
|
8 |
+
Dframe = pd.DataFrame()
|
9 |
+
|
10 |
+
|
11 |
+
st.title("Distance Calculator")
|
12 |
+
|
13 |
+
st.write(
|
14 |
+
"""This app allows you to calculate the distance between two points in a dataframe.
|
15 |
+
Please choose a file containing the latitude and longitude columns for the 2 points.
|
16 |
+
"""
|
17 |
+
)
|
18 |
+
|
19 |
+
uploaded_file = st.file_uploader(
|
20 |
+
"Upload Excel file",
|
21 |
+
type=["xlsx"],
|
22 |
+
accept_multiple_files=False,
|
23 |
+
help="Upload the Excel file containing the latitude and longitude columns for the 2 points",
|
24 |
+
)
|
25 |
+
|
26 |
+
if uploaded_file:
|
27 |
+
DataFrames.Dframe = pd.read_excel(uploaded_file, keep_default_na=False)
|
28 |
+
|
29 |
+
col1_list = DataFrames.Dframe.columns.tolist()
|
30 |
+
latitude1_dd = st.selectbox(
|
31 |
+
"Choose Latitude of point 1", col1_list, key="latitude1"
|
32 |
+
)
|
33 |
+
longitude1_dd = st.selectbox(
|
34 |
+
"Choose Longitude of point 1", col1_list, key="longitude1"
|
35 |
+
)
|
36 |
+
latitude2_dd = st.selectbox(
|
37 |
+
"Choose Latitude of point 2", col1_list, key="latitude2"
|
38 |
+
)
|
39 |
+
longitude2_dd = st.selectbox(
|
40 |
+
"Choose Longitude of point 2", col1_list, key="longitude2"
|
41 |
+
)
|
42 |
+
|
43 |
+
def calculate_distance(row):
|
44 |
+
coord1 = (row[latitude1_dd], row[longitude1_dd])
|
45 |
+
coord2 = (row[latitude2_dd], row[longitude2_dd])
|
46 |
+
return geodesic(coord1, coord2).kilometers
|
47 |
+
|
48 |
+
if st.button("CALCULATE DISTANCE", type="primary"):
|
49 |
+
try:
|
50 |
+
df = DataFrames.Dframe.copy()
|
51 |
+
df["distance"] = df.apply(calculate_distance, axis=1)
|
52 |
+
st.success("The distances are calculated successfully")
|
53 |
+
DataFrames.Dframe = df
|
54 |
+
|
55 |
+
@st.fragment
|
56 |
+
def table_data():
|
57 |
+
if DataFrames.Dframe is not None:
|
58 |
+
AgGrid(
|
59 |
+
DataFrames.Dframe,
|
60 |
+
fit_columns_on_grid_load=True,
|
61 |
+
theme="streamlit",
|
62 |
+
enable_enterprise_modules=True,
|
63 |
+
filter=True,
|
64 |
+
)
|
65 |
+
|
66 |
+
table_data()
|
67 |
+
|
68 |
+
except Exception as e:
|
69 |
+
st.error(
|
70 |
+
f"An error occurred. Make sure the file contains the latitudes and longitudes columns. Error: {e}"
|
71 |
+
)
|
72 |
+
|
73 |
+
else:
|
74 |
+
st.info(
|
75 |
+
"Please choose a file containing the latitude and longitude columns for the 2 points"
|
76 |
+
)
|
apps/gps_converter.py
CHANGED
@@ -8,7 +8,6 @@ class DataFrames:
|
|
8 |
Dframe = pd.DataFrame()
|
9 |
|
10 |
|
11 |
-
# def gps_converter_page():
|
12 |
st.title("GPS Coordinate Converter")
|
13 |
st.write(
|
14 |
"""This program allows you to convert coordinates from degree-minute-second (13°15'6.20"N) to decimal (13.2517222222222) and vice versa.
|
@@ -86,6 +85,3 @@ if uploaded_file is not None:
|
|
86 |
)
|
87 |
else:
|
88 |
st.info("Please choose a file containing the latitude and longitude columns")
|
89 |
-
|
90 |
-
|
91 |
-
# gps_converter_page()
|
|
|
8 |
Dframe = pd.DataFrame()
|
9 |
|
10 |
|
|
|
11 |
st.title("GPS Coordinate Converter")
|
12 |
st.write(
|
13 |
"""This program allows you to convert coordinates from degree-minute-second (13°15'6.20"N) to decimal (13.2517222222222) and vice versa.
|
|
|
85 |
)
|
86 |
else:
|
87 |
st.info("Please choose a file containing the latitude and longitude columns")
|
|
|
|
|
|
requirements.txt
CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
|
|