Skip to content

Commit

Permalink
Improved statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfrax committed Jun 17, 2017
1 parent 943f4b7 commit e647b0c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
47 changes: 46 additions & 1 deletion basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,12 @@ class Stats:
'df_29': 0,
'df_30': 0,
'df_31': 0,
'df_total': 0
'df_total': 0,
'no_unique_icao': 0,
'flights': 0
}
icao_list = []
flight_list = {}

def __init__(self):
self['spots_version'] = ADSB.VERSION
Expand All @@ -638,22 +642,63 @@ def __setitem__(self, key, value):
def __getitem__(self, item):
return self.data[item]

def add_icao(self, icao_address):
if icao_address not in self.icao_list:
self.icao_list.append(icao_address)
self['no_unique_icao'] = len(self.icao_list)

def add_flight(self, call_sign):
if call_sign in self.flight_list:
self.flight_list[call_sign] += 1
else:
self.flight_list[call_sign] = 0
self['flights'] = len(self.flight_list)

def __str__(self):
st = "\n"
st += "Preambles:{}\n".format(self['valid_preambles'])
st += "Valid CRC:{}\n".format(self['valid_crc'])
st += "Non valid CRC:{}\n".format(self['not_valid_crc'])
st += "Decoded messages: "
st += "\n"
st += "DF0: {} ".format(self['df_0'])
st += "DF1: {} ".format(self['df_1'])
st += "DF2: {} ".format(self['df_2'])
st += "DF3: {} ".format(self['df_3'])
st += "DF4: {} ".format(self['df_4'])
st += "DF5: {} ".format(self['df_5'])
st += "DF6: {} ".format(self['df_6'])
st += "DF7: {} ".format(self['df_7'])
st += "DF8: {} ".format(self['df_8'])
st += "DF9: {} ".format(self['df_9'])
st += "DF10: {} ".format(self['df_10'])
st += "DF11: {} ".format(self['df_11'])
st += "DF12: {} ".format(self['df_12'])
st += "DF13: {} ".format(self['df_13'])
st += "DF14: {} ".format(self['df_14'])
st += "DF15: {} ".format(self['df_15'])
st += "DF16: {} ".format(self['df_16'])
st += "DF17: {} ".format(self['df_17'])
st += "DF18: {} ".format(self['df_18'])
st += "DF18: {} ".format(self['df_19'])
st += "DF20: {} ".format(self['df_20'])
st += "DF21: {} ".format(self['df_21'])
st += "DF22: {} ".format(self['df_22'])
st += "DF23: {} ".format(self['df_23'])
st += "DF24: {} ".format(self['df_24'])
st += "DF25: {} ".format(self['df_25'])
st += "DF26: {} ".format(self['df_26'])
st += "DF27: {} ".format(self['df_27'])
st += "DF28: {} ".format(self['df_28'])
st += "DF29: {} ".format(self['df_29'])
st += "DF30: {} ".format(self['df_30'])
st += "DF31: {} ".format(self['df_31'])
st += "\n"
st += "DF Total: {} ".format(self['df_total'])
st += "\n"
st += "No of unique icao: {} ".format(self['no_unique_icao'])
st += "\n"
st += "No of flights: {}".format(self['flights'])

return st

Expand Down
9 changes: 8 additions & 1 deletion spots.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ <h4 id="hdStatistics"></h4>
<div class="col-sm-2">
<div id="graphPreamble" style="width:150px"></div>
</div>
<div id="footer">Mats Melander (c)</div>
<div class="col_sm-12" id="summary"></div>
<div class="col_sm-12" id="footer">Mats Melander (c)</div>

<script type="text/javascript">
function Spots() {
Expand Down Expand Up @@ -162,6 +163,12 @@ <h4 id="hdStatistics"></h4>
stats.push({y: series['df_31'], color: '#FF0000' }); //

Plot.statistics(stats);

var i = document.getElementById('summary');
var html = 'Total messages: ' + series['df_total'] + ' ';
html += 'Unique ICAO: ' + series['no_unique_icao'] + ' ';
html += 'No of flights: ' + series['flights'] + '<br>';
i.innerHTML = html;
}

function SignalCache(series) {
Expand Down
7 changes: 6 additions & 1 deletion squitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _get_msg_byte(self, byte_nr):
return (self.msg >> (self.no_of_bits - (byte_nr + 1) * 8)) & 0xFF

def decodeCPR_relative(self):
# Basic algorithms
# Basic algorithm
# https://adsb-decode-guide.readthedocs.io/en/latest/content/airborne-position.html

if self.odd_time == 0 and self.even_time == 0:
Expand Down Expand Up @@ -473,6 +473,7 @@ def decode_ADSB_msg(self):

if self.TC_ID_CAT_D_1 <= self.type_code <= self.TC_ID_CAT_A_4:
self['call_sign'] = callsign(hex(self.msg)[2:-1])
basic.statistics.add_flight(self['call_sign'])

if self.type_code == self.TC_AIRBORNE_VELOCITY_19:
if 1 <= sub_type <= 4:
Expand Down Expand Up @@ -567,6 +568,7 @@ def decode_extended_squitter_msg(self):
def decode_comm_bds_reply_msg(self):
if self._get_msg_byte(4) == 0x20:
self['call_sign'] = callsign(hex(self.msg)[2:-1])
basic.statistics.add_flight(self['call_sign'])

def decode_altitude_msg(self):
ac_13 = ((self._get_msg_byte(2) << 8) | self._get_msg_byte(3)) & 0x1FFF
Expand Down Expand Up @@ -660,10 +662,13 @@ def decode(self):
self['ICAO24'] = hex(((self._get_msg_byte(1) << 16)
| (self._get_msg_byte(2) << 8)
| self._get_msg_byte(3)))[2:].rstrip('L')
basic.statistics.add_icao(self['ICAO24'])

self.capability = self._get_msg_byte(0) & 0x07
self.type_code = self._get_msg_byte(4) >> 3
self.emitter_category = self._get_msg_byte(4) & 0x07
self.parity = self.msg & 0xFFFFFF

if self['downlink_format'] == self.DF_SHORT_AIR2AIR_SURVEILLANCE_0:
self.decode_altitude_msg()
elif self['downlink_format'] == self.DF_SURVEILLANCE_ALTITUDE_REPLY_4:
Expand Down

0 comments on commit e647b0c

Please sign in to comment.