messageboard-2020-06-19-1654.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









93949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133








142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190








12161217121812191220122112221223122412251226122712281229123012311232123312341235 1236123712381239124012411242124312441245  12461247124812491250125112521253125412551256125712581259126012611262126312641265











                            <----SKIPPED LINES---->




PICKLE_FLIGHTS = 'pickle/flights.pk'

# This allows us to identify the full history (including what was last sent
# to the splitflap display in a programmatic fashion. While it may be
# interesting in its own right, its real use is to handle the "replay"
# button, so we know to enable it if what is displayed is the last flight.
PICKLE_SCREENS = 'pickle/screens.pk'

# Status data about messageboard - is it running, etc.  Specifically, has tuples
# of data (timestamp, system_id, status), where system_id is either the pin id
# of GPIO, or a 0 to indicate overall system, and status is boolean
PICKLE_DASHBOARD = 'pickle/dashboard.pk'

CACHED_ELEMENT_PREFIX = 'cached_'

# This web-exposed file is used for non-error messages that might highlight
# data or code logic to check into. It is only cleared out manually.
LOGFILE = 'log.txt'
# Identical to the LOGFILE, except it includes just the most recent n lines.
# Newest lines are at the end.
ROLLING_LOGFILE = 'rolling_log.txt' #file for error messages

# default number of lines which may be overridden by settings file
ROLLING_LOG_SIZE = 1000

# Users can trigger .png histograms analogous to the text ones from the web
# interface; this is the folder (within WEBSERVER_PATH) where those files are
# placed
WEBSERVER_IMAGE_RELATIVE_FOLDER = 'images/'
# Multiple histograms can be generated, i.e. for airline, aircraft, day of
# week, etc. The output files are named by the prefix & suffix, i.e.: prefix +
# type + . + suffix, as in histogram_aircraft.png. These names match up to the
# names expected by the html page that displays the images. Also, note that the
# suffix is interpreted by matplotlib to identify the image format to create.
HISTOGRAM_IMAGE_PREFIX = 'histogram_'
HISTOGRAM_IMAGE_SUFFIX = 'png'
HISTOGRAM_IMAGE_HTML = 'histograms.html'

# This file indicates a pending request for histograms - either png,
# text-based, or both; once it is processed, this file is deleted. The
# contents are concatenated key-value pairs, histogram=all;




                            <----SKIPPED LINES---->




CONFIG_FILE = 'secure/settings.txt'
CONFIG_BOOLEANS = (
    'setting_screen_enabled', 'next_flight', 'reset_logs', 'log_jsons')
# A few key settings for the messageboard are its sensitivity to displaying
# flights - though it logs all flights within range, it may not be desirable
# to display all flights to the user. Two key parameters are the maximum
# altitude, and the furthest away we anticipate the flight being at its
# closest point to HOME. As those two parameters are manipulated in the
# settings, a histogram is displayed with one or potentially two series,
# showing the present and potentially prior-set distribution of flights,
# by hour throughout the day, over the last seven days, normalized to
# flights per day. This allows those parameters to be fine-tuned in a
# useful way. This file is the location, on the webserver, of that image,
# which needs to be in alignment with the html page that displays it.
HOURLY_IMAGE_FILE = 'hours.png'

# This is all messages that have been sent to the board since the last time
# the file was manually cleared. Newest messages are at the bottom. It is
# visible at the webserver.
#enumeration of all messages sent to board
ALL_MESSAGE_FILE = 'all_messages.txt'
# This shows the most recent n messages sent to the board. Newest messages
# are at the top for easier viewing of "what did I miss".
ROLLING_MESSAGE_FILE = 'rolling_messages.txt'

STDERR_FILE = 'stderr.txt'
BACKUP_FILE = 'backup.txt'
SERVICE_VERIFICATION_FILE = 'service-verification.txt'
UPTIMES_FILE = 'uptimes.html'

FLAG_MSG_FLIGHT = 1  # basic flight details
FLAG_MSG_INSIGHT = 2  # random tidbit about a flight
FLAG_MSG_HISTOGRAM = 3  # histogram message
FLAG_MSG_CLEAR = 4  # a blank message to clear the screen
# user-entered message to display for some duration of time
FLAG_MSG_PERSONAL = 5

