kopia lustrzana https://github.com/jprochazka/adsb-receiver
Updates for new SQL struture.
rodzic
16ef24f863
commit
c31b8020b5
|
|
@ -55,11 +55,4 @@ hard work and dedication this project would not have been possible.
|
|||
* Flightradar24 Client: https://www.flightradar24.com
|
||||
* Dump1090-Tools: https://github.com/mutability/dump1090-tools
|
||||
* Beast-Splitter https://github.com/flightaware/beast-splitter
|
||||
* bootpag http://botmonster.com/jquery-bootpag
|
||||
* Bootstrap: http://getbootstrap.com/
|
||||
* jQuery: http://jquery.com/
|
||||
* jQuery Steps: http://www.jquery-steps.com
|
||||
* js-cookie: https://github.com/js-cookie/js-cookie/releases
|
||||
* jquery-validation: https://github.com/jzaefferer/jquery-validation
|
||||
* Google Charts: https://developers.google.com/chart
|
||||
* Duck DNS http://www.duckdns.com
|
||||
|
|
|
|||
|
|
@ -1,33 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
#================================================================================#
|
||||
# ADS-B FEEDER PORTAL #
|
||||
# ------------------------------------------------------------------------------ #
|
||||
# Copyright and Licensing Information: #
|
||||
# #
|
||||
# The MIT License (MIT) #
|
||||
# #
|
||||
# Copyright (c) 2015-2024 Joseph A. Prochazka #
|
||||
# #
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy #
|
||||
# of this software and associated documentation files (the "Software"), to deal #
|
||||
# in the Software without restriction, including without limitation the rights #
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
|
||||
# copies of the Software, and to permit persons to whom the Software is #
|
||||
# furnished to do so, subject to the following conditions: #
|
||||
# #
|
||||
# The above copyright notice and this permission notice shall be included in all #
|
||||
# copies or substantial portions of the Software. #
|
||||
# #
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
|
||||
# SOFTWARE. #
|
||||
#================================================================================#
|
||||
|
||||
# WHAT THIS DOES:
|
||||
# ---------------------------------------------------------------
|
||||
#
|
||||
|
|
@ -81,17 +53,17 @@ class FlightsProcessor(object):
|
|||
return
|
||||
mapping = { "s": formatSymbol }
|
||||
self.STMTS = {
|
||||
'select_aircraft_count':"SELECT COUNT(*) FROM adsb_aircraft WHERE icao = %(s)s" % mapping,
|
||||
'select_aircraft_id': "SELECT id FROM adsb_aircraft WHERE icao = %(s)s" % mapping,
|
||||
'select_flight_count': "SELECT COUNT(*) FROM adsb_flights WHERE flight = %(s)s" % mapping,
|
||||
'select_flight_id': "SELECT id FROM adsb_flights WHERE flight = %(s)s" % mapping,
|
||||
'select_position': "SELECT message FROM adsb_positions WHERE flight = %(s)s AND message = %(s)s ORDER BY time DESC LIMIT 1" % mapping,
|
||||
'insert_aircraft': "INSERT INTO adsb_aircraft (icao, firstSeen, lastSeen) VALUES (%(s)s, %(s)s, %(s)s)" % mapping,
|
||||
'insert_flight': "INSERT INTO adsb_flights (aircraft, flight, firstSeen, lastSeen) VALUES (%(s)s, %(s)s, %(s)s, %(s)s)" % mapping,
|
||||
'insert_position_sqwk': "INSERT INTO adsb_positions (flight, time, message, squawk, latitude, longitude, track, altitude, verticleRate, speed, aircraft) VALUES (%(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s)" % mapping,
|
||||
'insert_position': "INSERT INTO adsb_positions (flight, time, message, latitude, longitude, track, altitude, verticleRate, speed, aircraft) VALUES (%(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s)" % mapping,
|
||||
'update_aircraft_seen': "UPDATE adsb_aircraft SET lastSeen = %(s)s WHERE icao = %(s)s" % mapping,
|
||||
'update_flight_seen': "UPDATE adsb_flights SET aircraft = %(s)s, lastSeen = %(s)s WHERE flight = %(s)s" % mapping
|
||||
'select_aircraft_count':"SELECT COUNT(*) FROM aircraft WHERE icao = %(s)s" % mapping,
|
||||
'select_aircraft_id': "SELECT id FROM aircraft WHERE icao = %(s)s" % mapping,
|
||||
'select_flight_count': "SELECT COUNT(*) FROM flights WHERE flight = %(s)s" % mapping,
|
||||
'select_flight_id': "SELECT id FROM flights WHERE flight = %(s)s" % mapping,
|
||||
'select_position': "SELECT message FROM positions WHERE flight = %(s)s AND message = %(s)s ORDER BY time DESC LIMIT 1" % mapping,
|
||||
'insert_aircraft': "INSERT INTO aircraft (icao, first_seen, last_seen) VALUES (%(s)s, %(s)s, %(s)s)" % mapping,
|
||||
'insert_flight': "INSERT INTO flights (aircraft, flight, first_seen, last_seen) VALUES (%(s)s, %(s)s, %(s)s, %(s)s)" % mapping,
|
||||
'insert_position_sqwk': "INSERT INTO positions (flight, time, message, squawk, latitude, longitude, track, altitude, verticleRate, speed, aircraft) VALUES (%(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s)" % mapping,
|
||||
'insert_position': "INSERT INTO positions (flight, time, message, latitude, longitude, track, altitude, verticleRate, speed, aircraft) VALUES (%(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s)" % mapping,
|
||||
'update_aircraft_seen': "UPDATE aircraft SET last_seen = %(s)s WHERE icao = %(s)s" % mapping,
|
||||
'update_flight_seen': "UPDATE flights SET aircraft = %(s)s, last_seen = %(s)s WHERE flight = %(s)s" % mapping
|
||||
}
|
||||
|
||||
def connectDB(self):
|
||||
|
|
@ -201,7 +173,7 @@ if __name__ == "__main__":
|
|||
# Main run loop
|
||||
while True:
|
||||
# Read dump1090 aircraft.json.
|
||||
response = urlopen('http://localhost/dump1090/data/aircraft.json')
|
||||
response = urlopen('http://127.0.0.1/dump1090/data/aircraft.json')
|
||||
data = json.load(response)
|
||||
|
||||
processor.processAircraftList(data["aircraft"])
|
||||
|
|
|
|||
|
|
@ -1,33 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
#================================================================================#
|
||||
# ADS-B FEEDER PORTAL #
|
||||
# ------------------------------------------------------------------------------ #
|
||||
# Copyright and Licensing Information: #
|
||||
# #
|
||||
# The MIT License (MIT) #
|
||||
# #
|
||||
# Copyright (c) 2015-2016 Joseph A. Prochazka #
|
||||
# #
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy #
|
||||
# of this software and associated documentation files (the "Software"), to deal #
|
||||
# in the Software without restriction, including without limitation the rights #
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
|
||||
# copies of the Software, and to permit persons to whom the Software is #
|
||||
# furnished to do so, subject to the following conditions: #
|
||||
# #
|
||||
# The above copyright notice and this permission notice shall be included in all #
|
||||
# copies or substantial portions of the Software. #
|
||||
# #
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
|
||||
# SOFTWARE. #
|
||||
#================================================================================#
|
||||
|
||||
import datetime
|
||||
import fcntl
|
||||
import json
|
||||
|
|
@ -66,28 +38,28 @@ while True:
|
|||
|
||||
purge_aircraft = False
|
||||
# MySQL and SQLite
|
||||
cursor.execute("SELECT value FROM adsb_settings WHERE name = 'purgeAircraft'")
|
||||
cursor.execute("SELECT value FROM settings WHERE name = 'purgeAircraft'")
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
purge_aircraft = row
|
||||
|
||||
purge_flights = False
|
||||
# MySQL and SQLite
|
||||
cursor.execute("SELECT value FROM adsb_settings WHERE name = 'purgeFlights'")
|
||||
cursor.execute("SELECT value FROM settings WHERE name = 'purgeFlights'")
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
purge_flights = row
|
||||
|
||||
purge_positions = False
|
||||
# MySQL and SQLite
|
||||
cursor.execute("SELECT value FROM adsb_settings WHERE name = 'purgePositions'")
|
||||
cursor.execute("SELECT value FROM settings WHERE name = 'purgePositions'")
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
purge_positions = row
|
||||
|
||||
purge_days_old = False
|
||||
# MySQL and SQLite
|
||||
cursor.execute("SELECT value FROM adsb_settings WHERE name = 'purgeDaysOld'")
|
||||
cursor.execute("SELECT value FROM settings WHERE name = 'purgeDaysOld'")
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
purge_days_old = row
|
||||
|
|
@ -106,56 +78,56 @@ while True:
|
|||
if purge_aircraft and purge_date:
|
||||
# MySQL
|
||||
if config["database"]["type"] == "mysql":
|
||||
cursor.execute("SELECT id FROM adsb_aircraft WHERE lastSeen < %s", purge_date)
|
||||
cursor.execute("SELECT id FROM aircraft WHERE last_seen < %s", purge_date)
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
cursor.execute("DELETE FROM adsb_positions WHERE aircraft = %s", row[0])
|
||||
cursor.execute("DELETE FROM adsb_flights WHERE aircraft = %s", row[0])
|
||||
cursor.execute("DELETE FROM adsb_aircraft WHERE id = %s", row[0])
|
||||
cursor.execute("DELETE FROM positions WHERE aircraft = %s", row[0])
|
||||
cursor.execute("DELETE FROM flights WHERE aircraft = %s", row[0])
|
||||
cursor.execute("DELETE FROM aircraft WHERE id = %s", row[0])
|
||||
|
||||
# SQLite
|
||||
if config["database"]["type"] == "sqlite":
|
||||
params = (purge_date,)
|
||||
cursor.execute("SELECT id FROM adsb_aircraft WHERE lastSeen < ?", params)
|
||||
cursor.execute("SELECT id FROM aircraft WHERE last_seen < ?", params)
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
params = (row[0],)
|
||||
cursor.execute("DELETE FROM adsb_positions WHERE aircraft = ?", params)
|
||||
cursor.execute("DELETE FROM adsb_flights WHERE aircraft = ?", params)
|
||||
cursor.execute("DELETE FROM adsb_aircraft WHERE id = ?", params)
|
||||
cursor.execute("DELETE FROM positions WHERE aircraft = ?", params)
|
||||
cursor.execute("DELETE FROM flights WHERE aircraft = ?", params)
|
||||
cursor.execute("DELETE FROM aircraft WHERE id = ?", params)
|
||||
|
||||
## Remove flights not seen since the specified date.
|
||||
|
||||
if purge_flights and purge_date:
|
||||
# MySQL
|
||||
if config["database"]["type"] == "mysql":
|
||||
cursor.execute("SELECT id FROM adsb_flights WHERE lastSeen < %s", purge_date)
|
||||
cursor.execute("SELECT id FROM flights WHERE last_seen < %s", purge_date)
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
cursor.execute("DELETE FROM adsb_positions WHERE flight = %s", row[0])
|
||||
cursor.execute("DELETE FROM adsb_flights WHERE id = %s", row[0])
|
||||
cursor.execute("DELETE FROM positions WHERE flight = %s", row[0])
|
||||
cursor.execute("DELETE FROM flights WHERE id = %s", row[0])
|
||||
|
||||
#SQLite
|
||||
if config["database"]["type"] == "sqlite":
|
||||
params = (purge_date,)
|
||||
cursor.execute("SELECT id FROM adsb_flights WHERE lastSeen < ?", params)
|
||||
cursor.execute("SELECT id FROM flights WHERE last_seen < ?", params)
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
params = (row[0],)
|
||||
cursor.execute("DELETE FROM adsb_positions WHERE flight = ?", params)
|
||||
cursor.execute("DELETE FROM adsb_flights WHERE id = ?", params)
|
||||
cursor.execute("DELETE FROM positions WHERE flight = ?", params)
|
||||
cursor.execute("DELETE FROM flights WHERE id = ?", params)
|
||||
|
||||
## Remove positions older than the specified date.
|
||||
|
||||
if purge_positions and purge_date:
|
||||
# MySQL
|
||||
if config["database"]["type"] == "mysql":
|
||||
cursor.execute("DELETE FROM adsb_positions WHERE time < %s", purge_date)
|
||||
cursor.execute("DELETE FROM positions WHERE time < %s", purge_date)
|
||||
|
||||
#SQLite
|
||||
if config["database"]["type"] == "sqlite":
|
||||
params = (purge_date,)
|
||||
cursor.execute("DELETE FROM adsb_positions WHERE time < ?", params)
|
||||
cursor.execute("DELETE FROM positions WHERE time < ?", params)
|
||||
|
||||
## Close the database connection.
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
-- VARIABLES
|
||||
|
||||
-- Specify the database name
|
||||
SET @database = "adsb_portal";
|
||||
|
||||
-- At this time table prefixes are not used so they will be removed
|
||||
-- Set the following variable to the current table prefix
|
||||
SET @current_prefix = "adsb_";
|
||||
|
||||
|
||||
-- REMOVE TABLE PREFIX
|
||||
|
||||
SET @s:='';
|
||||
SELECT
|
||||
@s:=concat("RENAME TABLE ", TABLE_NAME, " TO ", replace(TABLE_NAME, @old_prefix, ""), ';')
|
||||
FROM information_schema.TABLES WHERE TABLE_SCHEMA = @database
|
||||
;
|
||||
PREPARE stmt FROM @s;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- REMOVE INDEXES
|
||||
|
||||
ALTER TABLE `aircraft` DROP INDEX `idxIcao`;
|
||||
ALTER TABLE `positions` DROP INDEX `idxFlight`;
|
||||
|
||||
-- RENAME TABLES
|
||||
|
||||
RENAME TABLE `administrators` TO `users`;
|
||||
RENAME TABLE `flightNotifications ` TO `notifications`;
|
||||
RENAME TABLE `blogPosts` TO `blog_posts`;
|
||||
|
||||
-- RENAME COLUMNS
|
||||
|
||||
ALTER TABLE `aircraft` RENAME COLUMN `firstSeen` TO `first_seen`;
|
||||
ALTER TABLE `aircraft` RENAME COLUMN `lastSeen` TO `last_seen`;
|
||||
ALTER TABLE `flights` RENAME COLUMN `firstSeen` TO `first_seen`;
|
||||
ALTER TABLE `flights` RENAME COLUMN `lastSeen` TO `last_seen`;
|
||||
ALTER TABLE `positions` RENAME COLUMN `verticleRate` TO `verticle_rate`;
|
||||
|
||||
-- DROP COLUMNS
|
||||
|
||||
ALTER TABLE `users` DROP COLUMN `token`,
|
||||
|
||||
-- ADD COLUMNS
|
||||
|
||||
ALTER TABLE `users` ADD COLUMN `administrator` bit DEFAULT 0;
|
||||
UPDATE `users` SET `administrator` = 1;
|
||||
ALTER TABLE `users` ADD COLUMN `administrator` bit NOT NULL DEFAULT 0;
|
||||
|
||||
-- ADD FOREIGN KEYS
|
||||
|
||||
ALTER TABLE `flights` ADD FOREIGN KEY (`aircraft`) REFERENCES `aircraft`(`id`);
|
||||
ALTER TABLE `positions` ADD FOREIGN KEY (`aircraft`) REFERENCES `aircraft`(`id`);
|
||||
ALTER TABLE `positions` ADD FOREIGN KEY (`flight`) REFERENCES `flights`(`id`);
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
-- Specify the database name
|
||||
SET @database = "";
|
||||
|
||||
-- Later the ability to specify a table prefix will be added once more
|
||||
-- Specify the prefix you wish to assign current ADS-B Portal tables
|
||||
SET @prefix = "";
|
||||
|
||||
|
||||
-- ADD PREFIXES TO ADS-B PORTAL TABLES
|
||||
|
||||
SET @s:='';
|
||||
concat(
|
||||
"RENAME TABLE administrators TO ", @new_prefix, TABLE_NAME, ';'
|
||||
"RENAME TABLE aircraft TO ", @new_prefix, TABLE_NAME, ';'
|
||||
"RENAME TABLE blog_posts TO ", @new_prefix, TABLE_NAME, ';'
|
||||
"RENAME TABLE flights TO ", @new_prefix, TABLE_NAME, ';'
|
||||
"RENAME TABLE links TO ", @new_prefix, TABLE_NAME, ';'
|
||||
"RENAME TABLE notifications TO ", @new_prefix, TABLE_NAME, ';'
|
||||
"RENAME TABLE positions TO ", @new_prefix, TABLE_NAME, ';'
|
||||
"RENAME TABLE settings TO ", @new_prefix, TABLE_NAME, ';'
|
||||
)
|
||||
PREPARE stmt FROM @s;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
END;
|
||||
Ładowanie…
Reference in New Issue