Mercurial Hosting > traffic-intelligence
comparison python/tests/tutorials.py @ 648:da665302c88d
added some tutorial code as tests to avoid tutorial to become out of sync with code changes
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 15 Apr 2015 18:17:50 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
647:458890c0437c | 648:da665302c88d |
---|---|
1 import unittest | |
2 | |
3 class TestNGSIM(unittest.TestCase): | |
4 'Tutorial example for NGSIM data' | |
5 | |
6 def test_ex1(self): | |
7 import storage | |
8 objects = storage.loadTrajectoriesFromNgsimFile('../samples/trajectories-0400-0415.txt',100) | |
9 for o in objects: o.plot() | |
10 | |
11 class TestTrajectoryLoading(unittest.TestCase): | |
12 'Tutorial example for NGSIM data' | |
13 | |
14 def test_ex1(self): | |
15 import storage | |
16 objects = storage.loadTrajectoriesFromSqlite('../samples/laurier.sqlite', 'object') | |
17 | |
18 speed = objects[0].getVelocityAtInstant(10).norm2() | |
19 timeInterval = objects[0].getTimeInterval() | |
20 speeds = [objects[0].getVelocityAtInstant(t).norm2() for t in range(timeInterval.first, timeInterval.last)] | |
21 speeds = [v.norm2() for v in objects[0].getVelocities()] | |
22 | |
23 from matplotlib.pyplot import plot, close, axis | |
24 plot(range(timeInterval.first, timeInterval.last+1), speeds) | |
25 | |
26 close('all') | |
27 objects[0].plot() | |
28 axis('equal') | |
29 | |
30 features = storage.loadTrajectoriesFromSqlite('../samples/laurier.sqlite', 'feature') | |
31 objects[0].setFeatures(features) | |
32 | |
33 for f in objects[0].features: | |
34 f.plot() | |
35 axis('equal') | |
36 | |
37 | |
38 if __name__ == '__main__': | |
39 unittest.main() |