Ejemplo n.º 1
0
def search_airplanes():

  search_config = [
    {'field': 'TailNum', 'label': 'Tail Number'},
    {'field': 'Owner', 'sort_order': 0},
    {'field': 'OwnerState', 'label': 'Owner State'},
    {'field': 'Manufacturer', 'sort_order': 1},
    {'field': 'Model', 'sort_order': 2},
    {'field': 'ManufacturerYear', 'label': 'MFR Year'},
    {'field': 'SerialNumber', 'label': 'Serial Number'},
    {'field': 'EngineManufacturer', 'label': 'Engine MFR', 'sort_order': 3},
    {'field': 'EngineModel', 'label': 'Engine Model', 'sort_order': 4}
  ]

  # Pagination parameters
  start = request.args.get('start') or 0
  start = int(start)
  end = request.args.get('end') or config.AIRPLANE_RECORDS_PER_PAGE
  end = int(end)

  # Navigation path and offset setup
  nav_path = search_helpers.strip_place(request.url)
  nav_offsets = search_helpers.get_navigation_offsets(
    start, 
    end, 
    config.AIRPLANE_RECORDS_PER_PAGE
  )

  # Build the base of our elasticsearch query
  query = {
    'query': {
      'bool': {
        'must': []}
    },
    'from': start,
    'size': config.AIRPLANE_RECORDS_PER_PAGE
  }

  arg_dict = {}
  for item in search_config:
    field = item['field']
    value = request.args.get(field)
    arg_dict[field] = value
    if value:
      query['query']['bool']['must'].append({'match': {field: value}})

  # Query elasticsearch, process to get records and count
  results = elastic.search(query, index='agile_data_science')
  airplanes, airplane_count = search_helpers.process_search(results)

  # Persist search parameters in the form template
  return render_template(
    'all_airplanes.html',
    search_config=search_config,
    args=arg_dict,
    airplanes=airplanes,
    airplane_count=airplane_count,
    nav_path=nav_path,
    nav_offsets=nav_offsets,
  )
Ejemplo n.º 2
0
def search_flights():

    # Search parameters
    carrier = request.args.get('Carrier')
    flight_date = request.args.get('FlightDate')
    origin = request.args.get('Origin')
    dest = request.args.get('Dest')
    tail_number = request.args.get('TailNum')
    flight_number = request.args.get('FlightNum')

    # Pagination parameters
    start = request.args.get('start') or 0
    start = int(start)
    end = request.args.get('end') or config.RECORDS_PER_PAGE
    end = int(end)

    # Navigation path and offset setup
    nav_path = search_helpers.strip_place(request.url)
    nav_offsets = search_helpers.get_navigation_offsets(
        start, end, config.RECORDS_PER_PAGE)

    # Build the base of our elasticsearch query
    query = {
        'query': {
            'bool': {
                'must': []
            }
        },
        'sort': [{
            'FlightDate': 'asc'
        }, '_score'],
        'from': start,
        'size': config.RECORDS_PER_PAGE
    }

    # Add any search parameters present
    if carrier:
        query['query']['bool']['must'].append({'match': {'Carrier': carrier}})
    if flight_date:
        query['query']['bool']['must'].append(
            {'match': {
                'FlightDate': flight_date
            }})
    if origin:
        query['query']['bool']['must'].append({'match': {'Origin': origin}})
    if dest:
        query['query']['bool']['must'].append({'match': {'Dest': dest}})
    if tail_number:
        query['query']['bool']['must'].append(
            {'match': {
                'TailNum': tail_number
            }})
    if flight_number:
        query['query']['bool']['must'].append(
            {'match': {
                'FlightNum': flight_number
            }})

    # Query elasticsearch, process to get records and count
    results = elastic.search(query, index='agile_data_science')
    flights, flight_count = process_search(results)

    # Persist search parameters in the form template
    return render_template('search.html',
                           flights=flights,
                           flight_date=flight_date,
                           flight_count=flight_count,
                           nav_path=nav_path,
                           nav_offsets=nav_offsets,
                           carrier=carrier,
                           origin=origin,
                           dest=dest,
                           tail_number=tail_number,
                           flight_number=flight_number)
