fixed many issues to make it even run, now it parses and stores the data into dict succesfully, genMap doesnt work

This commit is contained in:
2022-07-05 22:13:52 +02:00
parent 06ceda9e8f
commit bd4c05cfb0

11
main.py
View File

@@ -16,6 +16,9 @@ import pytz
SOCK_BUFF_SIZE = 100000
global dictionary
dictionary = {}
STA = namedtuple('STA', ['time', 'lat', 'lon', 'velocity', 'heading', 'nav',
'nsat', 'alt', 'age', 'active', 'pwr', 'csq'])
@@ -58,6 +61,8 @@ def convert_STA(sta_txt):
alt, age, active, pwr, csq)
def generateMap():
print(f"generateMap func initialized")
#Gather all needed data
for key in dictionary.keys():
# Get the actual OBUID
@@ -71,6 +76,7 @@ def generateMap():
payload = dictionary[key]['payload']
datasta = convert_STA(payload)
# Parse unittime
timefromsta = datasta[0]
timefromsta = datetime.fromtimestamp(timefromsta, tz)
@@ -103,7 +109,7 @@ def generateMap():
f.write("lat|lng|Name|SN|Unit time|STA received|Lat|Lon|Country|Velocity|Heading|Nav|Nsat|Age|Active|Pwr|Csq|sta\n")
for key in dictionary.keys():
if lat and lon is not None:
wr = f"{lat}|{lon}|{key}|{obuid}|{timefromsta}|{rtime}|{lat}|{lon}|{country}|{velocity}|{heading}|{nav}|{nsat}|{age}|{active}|{pwr}|{csq}|{sta}\n
wr = f"{lat}|{lon}|{key}|{obuid}|{timefromsta}|{rtime}|{lat}|{lon}|{country}|{velocity}|{heading}|{nav}|{nsat}|{age}|{active}|{pwr}|{csq}|{sta}\n"
# TODO: needs rewrite to trigger this function on request
time.sleep(200)
@@ -157,6 +163,7 @@ def main():
thread_generateMap.start()
while True:
print(f"Waiting for data")
pack_compress, addr = sock.recvfrom(SOCK_BUFF_SIZE)
pack = zlib.decompress(pack_compress)
@@ -171,7 +178,7 @@ def main():
tz = pytz.timezone("Europe/Prague")
rtime = datetime.now(tz)
rdatetime = datetime.now(tz)
rtime = rdatetime.strftime("%Y-%m-%d %H:%M:%S")
if obuid not in dictionary: