-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
36 lines (28 loc) · 1.24 KB
/
parse.py
File metadata and controls
36 lines (28 loc) · 1.24 KB
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
import sys
import re
from geopy.distance import geodesic
import plotly.express as px
def parse_and_calculate_distance():
# Define the reference point (latitude, longitude)
reference_point = (40.7128, -74.0060)
results = []
# Read lines from stdin
for line in sys.stdin:
# Regex pattern to find tuples and lat-lon values
pattern = r"\((\d+,\s?\d+)\),\s\((\d+,\s?\d+)\):\s([+-]?[0-9]+\.?[0-9]*\s[+-]?[0-9]+\.?[0-9]*)"
# Find all matches
matches = re.findall(pattern, line)
# Process matches to get the desired format and calculate distances
for match in matches:
h1, h2, lat_lon = match
lat_lon = tuple(map(float, lat_lon.split()))
distance = geodesic(lat_lon, reference_point).meters
# Print results
# print(f"({h1}), ({h2}): {distance}")
results.append(distance)
return results
# Call the function to parse and calculate distance
# Note: This will wait for input from stdin, so it should be tested in an appropriate environment
distances = parse_and_calculate_distance()
fig = px.histogram(distances, nbins=30, labels={'value':'Distance (meters)'}, title='Distribution of Calculated Distances')
fig.show()