Filtering new-style subsequent requests

Is Virtual Radar Server not behaving itself? If so then please report it here.
william-ml-leslie
Posts: 1
Joined: Tue Mar 14, 2017 1:28 am

Filtering new-style subsequent requests

Postby william-ml-leslie » Tue Mar 14, 2017 1:49 am

Hi! I have been trying out the new style post requests, and either I am doing it wrong, or there is a big discrepancy between the new and old behaviour. Specifically, it seems none of my filter parameters are working. I've included a simple version of what I was trying, which I tried to implement according to "Known Aircraft" described here: http://www.virtualradarserver.co.uk/Doc ... tList.aspx

When run, it outputs:

$ python subsequent.py
initial-ss took 2.55172681808s
no. aircraft: 79
new-subsequent-ss took 4.52756786346s
no. aircraft: 4824
initial-ss took 2.30466294289s
no. aircraft: 80
old-subsequent-ss took 1.63134288788s
no. aircraft: 80


4824 aircraft is way too much. Here is the test program:

Code: Select all

"""Test comparing the different methods of updating data.

Requires the `python-requests` package.
"""

import requests
import json
import datetime
import time
from contextlib import contextmanager


ADSB_URL = "https://public-api.adsbexchange.com/VirtualRadar/AircraftList.json"

def get_bb(fmt, **other):
    qparams = {
        'fNBnd' : '-33',
        'fSBnd' : '-40',
        'fEBnd' : '151',
        'fWBnd' : '140',
    }
    if fmt is not None:
        qparams['trFmt'] = fmt
    qparams.update(other)
    response = requests.get(ADSB_URL, params=qparams)
    return response.json(), response.cookies

def post_bb(fmt, icaos=(), cookies={}, **other):
    qparams = {
        'fNBnd' : '-33',
        'fSBnd' : '-40',
        'fEBnd' : '151',
        'fWBnd' : '140',
    }
    if icaos:
        # yes, hyphen separated
        qparams['icaos'] = '-'.join(icaos)
    if fmt is not None:
        qparams['trFmt'] = fmt
    qparams.update(other)
    response = requests.post(ADSB_URL, data=qparams, cookies=cookies)
    return response.json(), response.cookies

def get_old_way(fmt, ids, cookies={}, **other):
    qparams = {
        'fNBnd' : '-33',
        'fSBnd' : '-40',
        'fEBnd' : '151',
        'fWBnd' : '140',
    }
    if fmt is not None:
        qparams['trFmt'] = fmt
    qparams.update(other)
    headers = {
        'X-VirtualRadarServer-AircraftIds' : ','.join(ids)
    }
    response = requests.get(ADSB_URL, params=qparams, cookies=cookies,
                            headers=headers)
    return response.json(), response.cookies


@contextmanager
def timing(name):
    t = time.time()
    yield
    print '%s took %ss' % (name, time.time() - t)


def test_new_way():
    with timing('initial-ss'):
        res, cookies = get_bb('ss')
    print 'no. aircraft: %s' % len(res['acList'])

    icows = list(ac['Icao'] for ac in res['acList'] if 'Icao' in ac)
    ids = list(str(ac['Id']) for ac in res['acList'])
    time.sleep(15)

    with timing('new-subsequent-ss'):
        res, cookies = post_bb('ss', icows, cookies=cookies,
                               ldv=res['lastDv'])
    print 'no. aircraft: %s' % len(res['acList'])

def test_old_way():
    with timing('initial-ss'):
        res, cookies = get_bb('ss')
    print 'no. aircraft: %s' % len(res['acList'])

    icows = list(ac['Icao'] for ac in res['acList'] if 'Icao' in ac)
    ids = list(str(ac['Id']) for ac in res['acList'])
    time.sleep(15)

    with timing('old-subsequent-ss'):
        res, cookies = get_old_way('ss', ids, cookies=cookies,
                                   ldv=res['lastDv'])
    print 'no. aircraft: %s' % len(res['acList'])

test_new_way()
test_old_way()

agw
Posts: 1896
Joined: Fri Feb 17, 2012 3:20 am

Re: Filtering new-style subsequent requests

Postby agw » Thu Mar 16, 2017 1:10 am

I'm not au fait with Python but from the looks of it you're passing the filters in the post body along with the icaos? It's just the icaos that go into the post body, the filters are always sent in the query string regardless of how you pass the known aircraft list back to the server.


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 1 guest