01234567890123456789012345678901234567890123456789012345678901234567890123456789
43244325432643274328432943304331433243334334433543364337433843394340434143424343 43444345434643474348434943504351435243534354435543564357435843594360436143624363 44274428442944304431443244334434443544364437443844394440444144424443444444454446 44474448444944504451445244534454445544564457445844594460446144624463446444654466 49104911491249134914491549164917491849194920492149224923492449254926492749284929 4930493149324933493449354936493749384939494049414942494349444945494649474948494949504951 5658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703 |
<----SKIPPED LINES---->
histograms_to_generate.append({'generate': 'airline', 'truncate': int(TRUNCATE/2)})
if which_histograms in ['aircraft', 'all']:
histograms_to_generate.append({'generate': 'aircraft'})
if which_histograms in ['altitude', 'all']:
histograms_to_generate.append({'generate': 'altitude', 'exhaustive': True})
if which_histograms in ['bearing', 'all']:
histograms_to_generate.append({'generate': 'bearing'})
if which_histograms in ['distance', 'all']:
histograms_to_generate.append({'generate': 'distance', 'exhaustive': True})
if which_histograms in ['day_of_week', 'all']:
histograms_to_generate.append({'generate': 'day_of_week'})
if which_histograms in ['day_of_month', 'all']:
histograms_to_generate.append({'generate': 'day_of_month'})
for histogram in histograms_to_generate:
this_histogram = which_histograms
if this_histogram == 'all':
this_histogram = histogram['generate']
(key, sort, title, hours) = HistogramSettingsKeySortTitle(this_histogram, hours)
CreateSingleHistogramChart(
flights,
key,
sort,
title,
truncate=histogram.get('truncate', TRUNCATE),
hours=hours,
exhaustive=histogram.get('exhaustive', False))
filename = filename_prefix + histogram['generate'] + '.' + filename_suffix
matplotlib.pyplot.savefig(filename)
matplotlib.pyplot.close()
histograms_generated = [h['generate'] for h in histograms_to_generate]
return histograms_generated
def MessageboardHistograms(
flights,
which_histograms,
how_much_history,
<----SKIPPED LINES---->
or which_histograms == 'day_of_week'):
histograms_to_generate.append({
'generate': 'day_of_week',
'columns': 3,
'absolute': True})
if ((which_histograms == 'all' and how_much_history == '30d')
or which_histograms == 'day_of_month'):
histograms_to_generate.append({
'generate': 'day_of_month',
'columns': 3,
'suppress_percent_sign': True,
'column_divider': '|',
'absolute': True})
for histogram in histograms_to_generate:
this_histogram = which_histograms
if this_histogram == 'all':
this_histogram = histogram['generate']
(key, sort, title, hours) = HistogramSettingsKeySortTitle(this_histogram, hours)
histogram = MessageboardHistogram(
flights,
key,
sort,
title,
screen_limit=screen_limit,
columns=histogram.get('columns', 2),
suppress_percent_sign=histogram.get('suppress_percent_sign', False),
column_divider=histogram.get('column_divider', ' '),
data_summary=data_summary,
hours=hours,
absolute=histogram.get('absolute', False))
messages.extend(histogram)
messages = [(FLAG_MSG_HISTOGRAM, m) for m in messages]
return messages
def MessageboardHistogram(
<----SKIPPED LINES---->
def CheckRebootNeeded(startup_time, message_queue, json_desc_dict, configuration):
"""Reboot based on duration instance has been running.
Reboot needed in one of the following situations:
- All quiet: if running for over 24 hours and all is quiet (message queue empty and
no planes in radio).
- Mostly quiet: if running for over 36 hours and message queue is empty and it's 3a.
- Reboot requested via html form.
Also checks if reset requested via html form.
"""
reboot = False
global SHUTDOWN_SIGNAL
running_hours = (time.time() - startup_time) / SECONDS_IN_HOUR
if (
running_hours >= HOURS_IN_DAY and
not message_queue and
not json_desc_dict.get('radio_range_flights')):
reboot = True
Log('All quiet reboot needed after running for %.2f hours' % running_hours)
if (
running_hours > HOURS_IN_DAY * 1.5 and
not message_queue and
int(EpochDisplayTime(time.time(), '%-H')) >= 3):
msg = 'Early morning reboot needed after running for %.2f hours' % running_hours
SHUTDOWN_SIGNAL = msg
Log(msg)
reboot = True
if 'soft_reboot' in configuration:
msg = 'Soft reboot requested via web form'
SHUTDOWN_SIGNAL = msg
Log(msg)
reboot = True
RemoveSetting(configuration, 'soft_reboot')
if 'end_process' in configuration:
msg = 'Process end requested via web form'
SHUTDOWN_SIGNAL = msg
<----SKIPPED LINES---->
for file in files_to_overwrite:
os.remove(file)
for f in saved_flights:
# we would like to use verify=True, but that's too slow without further optimizing the
# verification step for a loop of data
PickleObjectToFile(
f, PICKLE_FLIGHTS, True, timestamp=f['now'], verify=False)
return False
def HeartbeatRestart():
"""Logs a system down / system up pair of heartbeats as system is first starting."""
if SIMULATION:
return 0
UpdateDashboard(True) # Indicates that this wasn't running a moment before, ...
UpdateDashboard(False) # ... and now it is running!
return time.time()
def Heartbeat(last_heartbeat_time):
"""Logs a system up pair of heartbeat."""
if SIMULATION:
return last_heartbeat_time
now = time.time()
if now - last_heartbeat_time > HEARTBEAT_SECONDS:
UpdateDashboard(False)
last_heartbeat_time = now
return last_heartbeat_time
def VersionControl():
"""Copies the current instances of messageboard.py and arduino.py into a repository.
To aid debugging, we want to keep past versions of the code easily accessible, and
linked to the errors that have been logged. This function copies the python code
into a version control directory after adding in a date / time stamp to the file name.
"""
def MakeCopy(python_prefix):
file_extension = '.py'
live_name = python_prefix + '.py'
live_path = os.path.join(CODE_REPOSITORY, live_name)
epoch = os.path.getmtime(live_path)
last_modified_suffix = EpochDisplayTime(epoch, format_string='-%Y-%m-%d-%H%M')
<----SKIPPED LINES---->
|
01234567890123456789012345678901234567890123456789012345678901234567890123456789
432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368 44324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475 491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942 49434944494549464947494849494950495149524953495449554956495749584959496049614962 5669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714 |
<----SKIPPED LINES---->
histograms_to_generate.append({'generate': 'airline', 'truncate': int(TRUNCATE/2)})
if which_histograms in ['aircraft', 'all']:
histograms_to_generate.append({'generate': 'aircraft'})
if which_histograms in ['altitude', 'all']:
histograms_to_generate.append({'generate': 'altitude', 'exhaustive': True})
if which_histograms in ['bearing', 'all']:
histograms_to_generate.append({'generate': 'bearing'})
if which_histograms in ['distance', 'all']:
histograms_to_generate.append({'generate': 'distance', 'exhaustive': True})
if which_histograms in ['day_of_week', 'all']:
histograms_to_generate.append({'generate': 'day_of_week'})
if which_histograms in ['day_of_month', 'all']:
histograms_to_generate.append({'generate': 'day_of_month'})
for histogram in histograms_to_generate:
this_histogram = which_histograms
if this_histogram == 'all':
this_histogram = histogram['generate']
(key, sort, title, hours) = HistogramSettingsKeySortTitle(this_histogram, hours)
# if multiple histograms are getting generated, this might take a few seconds;
# logging a heartbeat with each histogram ensures that monitoring.py does not
# mistake this pause for a hang.
Heartbeat()
CreateSingleHistogramChart(
flights,
key,
sort,
title,
truncate=histogram.get('truncate', TRUNCATE),
hours=hours,
exhaustive=histogram.get('exhaustive', False))
filename = filename_prefix + histogram['generate'] + '.' + filename_suffix
matplotlib.pyplot.savefig(filename)
matplotlib.pyplot.close()
histograms_generated = [h['generate'] for h in histograms_to_generate]
return histograms_generated
def MessageboardHistograms(
flights,
which_histograms,
how_much_history,
<----SKIPPED LINES---->
or which_histograms == 'day_of_week'):
histograms_to_generate.append({
'generate': 'day_of_week',
'columns': 3,
'absolute': True})
if ((which_histograms == 'all' and how_much_history == '30d')
or which_histograms == 'day_of_month'):
histograms_to_generate.append({
'generate': 'day_of_month',
'columns': 3,
'suppress_percent_sign': True,
'column_divider': '|',
'absolute': True})
for histogram in histograms_to_generate:
this_histogram = which_histograms
if this_histogram == 'all':
this_histogram = histogram['generate']
(key, sort, title, hours) = HistogramSettingsKeySortTitle(this_histogram, hours)
# if multiple histograms are getting generated, this might take a few seconds;
# logging a heartbeat with each histogram ensures that monitoring.py does not
# mistake this pause for a hang.
Heartbeat()
histogram = MessageboardHistogram(
flights,
key,
sort,
title,
screen_limit=screen_limit,
columns=histogram.get('columns', 2),
suppress_percent_sign=histogram.get('suppress_percent_sign', False),
column_divider=histogram.get('column_divider', ' '),
data_summary=data_summary,
hours=hours,
absolute=histogram.get('absolute', False))
messages.extend(histogram)
messages = [(FLAG_MSG_HISTOGRAM, m) for m in messages]
return messages
def MessageboardHistogram(
<----SKIPPED LINES---->
def CheckRebootNeeded(startup_time, message_queue, json_desc_dict, configuration):
"""Reboot based on duration instance has been running.
Reboot needed in one of the following situations:
- All quiet: if running for over 24 hours and all is quiet (message queue empty and
no planes in radio).
- Mostly quiet: if running for over 36 hours and message queue is empty and it's 3a.
- Reboot requested via html form.
Also checks if reset requested via html form.
"""
reboot = False
global SHUTDOWN_SIGNAL
running_hours = (time.time() - startup_time) / SECONDS_IN_HOUR
if (
running_hours >= HOURS_IN_DAY and
not message_queue and
not json_desc_dict.get('radio_range_flights')):
msg = 'All quiet reboot needed after running for %.2f hours' % running_hours
SHUTDOWN_SIGNAL = msg
Log(msg)
reboot = True
if (
running_hours > HOURS_IN_DAY * 1.5 and
not message_queue and
int(EpochDisplayTime(time.time(), '%-H')) >= 3):
msg = 'Early morning reboot needed after running for %.2f hours' % running_hours
SHUTDOWN_SIGNAL = msg
Log(msg)
reboot = True
if 'soft_reboot' in configuration:
msg = 'Soft reboot requested via web form'
SHUTDOWN_SIGNAL = msg
Log(msg)
reboot = True
RemoveSetting(configuration, 'soft_reboot')
if 'end_process' in configuration:
msg = 'Process end requested via web form'
SHUTDOWN_SIGNAL = msg
<----SKIPPED LINES---->
for file in files_to_overwrite:
os.remove(file)
for f in saved_flights:
# we would like to use verify=True, but that's too slow without further optimizing the
# verification step for a loop of data
PickleObjectToFile(
f, PICKLE_FLIGHTS, True, timestamp=f['now'], verify=False)
return False
def HeartbeatRestart():
"""Logs a system down / system up pair of heartbeats as system is first starting."""
if SIMULATION:
return 0
UpdateDashboard(True) # Indicates that this wasn't running a moment before, ...
UpdateDashboard(False) # ... and now it is running!
return time.time()
def Heartbeat(last_heartbeat_time=None):
"""Logs a system up heartbeat."""
if SIMULATION:
return last_heartbeat_time
now = time.time()
if not last_heartbeat_time or now - last_heartbeat_time > HEARTBEAT_SECONDS:
UpdateDashboard(False)
last_heartbeat_time = now
return last_heartbeat_time
def VersionControl():
"""Copies the current instances of messageboard.py and arduino.py into a repository.
To aid debugging, we want to keep past versions of the code easily accessible, and
linked to the errors that have been logged. This function copies the python code
into a version control directory after adding in a date / time stamp to the file name.
"""
def MakeCopy(python_prefix):
file_extension = '.py'
live_name = python_prefix + '.py'
live_path = os.path.join(CODE_REPOSITORY, live_name)
epoch = os.path.getmtime(live_path)
last_modified_suffix = EpochDisplayTime(epoch, format_string='-%Y-%m-%d-%H%M')
<----SKIPPED LINES---->
|