-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plane.py
160 lines (142 loc) · 6.33 KB
/
Plane.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import jinja2
from datetime import datetime
from Message import Message
import time
from WaypointDB import WaypointDB
class Plane:
def __init__(self, registration_no, timestamp):
self.registration_no = registration_no
self.first_seen = timestamp
self.last_seen = timestamp
self.flight_no = 'Unknown'
self.departure_airport = 'Unknown'
self.destination_airport = 'Unknown'
self.eta = 'Unknown'
self.gout = 'Unknown'
self.gin = 'Unknown'
self.won = 'Unknown'
self.woff = 'Unknown'
self.messages = {}
self.route = ''
self.has_extra = 'No'
self.lat = 'Unknown'
self.lon = 'Unknown'
self.alt = 'Unknown'
self.speed = 'Unknown'
self.heading = 'Unknown'
self.m_wind_speed = 'Unknown'
self.m_direction = 'Unknown'
self.m_temp = 'Unknown'
self.has_location = 'No'
self.has_meteo = 'No'
def addRoute(self,sentance):
self.route = sentance
def update_last_seen(self, last_seen):
if last_seen > self.last_seen:
self.last_seen = last_seen
def add_flight_no(self, flight_no):
self.flight_no = flight_no
def add_departure_airport(self, departure_airport):
self.departure_airport = departure_airport
def add_destination_airport(self, destination_airport):
self.destination_airport = destination_airport
def add_eta(self, eta):
self.eta = eta
def add_gin(self, gin):
self.has_extra = 'Yes'
self.gin = gin
def add_gout(self, gout):
self.has_extra = 'Yes'
self.gout = gout
def add_won(self, won):
self.has_extra = 'Yes'
self.won = won
def add_woff(self, woff):
self.has_extra = 'Yes'
self.woff = woff
def add_message(self, message):
self.messages[message.id] = message
def getRoute(self,message_id, waypointsDB):
if message_id in self.messages:
return self.messages[message_id].getRouteHTML(waypointsDB)
else:
return "Id was not found"
def getRouteJSON(self,message_id, waypointsDB):
if message_id in self.messages:
return self.messages[message_id].getRouteJSON(waypointsDB)
else:
return "[]"
def get_brief(self):
output = {}
output['key'] = self.registration_no
output['timestamp'] = datetime.fromtimestamp(self.last_seen).strftime("%d-%m-%y %H:%M:%S")
output['msgno'] = len(self.messages)
output['extra'] = self.has_extra
output['location'] = self.has_location
output['meteo'] = self.has_meteo
i = 0
for id in self.messages:
if self.messages[id].timestamp > time.time() - 1*60*60:
i+=1
output['msgno_1h'] = i
return output
def getLast8HTML(self):
first_dt = datetime.fromtimestamp(self.first_seen).strftime("%d-%m-%y %H:%M:%S")
last_dt = datetime.fromtimestamp(self.last_seen).strftime("%d-%m-%y %H:%M:%S")
templateLoader = jinja2.FileSystemLoader(searchpath="./templates")
templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template('planeinfo.html')
last8hmessages = []
for id in self.messages:
if self.messages[id].timestamp > time.time() - 8*60*60:
last8hmessages.append(self.messages[id])
return template.render(gin = self.gin,
gout = self.gout,
won = self.won,
woff = self.woff,
registration_no=self.registration_no,
flight_no = self.flight_no,
departure_airport = self.departure_airport,
destination_airport = self.destination_airport,
first_seen = str(first_dt),
last_seen = str(last_dt),
msg_no = str(len(self.messages)),
messages = last8hmessages,
msg_last_8 = len(last8hmessages),
lat = str(self.lat),
lon = str(self.lon),
alt = str(self.alt),
speed = str(self.speed),
hdg = str(self.heading),
m_speed = str(self.m_wind_speed),
m_dir = str(self.m_direction),
m_temp = str(self.m_temp))
def getHTML(self):
first_dt = datetime.fromtimestamp(self.first_seen).strftime("%d-%m-%y %H:%M:%S")
last_dt = datetime.fromtimestamp(self.last_seen).strftime("%d-%m-%y %H:%M:%S")
templateLoader = jinja2.FileSystemLoader(searchpath="./templates")
templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template('planeinfo_all.html')
allmessages = []
for id in self.messages:
allmessages.append(self.messages[id])
return template.render(gin = self.gin,
gout = self.gout,
won = self.won,
woff = self.woff,
registration_no=self.registration_no,
flight_no = self.flight_no,
departure_airport = self.departure_airport,
destination_airport = self.destination_airport,
first_seen = str(first_dt),
last_seen = str(last_dt),
msg_no = str(len(self.messages)),
messages = allmessages,
lat = str(self.lat),
lon = str(self.lon),
alt = str(self.alt),
speed = str(self.speed),
hdg = str(self.heading),
m_speed = str(self.m_wind_speed),
m_dir = str(self.m_direction),
m_temp = str(self.m_temp))