FLAG_INSIGHT_LAST_SEEN = 0
FLAG_INSIGHT_DIFF_AIRCRAFT = 1
FLAG_INSIGHT_NTH_FLIGHT = 2
FLAG_INSIGHT_GROUNDSPEED = 3
FLAG_INSIGHT_ALTITUDE = 4
FLAG_INSIGHT_VERTRATE = 5
FLAG_INSIGHT_FIRST_DEST = 6
FLAG_INSIGHT_FIRST_ORIGIN = 7
FLAG_INSIGHT_FIRST_AIRLINE = 8
FLAG_INSIGHT_FIRST_AIRCRAFT = 9
FLAG_INSIGHT_LONGEST_DELAY = 10
FLAG_INSIGHT_FLIGHT_DELAY_FREQUENCY = 11




                            <----SKIPPED LINES---->




      earliest_date = EpochDisplayTime(
          time.time() - (max_days - 1) * SECONDS_IN_DAY, '%Y-%m-%d')
      files = [f for f in files if f[:10] >= earliest_date]

    files = sorted(
        [os.path.join(directory, f) for f in files if pattern.match(f)])
  else:
    if os.path.exists(full_path):
      files = [full_path]
    else:
      return []

  data = []

  if filenames:
    return files

  for file in files:
    if heartbeat:
      Heartbeat()

    try:
      with open(file, 'rb') as f:
        while True:
          try:
            data.append(pickle.load(f))
          except (UnicodeDecodeError) as e:
            Log('Process %s reading file %s gave error %s' % (
                psutil.Process(os.getpid()).name(), f, e))
    except (EOFError, pickle.UnpicklingError):
      pass



  return data


