-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreformatComments.py
101 lines (74 loc) · 2.34 KB
/
reformatComments.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import json
import os
from datetime import datetime
import datetime
def dms_to_dd(d, m, s):
if d[0]=='-':
dd = float(d) - float(m)/60 - float(s)/3600
else:
dd = float(d) + float(m)/60 + float(s)/3600
return dd
def nmeaGGA2decDeg(GGA):
if int(GGA[0]) != 0:
deg = GGA[0] + GGA[1]
min = GGA[2:]
else:
deg = GGA[0] + GGA[1] + GGA[2]
min = GGA[3:]
decimal = dms_to_dd(deg,min,0)
return(decimal)
def getLatLonComments(comment):
lat = nmeaGGA2decDeg(comment['data'][1])
lat_dir = comment['data'][2]
if lat_dir == 'S':
lat = lat * -1
lon = nmeaGGA2decDeg(comment['data'][3])
lon_dir = comment['data'][4]
if lon_dir == 'W':
lon = lon * -1
# print(lat,lon)
alt = float(comment['data'][8])
return lat, lon, alt
def extractHMS(string):
hour = int(string[:2])
minute = int(string[2:4])
second = int(string[4:6])
return hour, minute, second
year = 2023
month = 9
day = 14
# epoch = datetime.datetime(year, month, day, hour, minute, second).strftime('%s')
# print(epoch)
directory = "./newComments"
newDir = "./reformattedComments/"
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
print(f)
masterDict ={
'comments':[]
}
if os.path.isfile(f):
with open(f) as file:
old = json.load(file)
for entry in old['comments']:
current_dict = {}
event = entry['problem']
data = entry['data']
time = data[0]
h,m,s = extractHMS(time)
epoch_time = float(datetime.datetime(year,month,day,h,m,s).strftime('%s'))
current_dict['timestampSec'] = epoch_time
current_dict['event'] = event
current_dict['groupID'] = 3
lat, lon, alt = getLatLonComments(entry)
LLH = {
'latitude': lat,
'longitude': lon,
'alt_msl': alt
}
current_dict['gnssPosition'] = LLH
masterDict['comments'].append(current_dict)
# print(masterDict)
with open(newDir+filename, 'w') as fp:
print("CREATED NEW FILE: ", newDir+filename)
json.dump(masterDict, fp, indent=4)