Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,15 +23,21 @@ def load_tab(sheet_name):
|
|
23 |
|
24 |
# GPS calculations
|
25 |
def calculate_gps_data(df):
|
26 |
-
df = df.sort_values(['Date', 'Time'])
|
27 |
df[['Latitude', 'Longitude']] = df['Location'].str.split(', ', expand=True).astype(float)
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
return df
|
36 |
|
37 |
# Load and process Field Sales data
|
|
|
23 |
|
24 |
# GPS calculations
|
25 |
def calculate_gps_data(df):
|
26 |
+
df = df.sort_values(['Date', 'Time']).reset_index(drop=True)
|
27 |
df[['Latitude', 'Longitude']] = df['Location'].str.split(', ', expand=True).astype(float)
|
28 |
+
|
29 |
+
df['Kms Travelled'] = 0.0
|
30 |
+
df['Duration Between Calls (min)'] = 0.0
|
31 |
+
|
32 |
+
for i in range(1, len(df)):
|
33 |
+
prev_coords = (df.at[i-1, 'Latitude'], df.at[i-1, 'Longitude'])
|
34 |
+
current_coords = (df.at[i, 'Latitude'], df.at[i, 'Longitude'])
|
35 |
+
df.at[i, 'Kms Travelled'] = geodesic(prev_coords, current_coords).km
|
36 |
+
|
37 |
+
prev_time = pd.to_datetime(df.at[i-1, 'Date'] + ' ' + df.at[i-1, 'Time'])
|
38 |
+
current_time = pd.to_datetime(df.at[i, 'Date'] + ' ' + df.at[i, 'Time'])
|
39 |
+
df.at[i, 'Duration Between Calls (min)'] = (current_time - prev_time).total_seconds() / 60.0
|
40 |
+
|
41 |
return df
|
42 |
|
43 |
# Load and process Field Sales data
|