Ejemplo n.º 3
0
def search_airplanes():

  search_config = [
    {'field': 'TailNum', 'label': 'Tail Number'},
    {'field': 'Owner', 'sort_order': 0},
    {'field': 'OwnerState', 'label': 'Owner State'},
    {'field': 'Manufacturer', 'sort_order': 1},
    {'field': 'Model', 'sort_order': 2},
    {'field': 'ManufacturerYear', 'label': 'MFR Year'},
    {'field': 'SerialNumber', 'label': 'Serial Number'},
    {'field': 'EngineManufacturer', 'label': 'Engine MFR', 'sort_order': 3},
    {'field': 'EngineModel', 'label': 'Engine Model', 'sort_order': 4}
  ]

  # Pagination parameters
  start = request.args.get('start') or 0
  start = int(start)
  end = request.args.get('end') or config.AIRPLANE_RECORDS_PER_PAGE
  end = int(end)

  # Navigation path and offset setup
  nav_path = search_helpers.strip_place(request.url)
  nav_offsets = search_helpers.get_navigation_offsets(start, end, config.AIRPLANE_RECORDS_PER_PAGE)

  print("nav_path: [{}]".format(nav_path))
  print(json.dumps(nav_offsets))

  # Build the base of our elasticsearch query
  query = {
    'query': {
      'bool': {
        'must': []}
    },
    'sort': [
      {'Owner': {'order': 'asc'} },
      # {'Manufacturer': {'order': 'asc', 'ignore_unmapped' : True} },
      # {'Model': {'order': 'asc', 'ignore_unmapped': True} },
      # {'EngineManufacturer': {'order': 'asc', 'ignore_unmapped' : True} },
      # {'EngineModel': {'order': 'asc', 'ignore_unmapped': True} },
      # {'TailNum': {'order': 'asc', 'ignore_unmapped' : True} },
      '_score'
    ],
    'from': start,
    'size': config.AIRPLANE_RECORDS_PER_PAGE
  }

  arg_dict = {}
  for item in search_config:
    field = item['field']
    value = request.args.get(field)
    print(field, value)
    arg_dict[field] = value
    if value:
      query['query']['bool']['must'].append({'match': {field: value}})

  # Query elasticsearch, process to get records and count
  results = elastic.search(query)
  airplanes, airplane_count = search_helpers.process_search(results)

  # Persist search parameters in the form template
  return render_template(
    'all_airplanes.html',
    search_config=search_config,
    args=arg_dict,
    airplanes=airplanes,
    airplane_count=airplane_count,
    nav_path=nav_path,
    nav_offsets=nav_offsets,
  )
