From c1f58966a6c66b69091b1c4931c361779d2bea12 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Wed, 13 Dec 2023 20:44:11 -0600 Subject: [PATCH 1/6] Stub out add-party. --- constants.py | 1 + kiss_and_db.py | 31 +++++++++++++++++++++++++++++-- schema.sql | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/constants.py b/constants.py index 7ade087..c711b2f 100644 --- a/constants.py +++ b/constants.py @@ -22,6 +22,7 @@ db_frames_fields = ("id", "mtype", "object_format", "object_name", +"party", "path", "phg", "phg_dir", diff --git a/kiss_and_db.py b/kiss_and_db.py index 9d74bfa..1b1882e 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -76,8 +76,17 @@ def main(): # Make this a string and deal with it later (probably a mistake) a['path'] = str(a['path']) + # Process 3rd-party data if 'subpacket' in a: a['subpacket'] = str(a['subpacket']) + b = aprslib.parse(str(a['subpacket'])) + b['party'] = 3 + b['station_call'] = config['Settings']['station_call'] + b['station_lat'] = config['Settings']['station_lat'] + b['station_lon'] = config['Settings']['station_lon'] + b['created_unix'] = int(time.time()) + else: + a['party'] = 1 #logging.debug(a['path']) # Store true/false as 1/0 if 'alive' in a: @@ -90,12 +99,21 @@ def main(): attrib_values = ", ".join("?" * len(a.keys())) logging.debug(attrib_names) logging.debug(a.values()) - - logging.debug("Inserting into database") + if 'subpacket' in a: + # 3rd-party + b_attrib_names = ', '.join('"%s"' % w for w in b.keys()) + b_attrib_values = ", ".join("?" * len(b.keys())) + logging.debug(b_attrib_names) + logging.debug(b.values()) + try: + logging.debug("Inserting into database") # Insert data sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")" conn.execute(sql, list(a.values())) + if 'subpacket' in a: + b_sql = "INSERT INTO frames ("+b_attrib_names+") VALUES ("+b_attrib_values+")" + conn.execute(b_sql, list(b.values())) logging.debug("Frames table updated") # TODO update stations table here # Original intent was to include the id from the frames table, @@ -113,6 +131,15 @@ def main(): last_heard_unix = excluded.last_heard_unix;" # Insert/update data conn.execute(query3) + if 'subpacket' in a: + b_station_update = "'"+b['from'] +"', '"+ str(b['created_unix']) +"', '1'" + b_query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ + VALUES("+b_station_update+") \ + ON CONFLICT([from]) \ + DO UPDATE SET count = count + 1,\ + last_heard_unix = excluded.last_heard_unix;" + # Insert/update data + conn.execute(b_query3) logging.debug("Station table updated") conn.commit() #except: diff --git a/schema.sql b/schema.sql index c6fe23d..ea29c02 100644 --- a/schema.sql +++ b/schema.sql @@ -24,6 +24,7 @@ CREATE TABLE frames ( mtype TEXT, object_format TEXT, object_name TEXT, + party INT, path TEXT, phg REAL, phg_dir TEXT, -- 2.30.2 From 0592f45af831a1a392c61c7c847346b1c216ff96 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Wed, 13 Dec 2023 21:18:44 -0600 Subject: [PATCH 2/6] Assign subpacket correctly. --- kiss_and_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiss_and_db.py b/kiss_and_db.py index 1b1882e..58d004c 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -79,7 +79,7 @@ def main(): # Process 3rd-party data if 'subpacket' in a: a['subpacket'] = str(a['subpacket']) - b = aprslib.parse(str(a['subpacket'])) + b = a['subpacket'] b['party'] = 3 b['station_call'] = config['Settings']['station_call'] b['station_lat'] = config['Settings']['station_lat'] -- 2.30.2 From bfa7b91446cdff4aa9bb1fca53aa6abc5c4ee122 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Wed, 13 Dec 2023 21:25:30 -0600 Subject: [PATCH 3/6] Fix mistake. --- kiss_and_db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kiss_and_db.py b/kiss_and_db.py index 58d004c..e2d1856 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -78,8 +78,8 @@ def main(): a['path'] = str(a['path']) # Process 3rd-party data if 'subpacket' in a: - a['subpacket'] = str(a['subpacket']) - b = a['subpacket'] + b = a['subpacket'] # make a copy + a['subpacket'] = str(a['subpacket']) # turn the original to a string b['party'] = 3 b['station_call'] = config['Settings']['station_call'] b['station_lat'] = config['Settings']['station_lat'] -- 2.30.2 From 9797f29bf2c411596de8c74e79639cc98e755c4f Mon Sep 17 00:00:00 2001 From: W1CDN Date: Wed, 13 Dec 2023 22:10:00 -0600 Subject: [PATCH 4/6] Snapshot. --- kiss_and_db.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kiss_and_db.py b/kiss_and_db.py index e2d1856..ba7ac9b 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -81,6 +81,7 @@ def main(): b = a['subpacket'] # make a copy a['subpacket'] = str(a['subpacket']) # turn the original to a string b['party'] = 3 + b['header_raw'] = a['raw'].split("}", 1)[0] # just the first part b['station_call'] = config['Settings']['station_call'] b['station_lat'] = config['Settings']['station_lat'] b['station_lon'] = config['Settings']['station_lon'] -- 2.30.2 From 8f2425290c9f6e1606354087ca0286d63c52b0fa Mon Sep 17 00:00:00 2001 From: W1CDN Date: Thu, 14 Dec 2023 08:38:04 -0600 Subject: [PATCH 5/6] Subpacket path to string. --- kiss_and_db.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kiss_and_db.py b/kiss_and_db.py index ba7ac9b..395d6cb 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -81,6 +81,7 @@ def main(): b = a['subpacket'] # make a copy a['subpacket'] = str(a['subpacket']) # turn the original to a string b['party'] = 3 + b['path'] = str(b['path']) b['header_raw'] = a['raw'].split("}", 1)[0] # just the first part b['station_call'] = config['Settings']['station_call'] b['station_lat'] = config['Settings']['station_lat'] -- 2.30.2 From 31fb381063d3c6f7090ad3c7b9e44e6750fb9cbb Mon Sep 17 00:00:00 2001 From: W1CDN Date: Thu, 14 Dec 2023 08:55:15 -0600 Subject: [PATCH 6/6] Assign first party and add frames.rng field. --- constants.py | 1 + kiss_and_db.py | 3 +-- schema.sql | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/constants.py b/constants.py index c711b2f..1a0dc5c 100644 --- a/constants.py +++ b/constants.py @@ -33,6 +33,7 @@ db_frames_fields = ("id", "posambiguity", "raw", "raw_timestamp", +"rng", "speed", "station_call", "station_lat", diff --git a/kiss_and_db.py b/kiss_and_db.py index 395d6cb..3c46b37 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -73,6 +73,7 @@ def main(): a['station_lat'] = config['Settings']['station_lat'] a['station_lon'] = config['Settings']['station_lon'] a['created_unix'] = int(time.time()) + a['party'] = 1 # Make this a string and deal with it later (probably a mistake) a['path'] = str(a['path']) @@ -87,8 +88,6 @@ def main(): b['station_lat'] = config['Settings']['station_lat'] b['station_lon'] = config['Settings']['station_lon'] b['created_unix'] = int(time.time()) - else: - a['party'] = 1 #logging.debug(a['path']) # Store true/false as 1/0 if 'alive' in a: diff --git a/schema.sql b/schema.sql index ea29c02..50f5a24 100644 --- a/schema.sql +++ b/schema.sql @@ -35,6 +35,7 @@ CREATE TABLE frames ( posambiguity INT, raw TEXT, raw_timestamp TEXT, + rng REAL, speed REAL, station_call TEXT, station_lat REAL, -- 2.30.2