cached_object_count = {}
def PickleObjectToFile(
    data, full_path, date_segmentation, timestamp=None, verify=False):
  """Append one pickled flight to the end of binary file.

  Args:
    data: data to pickle
    full_path: name (potentially including path) of the pickled file
    date_segmentation: boolean indicating whether the date string yyyy-mm-dd
      should be prepended to the file name in full_path based on the current
      date, so that pickled files are segmented by date.
    timestamp: if date_segmentation is True, this is used rather than system
      time to generate the file name.
    verify: boolean indicating if we should verify that the pickled file object
      count increments by one, rewriting entire pickle file if it doesn't. Note
      that since this requires reading the entire pickle file and unpickling,




                            <----SKIPPED LINES---->





01234567890123456789012345678901234567890123456789012345678901234567890123456789









93949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133








142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190








12161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268











                            <----SKIPPED LINES---->




PICKLE_FLIGHTS = 'pickle/flights.pk'

# This allows us to identify the full history (including what was last sent
# to the splitflap display in a programmatic fashion. While it may be
# interesting in its own right, its real use is to handle the "replay"
# button, so we know to enable it if what is displayed is the last flight.
PICKLE_SCREENS = 'pickle/screens.pk'

# Status data about messageboard - is it running, etc.  Specifically, has tuples
# of data (timestamp, system_id, status), where system_id is either the pin id
# of GPIO, or a 0 to indicate overall system, and status is boolean
PICKLE_DASHBOARD = 'pickle/dashboard.pk'

CACHED_ELEMENT_PREFIX = 'cached_'

# This web-exposed file is used for non-error messages that might highlight
# data or code logic to check into. It is only cleared out manually.
LOGFILE = 'log.txt'
# Identical to the LOGFILE, except it includes just the most recent n lines.
# Newest lines are at the end.
ROLLING_LOGFILE = 'secure/rolling_log.txt' #file for error messages

# default number of lines which may be overridden by settings file
ROLLING_LOG_SIZE = 1000

# Users can trigger .png histograms analogous to the text ones from the web
# interface; this is the folder (within WEBSERVER_PATH) where those files are
# placed
WEBSERVER_IMAGE_RELATIVE_FOLDER = 'images/'
# Multiple histograms can be generated, i.e. for airline, aircraft, day of
# week, etc. The output files are named by the prefix & suffix, i.e.: prefix +
# type + . + suffix, as in histogram_aircraft.png. These names match up to the
# names expected by the html page that displays the images. Also, note that the
# suffix is interpreted by matplotlib to identify the image format to create.
HISTOGRAM_IMAGE_PREFIX = 'histogram_'
HISTOGRAM_IMAGE_SUFFIX = 'png'
HISTOGRAM_IMAGE_HTML = 'histograms.html'

# This file indicates a pending request for histograms - either png,
# text-based, or both; once it is processed, this file is deleted. The
# contents are concatenated key-value pairs, histogram=all;




                            <----SKIPPED LINES---->




CONFIG_FILE = 'secure/settings.txt'
CONFIG_BOOLEANS = (
    'setting_screen_enabled', 'next_flight', 'reset_logs', 'log_jsons')
# A few key settings for the messageboard are its sensitivity to displaying
# flights - though it logs all flights within range, it may not be desirable
# to display all flights to the user. Two key parameters are the maximum
# altitude, and the furthest away we anticipate the flight being at its
# closest point to HOME. As those two parameters are manipulated in the
# settings, a histogram is displayed with one or potentially two series,
# showing the present and potentially prior-set distribution of flights,
# by hour throughout the day, over the last seven days, normalized to
# flights per day. This allows those parameters to be fine-tuned in a
# useful way. This file is the location, on the webserver, of that image,
# which needs to be in alignment with the html page that displays it.
HOURLY_IMAGE_FILE = 'hours.png'

# This is all messages that have been sent to the board since the last time
# the file was manually cleared. Newest messages are at the bottom. It is
# visible at the webserver.
#enumeration of all messages sent to board
ALL_MESSAGE_FILE = 'secure/all_messages.txt'
# This shows the most recent n messages sent to the board. Newest messages
# are at the top for easier viewing of "what did I miss".
ROLLING_MESSAGE_FILE = 'rolling_messages.txt'

STDERR_FILE = 'secure/stderr.txt'
BACKUP_FILE = 'secure/backup.txt'
SERVICE_VERIFICATION_FILE = 'secure/service-verification.txt'
UPTIMES_FILE = 'uptimes.php'

FLAG_MSG_FLIGHT = 1  # basic flight details
FLAG_MSG_INSIGHT = 2  # random tidbit about a flight
FLAG_MSG_HISTOGRAM = 3  # histogram message
FLAG_MSG_CLEAR = 4  # a blank message to clear the screen
# user-entered message to display for some duration of time
FLAG_MSG_PERSONAL = 5

FLAG_INSIGHT_LAST_SEEN = 0
FLAG_INSIGHT_DIFF_AIRCRAFT = 1
FLAG_INSIGHT_NTH_FLIGHT = 2
FLAG_INSIGHT_GROUNDSPEED = 3
FLAG_INSIGHT_ALTITUDE = 4
FLAG_INSIGHT_VERTRATE = 5
FLAG_INSIGHT_FIRST_DEST = 6
FLAG_INSIGHT_FIRST_ORIGIN = 7
FLAG_INSIGHT_FIRST_AIRLINE = 8
FLAG_INSIGHT_FIRST_AIRCRAFT = 9
FLAG_INSIGHT_LONGEST_DELAY = 10
FLAG_INSIGHT_FLIGHT_DELAY_FREQUENCY = 11




                            <----SKIPPED LINES---->




      earliest_date = EpochDisplayTime(
          time.time() - (max_days - 1) * SECONDS_IN_DAY, '%Y-%m-%d')
      files = [f for f in files if f[:10] >= earliest_date]

    files = sorted(
        [os.path.join(directory, f) for f in files if pattern.match(f)])
  else:
    if os.path.exists(full_path):
      files = [full_path]
    else:
      return []

  data = []

  if filenames:
    return files

  for file in files:
    if heartbeat:
      Heartbeat()
    new_data = []
    try:
      with open(file, 'rb') as f:
        while True:
          try:
            new_data.append(pickle.load(f))
          except (UnicodeDecodeError) as e:
            Log('Process %s reading file %s gave error %s' % (
                psutil.Process(os.getpid()).name(), f, e))
    except (EOFError, pickle.UnpicklingError):
      pass

    data.extend(new_data)

  return data


cached_object_count = {}
def PickleObjectToFile(
    data, full_path, date_segmentation, timestamp=None, verify=False):
  """Append one pickled flight to the end of binary file.

  Args:
    data: data to pickle
    full_path: name (potentially including path) of the pickled file
    date_segmentation: boolean indicating whether the date string yyyy-mm-dd
      should be prepended to the file name in full_path based on the current
      date, so that pickled files are segmented by date.
    timestamp: if date_segmentation is True, this is used rather than system
      time to generate the file name.
    verify: boolean indicating if we should verify that the pickled file object
      count increments by one, rewriting entire pickle file if it doesn't. Note
      that since this requires reading the entire pickle file and unpickling,




                            <----SKIPPED LINES---->