def search_airplanes():

    search_config = [{
        'field': 'TailNum',
        'label': 'Tail Number'
    }, {
        'field': 'Owner',
        'sort_order': 0
    }, {
        'field': 'OwnerState',
        'label': 'Owner State'
    }, {
        'field': 'Manufacturer',
        'sort_order': 1
    }, {
        'field': 'Model',
        'sort_order': 2
    }, {
        'field': 'ManufacturerYear',
        'label': 'MFR Year'
    }, {
        'field': 'SerialNumber',
        'label': 'Serial Number'
    }, {
        'field': 'EngineManufacturer',
        'label': 'Engine MFR',
        'sort_order': 3
    }, {
        'field': 'EngineModel',
        'label': 'Engine Model',
        'sort_order': 4
    }]

    # Pagination parameters
    start = request.args.get('start') or 0
    start = int(start)
    end = request.args.get('end') or config.AIRPLANE_RECORDS_PER_PAGE
    end = int(end)

    # Navigation path and offset setup
    nav_path = search_helpers.strip_place(request.url)
    nav_offsets = search_helpers.get_navigation_offsets(
        start, end, config.AIRPLANE_RECORDS_PER_PAGE)

    print("nav_path: [{}]".format(nav_path))
    print(json.dumps(nav_offsets))

    # Build the base of our elasticsearch query
    query = {
        'query': {
            'bool': {
                'must': []
            }
        },
        # 'sort': [
        #   {"Owner": {"order": "asc", "unmapped_type" : "string"} },
        #   {'Manufacturer': {'order': 'asc', 'ignore_unmapped' : True} },
        #   {'Model': {'order': 'asc', 'ignore_unmapped': True} },
        #   {'EngineManufacturer': {'order': 'asc', 'ignore_unmapped' : True} },
        #   {'EngineModel': {'order': 'asc', 'ignore_unmapped': True} },
        #   {'TailNum': {'order': 'asc', 'ignore_unmapped' : True} },
        #   '_score'
        # ],
        'from': start,
        'size': config.AIRPLANE_RECORDS_PER_PAGE
    }

    arg_dict = {}
    for item in search_config:
        field = item['field']
        value = request.args.get(field)
        print(field, value)
        arg_dict[field] = value
        if value:
            query['query']['bool']['must'].append({'match': {field: value}})

    print("arg_sict is {}".format(arg_dict))
    print("QUERY")
    print(json.dumps(query))
    # Query elasticsearch, process to get records and count
    results = elastic.search(query)
    airplanes, airplane_count = search_helpers.process_search(results)

    # Persist search parameters in the form template
    return render_template(
        'all_airplanes.html',
        search_config=search_config,
        args=arg_dict,
        airplanes=airplanes,
        airplane_count=airplane_count,
        nav_path=nav_path,
        nav_offsets=nav_offsets,
    )
Ejemplo n.º 5
0
def search_flights():

  # Search parameters
  carrier = request.args.get('Carrier')
  flight_date = request.args.get('FlightDate')
  origin = request.args.get('Origin')
  dest = request.args.get('Dest')
  tail_number = request.args.get('TailNum')
  flight_number = request.args.get('FlightNum')

  # Pagination parameters
  start = request.args.get('start') or 0
  start = int(start)
  end = request.args.get('end') or config.RECORDS_PER_PAGE
  end = int(end)

  # Navigation path and offset setup
  nav_path = search_helpers.strip_place(request.url)
  nav_offsets = search_helpers.get_navigation_offsets(start, end, config.RECORDS_PER_PAGE)

  # Build the base of our elasticsearch query
  query = {
    'query': {
      'bool': {
        'must': []}
    },
    'sort': [
      {'FlightDate': {'order': 'asc', 'ignore_unmapped' : True} },
      {'DepTime': {'order': 'asc', 'ignore_unmapped' : True} },
      {'Carrier': {'order': 'asc', 'ignore_unmapped' : True} },
      {'FlightNum': {'order': 'asc', 'ignore_unmapped' : True} },
      '_score'
    ],
    'from': start,
    'size': config.RECORDS_PER_PAGE
  }

  # Add any search parameters present
  if carrier:
    query['query']['bool']['must'].append({'match': {'Carrier': carrier}})
  if flight_date:
    query['query']['bool']['must'].append({'match': {'FlightDate': flight_date}})
  if origin:
    query['query']['bool']['must'].append({'match': {'Origin': origin}})
  if dest:
    query['query']['bool']['must'].append({'match': {'Dest': dest}})
  if tail_number:
    query['query']['bool']['must'].append({'match': {'TailNum': tail_number}})
  if flight_number:
    query['query']['bool']['must'].append({'match': {'FlightNum': flight_number}})

  # Query elasticsearch, process to get records and count
  results = elastic.search(query)
  flights, flight_count = search_helpers.process_search(results)

  # Persist search parameters in the form template
  return render_template(
    'search.html',
    flights=flights,
    flight_date=flight_date,
    flight_count=flight_count,
    nav_path=nav_path,
    nav_offsets=nav_offsets,
    carrier=carrier,
    origin=origin,
    dest=dest,
    tail_number=tail_number,
    flight_number=flight_number
    )