Skip to content

Commit

Permalink
Store statistics recurrently using a time, once per hour
Browse files Browse the repository at this point in the history
Version 2.3.7
  • Loading branch information
Wolfrax committed Jun 9, 2018
1 parent 692120a commit 5874c82
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions client/spots.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ <h4 id="hdFlightDB"></h4>
prev_nr_preambles = series['valid_preambles'];

$("#hdStatistics").html("Version " + series['spots_version'] + " " +
"running since " + series['start_time_string'] + " " +
"(latest restart " + series['latest_start_time_string'] + ")");
"running since " + series['start_time_string'] + "<br> " +
"Latest restart " + series['latest_start_time_string']);

stats.push(series['df_total']);
stats.push(series['df_0']);
Expand Down
2 changes: 1 addition & 1 deletion radar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pkg_resources import get_distribution, DistributionNotFound
import os.path

VERSION = "2.3.6"
VERSION = "2.3.7"

try:
_dist = get_distribution('spots')
Expand Down
7 changes: 7 additions & 0 deletions radar/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@ def __init__(self):
self['start_time'] = self['latest_start_time']
self['start_time_string'] = self['latest_start_time_string']

self.stat_timer = RepeatTimer(3600, self.dump, "Statistics timer") # Dump statistics to file once per hour
self.stat_timer.start()

def __setitem__(self, key, value):
self.data[key] = value

Expand All @@ -745,6 +748,10 @@ def dump(self):
with open(self.loc, 'wt') as stat_file:
simplejson.dump(self.data, stat_file, skipkeys=True, indent=4*' ')

def stop(self):
self.stat_timer.cancel()
self.dump()

def __str__(self):
st = "\n"
st += "Preambles:{}\n".format(self['valid_preambles'])
Expand Down
6 changes: 3 additions & 3 deletions radar/radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def __init__(self):
# We create a simple persistent storage for counting of flights
self.flight_db = FlightDB(basic.ADSB.cfg_flight_db_name)
self.flight_db.dump()
self.flight_timer = basic.RepeatTimer(10 * 60, self._dump_flight_db, "Radar flight DB timer")
self.flight_timer = basic.RepeatTimer(600, self._dump_flight_db, "Radar flight DB timer")
self.flight_timer.start()

self.blip_timer = basic.RepeatTimer(1, self._scan_blips, "Radar blip timer")
Expand Down Expand Up @@ -409,14 +409,14 @@ def _die(self):
self.logger.info("Radar dying")

if basic.ADSB.cfg_use_flight_db:
self._dump_flight_db()
self.flight_timer.cancel()
self._dump_flight_db()
self.finished.set()
self.blip_timer.cancel()
self.stat_timer.cancel()
if self.cfg_use_text_display:
self.screen.close()
basic.statistics.dump()
basic.statistics.stop()

def tuner_read(self, msgs, stop=False):
"""
Expand Down

0 comments on commit 5874c82

Please sign in to comment.