messageboard-2020-10-19-1824.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









421422423424425426427428429430431432433434435436437438439440   441442443444445446447448449450451452453454455456457458459460








1983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025








26632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706











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




AIRCRAFT_LENGTH['Embraer 170/175 (twin-jet)'] = (29.90 + 31.68) / 2
AIRCRAFT_LENGTH['EMBRAER 175 (long wing) (twin-jet)'] = 31.68
AIRCRAFT_LENGTH['Embraer ERJ-135 (twin-jet)'] = 26.33
AIRCRAFT_LENGTH['Embraer ERJ-145 (twin-jet)'] = 29.87
AIRCRAFT_LENGTH['Embraer Legacy 450 (twin-jet)'] = 19.69
AIRCRAFT_LENGTH['Embraer Legacy 550 (twin-jet)'] = 20.74
AIRCRAFT_LENGTH['Embraer Phenom 300 (twin-jet)'] = 15.9
AIRCRAFT_LENGTH['Eurocopter EC-635 (twin-turboshaft)'] = 10.21
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream 3 (twin-jet)'] = 25.32
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream G550 (twin-jet)'] = 29.39
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream IV (twin-jet)'] = 26.92
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream V (twin-jet)'] = 29.4
AIRCRAFT_LENGTH['IAI Gulfstream G280 (twin-jet)'] = 20.3
AIRCRAFT_LENGTH['Learjet 35 (twin-jet)'] = 14.83
AIRCRAFT_LENGTH['Learjet 45 (twin-jet)'] = 17.68
AIRCRAFT_LENGTH['Learjet 60 (twin-jet)'] = 17.88
AIRCRAFT_LENGTH['McDonnell Douglas MD-11 (tri-jet)'] = 61.6
AIRCRAFT_LENGTH['Pilatus PC-12 (single-turboprop)'] = 14.4
AIRCRAFT_LENGTH['Raytheon Hawker 800XP (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Rockwell Turbo Commander 690 (twin-turboprop)'] = 11.22





def Log(message, file=None, rolling=None):
  """Write a message to a logfile along with a timestamp.

  Args:
    message: string message to write
    file: string representing file name and, if needed, path to the
      file to write to
    rolling: name of file that will keep only the last n files of file
  """
  # can't define as a default parameter because LOGFILE name is potentially
  # modified based on SIMULATION flag
  if not file:
    file = LOGFILE

  # special case: for the main logfile, we always keep a rolling log
  if not rolling and file == LOGFILE:
    rolling = ROLLING_LOGFILE





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





  # Some names are very similar to others and so appear identical on splitflap
  replacement_names = (
      ('Delta Private Jets', 'DPJ'),
      ('United Parcel Service', 'UPS'))
  for (old, new) in replacement_names:
    if airline and old.upper() == airline.upper():
      airline = new
      break

  if not airline:
    airline = KEY_NOT_PRESENT_STRING
  return airline


def AircraftLength(flight, default=0):
  """Returns length (in meters) of aircraft, or default if unknown."""
  aircraft = flight.get('aircraft_type_friendly')
  if not aircraft:
    return default
  if aircraft not in AIRCRAFT_LENGTH:
    return default
  return AIRCRAFT_LENGTH[aircraft]


def DisplayLength(flight):
  """Returns rounded length (in meters) of aircraft, or UNKNOWN if unknown."""
  length = round(AircraftLength(flight, default=0))
  if length:
    return length
  return KEY_NOT_PRESENT_STRING


def DisplaySpeed(flight):
  """Returns speed in knots or UNKNOWN if not known."""
  return flight.get('speed', KEY_NOT_PRESENT_STRING)


