messageboard-2022-10-31-0754.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









71927193719471957196719771987199720072017202720372047205720672077208720972107211 72127213721472157216721772187219722072217222722372247225722672277228722972307231








74107411741274137414741574167417741874197420742174227423742474257426742774287429 74307431743274337434743574367437743874397440744174427443744474457446744774487449











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




  if initial_memory_dump:
    tracemalloc.start(initial_frame_count)

  startup_time = time.time()
  json_desc_dict = {}

  init_timing.append((time.time(), 3))
  flights = UnpickleObjectFromFile(
      PICKLE_FLIGHTS, True, max_days=MAX_INSIGHT_HORIZON_DAYS, heartbeat=True)
  # Clear the loaded flight of any cached data, identified by keys
  # with a specific suffix, since code fixes may change the values for
  # some of those cached elements
  init_timing.append((time.time(), 4))
  for flight in flights:
    for key in list(flight.keys()):
      if key.endswith(CACHED_ELEMENT_PREFIX):
        flight.pop(key)
  init_timing.append((time.time(), 5))
  # We have no use for the memory-hogging persistent_path key of historical
  # flights, so let's remove all those keys and save a lot of memory

  if flights:
    for flight in flights[:-1]:
      if 'persistent_path' in flight:
        del flight['persistent_path']

  screen_history = UnpickleObjectFromFile(PICKLE_SCREENS, True, max_days=2)

  # If we're displaying just a single insight message, we want it to be
  # something unique, to the extent possible; this dict holds a count of
  # the diff types of messages displayed so far
  insight_message_distribution = {}

  # bootstrap the flight insights distribution from a list of insights on each
  # flight (i.e.: flight['insight_types'] for a given flight might look like
  # [1, 2, 7, 9], or [], to indicate which insights were identified; this then
  # transforms that into {0: 25, 1: 18, ...} summing across all flights.
  missing_insights = []
  for flight in flights:
    if 'insight_types' not in flight:
      missing_insights.append('%s on %s' % (




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




                'time_new_flight_found': time_new_flight_found,
                'time_flight_message_inserted': time_flight_message_inserted,
                'time_insight_message_inserted': time_insight_message_inserted})
        PickleObjectToFile(data, PICKLE_FLIGHT_DASHBOARD, True)

      else:
        remote, servo = RefreshArduinos(
            remote, servo,
            to_remote_q, to_servo_q, to_main_q, shutdown,
            flights, json_desc_dict, configuration, screen_history)

    message_queue, next_message_time = ProcessArduinoCommmands(
        to_main_q, flights, configuration, message_queue, next_message_time)

    personal_message = PersonalMessage(
        configuration, message_queue, personal_message)

    # MEMORY MANAGEMENT
    # now that we've saved the flight, we have no more need to keep the
    # memory-hogging persistent_path key of that flight in live memory

    if 'persistent_path' in flights[-1]:
      del flights[-1]['persistent_path']
    # it turns out we only need the last screen in the screen history, not
    # the entire history, so we can purge all the rest from active memory
    # to eliminate a slow-growing memory hog
    if screen_history:
      screen_history = [screen_history[-1]]
    # we also do not need more than MAX_INSIGHT_HORIZON_DAYS of history
    # of the flights, so we can purge flights older than that as the flights
    # list slowly grows over time.  we can search the entire list every time
    # but that's unnecessary; instead we can just pop off the 0-th element
    # each time through the list if it's more than 1 + max days in the past.
    # Why + 1?  Because the histogram generation expects that many *full* days
    # of history, so to make sure we don't have a partial day if we were to
    # generate the monthly histograms mid-day, we will keep an extra day.
    if time.time() - flights[0]['now'] > SECONDS_IN_DAY * (
        MAX_INSIGHT_HORIZON_DAYS + 1):
      flights.pop(0)

    if SIMULATION:




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





01234567890123456789012345678901234567890123456789012345678901234567890123456789









71927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232








74117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451











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




  if initial_memory_dump:
    tracemalloc.start(initial_frame_count)

  startup_time = time.time()
  json_desc_dict = {}

  init_timing.append((time.time(), 3))
  flights = UnpickleObjectFromFile(
      PICKLE_FLIGHTS, True, max_days=MAX_INSIGHT_HORIZON_DAYS, heartbeat=True)
  # Clear the loaded flight of any cached data, identified by keys
  # with a specific suffix, since code fixes may change the values for
  # some of those cached elements
  init_timing.append((time.time(), 4))
  for flight in flights:
    for key in list(flight.keys()):
      if key.endswith(CACHED_ELEMENT_PREFIX):
        flight.pop(key)
  init_timing.append((time.time(), 5))
  # We have no use for the memory-hogging persistent_path key of historical
  # flights, so let's remove all those keys and save a lot of memory
  # TODO: On 2022-10-31, commented out anything deleting persistent path
  if flights:
    for flight in flights[:-1]:
      if 'persistent_path' in flight:
        del flight['persistent_path']

  screen_history = UnpickleObjectFromFile(PICKLE_SCREENS, True, max_days=2)

  # If we're displaying just a single insight message, we want it to be
  # something unique, to the extent possible; this dict holds a count of
  # the diff types of messages displayed so far
  insight_message_distribution = {}

  # bootstrap the flight insights distribution from a list of insights on each
  # flight (i.e.: flight['insight_types'] for a given flight might look like
  # [1, 2, 7, 9], or [], to indicate which insights were identified; this then
  # transforms that into {0: 25, 1: 18, ...} summing across all flights.
  missing_insights = []
  for flight in flights:
    if 'insight_types' not in flight:
      missing_insights.append('%s on %s' % (




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




                'time_new_flight_found': time_new_flight_found,
                'time_flight_message_inserted': time_flight_message_inserted,
                'time_insight_message_inserted': time_insight_message_inserted})
        PickleObjectToFile(data, PICKLE_FLIGHT_DASHBOARD, True)

      else:
        remote, servo = RefreshArduinos(
            remote, servo,
            to_remote_q, to_servo_q, to_main_q, shutdown,
            flights, json_desc_dict, configuration, screen_history)

    message_queue, next_message_time = ProcessArduinoCommmands(
        to_main_q, flights, configuration, message_queue, next_message_time)

    personal_message = PersonalMessage(
        configuration, message_queue, personal_message)

    # MEMORY MANAGEMENT
    # now that we've saved the flight, we have no more need to keep the
    # memory-hogging persistent_path key of that flight in live memory
    # TODO: On 2022-10-31, commented out anything deleting persistent path
    if 'persistent_path' in flights[-1]:
      del flights[-1]['persistent_path']
    # it turns out we only need the last screen in the screen history, not
    # the entire history, so we can purge all the rest from active memory
    # to eliminate a slow-growing memory hog
    if screen_history:
      screen_history = [screen_history[-1]]
    # we also do not need more than MAX_INSIGHT_HORIZON_DAYS of history
    # of the flights, so we can purge flights older than that as the flights
    # list slowly grows over time.  we can search the entire list every time
    # but that's unnecessary; instead we can just pop off the 0-th element
    # each time through the list if it's more than 1 + max days in the past.
    # Why + 1?  Because the histogram generation expects that many *full* days
    # of history, so to make sure we don't have a partial day if we were to
    # generate the monthly histograms mid-day, we will keep an extra day.
    if time.time() - flights[0]['now'] > SECONDS_IN_DAY * (
        MAX_INSIGHT_HORIZON_DAYS + 1):
      flights.pop(0)

    if SIMULATION:




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