update tests

This commit is contained in:
Junzi Sun 2019-10-29 23:19:37 +01:00
parent 02c5117de5
commit 3dae0438bf
3 changed files with 160 additions and 37 deletions

97
tests/benchmark.py Normal file
View File

@ -0,0 +1,97 @@
import sys
import time
import pandas as pd
from tqdm import tqdm
fin = sys.argv[1]
df = pd.read_csv(fin, names=["ts", "df", "icao", "msg"])
df_adsb = df[df["df"] == 17].copy()
total = df_adsb.shape[0]
def native():
from pyModeS.decoder import adsb
from pyModeS.decoder import common
msg0 = None
msg1 = None
for i, r in tqdm(df_adsb.iterrows(), total=total):
ts = r.ts
m = r.msg.encode()
downlink_format = common.df(m)
crc = common.crc(m)
icao = adsb.icao(m)
tc = adsb.typecode(m)
if 1 <= tc <= 4:
category = adsb.category(m)
callsign = adsb.callsign(m)
if tc == 19:
velocity = adsb.velocity(m)
if 5 <= tc <= 18:
if adsb.oe_flag(m):
msg1 = m
t1 = ts
else:
msg0 = m
t0 = ts
if msg0 and msg1:
try:
position = adsb.position(msg0, msg1, t0, t1)
except:
continue
altitude = adsb.altitude(m)
def cython():
from pyModeS.c_decoder import adsb
from pyModeS.c_decoder import common
msg0 = None
msg1 = None
for i, r in tqdm(df_adsb.iterrows(), total=total):
ts = r.ts
m = r.msg.encode()
downlink_format = common.df(m)
crc = common.crc(m)
icao = adsb.icao(m)
tc = adsb.typecode(m)
if 1 <= tc <= 4:
category = adsb.category(m)
callsign = adsb.callsign(m)
if tc == 19:
velocity = adsb.velocity(m)
if 5 <= tc <= 18:
if adsb.oe_flag(m):
msg1 = m
t1 = ts
else:
msg0 = m
t0 = ts
if msg0 and msg1:
try:
position = adsb.position(msg0, msg1, t0, t1)
except:
continue
altitude = adsb.altitude(m)
if __name__ == "__main__":
t1 = time.time()
native()
dt1 = time.time() - t1
t2 = time.time()
cython()
dt2 = time.time() - t2

View File

@ -1,44 +1,35 @@
from __future__ import print_function
from pyModeS import adsb, ehs
import csv
from pyModeS import adsb
import logging
# logging.basicConfig(level=logging.INFO)
# === Decode sample data file ===
logging.info("===== Decode ADS-B sample data=====")
f = open("tests/data/sample_data_adsb.csv", "rt")
def adsb_decode_all(n=None):
print("===== Decode ADS-B sample data=====")
import csv
msg0 = None
msg1 = None
f = open("tests/data/sample_data_adsb.csv", "rt")
for i, r in enumerate(csv.reader(f)):
msg0 = None
msg1 = None
ts = r[0]
m = r[1]
icao = adsb.icao(m)
tc = adsb.typecode(m)
if 1 <= tc <= 4:
logging.info([ts, m, icao, tc, adsb.category(m), adsb.callsign(m)])
if tc == 19:
logging.info([ts, m, icao, tc, adsb.velocity(m)])
if 5 <= tc <= 18:
if adsb.oe_flag(m):
msg1 = m
t1 = ts
else:
msg0 = m
t0 = ts
for i, r in enumerate(csv.reader(f)):
if n and i > n:
break
ts = r[0]
m = r[1]
icao = adsb.icao(m)
tc = adsb.typecode(m)
if 1 <= tc <= 4:
print(ts, m, icao, tc, adsb.category(m), adsb.callsign(m))
if tc == 19:
print(ts, m, icao, tc, adsb.velocity(m))
if 5 <= tc <= 18:
if adsb.oe_flag(m):
msg1 = m
t1 = ts
else:
msg0 = m
t0 = ts
if msg0 and msg1:
pos = adsb.position(msg0, msg1, t0, t1)
alt = adsb.altitude(m)
print(ts, m, icao, tc, pos, alt)
if __name__ == "__main__":
adsb_decode_all(n=100)
if msg0 and msg1:
pos = adsb.position(msg0, msg1, t0, t1)
alt = adsb.altitude(m)
logging.info([ts, m, icao, tc, pos, alt])

View File

@ -0,0 +1,35 @@
from pyModeS.c_decoder import adsb
import logging
import csv
# logging.basicConfig(level=logging.INFO)
logging.info("===== Decode ADS-B sample data=====")
f = open("tests/data/sample_data_adsb.csv", "rt")
msg0 = None
msg1 = None
for i, r in enumerate(csv.reader(f)):
ts = int(r[0])
m = str.encode(r[1])
icao = adsb.icao(m)
tc = adsb.typecode(m)
if 1 <= tc <= 4:
logging.info([ts, m, icao, tc, adsb.category(m), adsb.callsign(m)])
if tc == 19:
logging.info([ts, m, icao, tc, adsb.velocity(m)])
if 5 <= tc <= 18:
if adsb.oe_flag(m):
msg1 = m
t1 = ts
else:
msg0 = m
t0 = ts
if msg0 and msg1:
pos = adsb.position(msg0, msg1, t0, t1)
alt = adsb.altitude(m)
logging.info([ts, m, icao, tc, pos, alt])