def DisplayVertRate(flight):
  """Returns vertical rate in fpm or UNKNOWN if not known."""
  return flight.get('vert_rate', KEY_NOT_PRESENT_STRING)






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




      which we are attempting to generate an insight.
    percent_size_difference: the minimum size (i.e.: length) difference for the
      insight to warrant including the size details.

  Returns:
    Printable string message; if no message or insights to generate, then an
    empty string.
  """
  message = ''
  this_flight = flights[-1]
  this_flight_number = DisplayFlightNumber(this_flight)
  last_seen = [
      f for f in flights[:-1]
      if DisplayFlightNumber(f) == this_flight_number]

  # Last time this same flight flew a materially different type of aircraft
  if last_seen and 'flight_number' in this_flight:
    last_flight = last_seen[-1]

    last_aircraft = last_flight.get('aircraft_type_friendly')
    last_aircraft_length = AIRCRAFT_LENGTH.get(last_aircraft, 0)

    this_aircraft = this_flight.get('aircraft_type_friendly')
    this_aircraft_length = AIRCRAFT_LENGTH.get(this_aircraft, 0)

    this_likely_commercial_flight = (
        this_flight.get('origin_iata') and this_flight.get('destination_iata'))
    if (this_likely_commercial_flight and this_aircraft
        and not this_aircraft_length):
      Log('%s used in a flight with defined origin & destination but yet is '
          'missing length details' % this_aircraft, file=LOGFILE)
      WriteFile(NEW_AIRCRAFT_FILE, this_aircraft, append=True)

    likely_same_commercial_flight = (
        last_flight.get('origin_iata') == this_flight.get('origin_iata') and
        last_flight.get(
            'destination_iata') == this_flight.get('destination_iata') and
        last_flight.get(
            'airline_call_sign') == this_flight.get('airline_call_sign'))

    this_aircraft_bigger = False
    last_aircraft_bigger = False
    if (likely_same_commercial_flight and
        this_aircraft_length > last_aircraft_length * (




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





01234567890123456789012345678901234567890123456789012345678901234567890123456789









421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463








1986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028








26662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709











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




AIRCRAFT_LENGTH['Embraer 170/175 (twin-jet)'] = (29.90 + 31.68) / 2
AIRCRAFT_LENGTH['EMBRAER 175 (long wing) (twin-jet)'] = 31.68
AIRCRAFT_LENGTH['Embraer ERJ-135 (twin-jet)'] = 26.33
AIRCRAFT_LENGTH['Embraer ERJ-145 (twin-jet)'] = 29.87
AIRCRAFT_LENGTH['Embraer Legacy 450 (twin-jet)'] = 19.69
AIRCRAFT_LENGTH['Embraer Legacy 550 (twin-jet)'] = 20.74
AIRCRAFT_LENGTH['Embraer Phenom 300 (twin-jet)'] = 15.9
AIRCRAFT_LENGTH['Eurocopter EC-635 (twin-turboshaft)'] = 10.21
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream 3 (twin-jet)'] = 25.32
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream G550 (twin-jet)'] = 29.39
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream IV (twin-jet)'] = 26.92
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream V (twin-jet)'] = 29.4
AIRCRAFT_LENGTH['IAI Gulfstream G280 (twin-jet)'] = 20.3
AIRCRAFT_LENGTH['Learjet 35 (twin-jet)'] = 14.83
AIRCRAFT_LENGTH['Learjet 45 (twin-jet)'] = 17.68
AIRCRAFT_LENGTH['Learjet 60 (twin-jet)'] = 17.88
AIRCRAFT_LENGTH['McDonnell Douglas MD-11 (tri-jet)'] = 61.6
AIRCRAFT_LENGTH['Pilatus PC-12 (single-turboprop)'] = 14.4
AIRCRAFT_LENGTH['Raytheon Hawker 800XP (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Rockwell Turbo Commander 690 (twin-turboprop)'] = 11.22
for mixed_case_plane in list(AIRCRAFT_LENGTH.keys()):  # pylint: disable=C0201
  AIRCRAFT_LENGTH[mixed_case_plane.upper()] = AIRCRAFT_LENGTH[mixed_case_plane]
  AIRCRAFT_LENGTH.pop(mixed_case_plane)


def Log(message, file=None, rolling=None):
  """Write a message to a logfile along with a timestamp.

  Args:
    message: string message to write
    file: string representing file name and, if needed, path to the
      file to write to
    rolling: name of file that will keep only the last n files of file
  """
  # can't define as a default parameter because LOGFILE name is potentially
  # modified based on SIMULATION flag
  if not file:
    file = LOGFILE

  # special case: for the main logfile, we always keep a rolling log
  if not rolling and file == LOGFILE:
    rolling = ROLLING_LOGFILE





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





  # Some names are very similar to others and so appear identical on splitflap
  replacement_names = (
      ('Delta Private Jets', 'DPJ'),
      ('United Parcel Service', 'UPS'))
  for (old, new) in replacement_names:
    if airline and old.upper() == airline.upper():
      airline = new
      break

  if not airline:
    airline = KEY_NOT_PRESENT_STRING
  return airline


def AircraftLength(flight, default=0):
  """Returns length (in meters) of aircraft, or default if unknown."""
  aircraft = flight.get('aircraft_type_friendly')
  if not aircraft:
    return default
  if aircraft.upper() not in AIRCRAFT_LENGTH:
    return default
  return AIRCRAFT_LENGTH[aircraft.upper()]


def DisplayLength(flight):
  """Returns rounded length (in meters) of aircraft, or UNKNOWN if unknown."""
  length = round(AircraftLength(flight, default=0))
  if length:
    return length
  return KEY_NOT_PRESENT_STRING


def DisplaySpeed(flight):
  """Returns speed in knots or UNKNOWN if not known."""
  return flight.get('speed', KEY_NOT_PRESENT_STRING)


def DisplayVertRate(flight):
  """Returns vertical rate in fpm or UNKNOWN if not known."""
  return flight.get('vert_rate', KEY_NOT_PRESENT_STRING)






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




      which we are attempting to generate an insight.
    percent_size_difference: the minimum size (i.e.: length) difference for the
      insight to warrant including the size details.

  Returns:
    Printable string message; if no message or insights to generate, then an
    empty string.
  """
  message = ''
  this_flight = flights[-1]
  this_flight_number = DisplayFlightNumber(this_flight)
  last_seen = [
      f for f in flights[:-1]
      if DisplayFlightNumber(f) == this_flight_number]

  # Last time this same flight flew a materially different type of aircraft
  if last_seen and 'flight_number' in this_flight:
    last_flight = last_seen[-1]

    last_aircraft = last_flight.get('aircraft_type_friendly')
    last_aircraft_length = AIRCRAFT_LENGTH.get(last_aircraft.upper(), 0)

    this_aircraft = this_flight.get('aircraft_type_friendly')
    this_aircraft_length = AIRCRAFT_LENGTH.get(this_aircraft.upper(), 0)

    this_likely_commercial_flight = (
        this_flight.get('origin_iata') and this_flight.get('destination_iata'))
    if (this_likely_commercial_flight and this_aircraft
        and not this_aircraft_length):
      Log('%s used in a flight with defined origin & destination but yet is '
          'missing length details' % this_aircraft, file=LOGFILE)
      WriteFile(NEW_AIRCRAFT_FILE, this_aircraft, append=True)

    likely_same_commercial_flight = (
        last_flight.get('origin_iata') == this_flight.get('origin_iata') and
        last_flight.get(
            'destination_iata') == this_flight.get('destination_iata') and
        last_flight.get(
            'airline_call_sign') == this_flight.get('airline_call_sign'))

    this_aircraft_bigger = False
    last_aircraft_bigger = False
    if (likely_same_commercial_flight and
        this_aircraft_length > last_aircraft_length * (




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