Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/tests/storage.txt @ 1028:cc5cb04b04b0
major update using the trafficintelligence package name and install through pip
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 15 Jun 2018 11:19:10 -0400 |
parents | python/tests/storage.txt@933670761a57 |
children | aafbc0bab925 |
comparison
equal
deleted
inserted
replaced
1027:6129296848d3 | 1028:cc5cb04b04b0 |
---|---|
1 >>> from storage import * | |
2 >>> from io import StringIO | |
3 >>> from moving import MovingObject, Point, TimeInterval, Trajectory, prepareSplines | |
4 | |
5 >>> f = openCheck('non_existant_file.txt') | |
6 File non_existant_file.txt could not be opened. | |
7 | |
8 >>> nonexistentFilename = "nonexistent" | |
9 >>> loadTrajectoriesFromSqlite(nonexistentFilename, 'feature') | |
10 DB Error: no such table: positions | |
11 DB Error: no such table: velocities | |
12 [] | |
13 >>> from os import remove | |
14 >>> remove(nonexistentFilename) | |
15 | |
16 >>> o1 = MovingObject.generate(2, Point(0.,0.), Point(1.,0.), TimeInterval(0,10)) | |
17 >>> o2 = MovingObject.generate(3, Point(1.,1.), Point(-0.5,-0.2), TimeInterval(0,9)) | |
18 >>> saveTrajectoriesToSqlite('test.sqlite', [o1, o2], 'feature') | |
19 >>> objects = loadTrajectoriesFromSqlite('test.sqlite', 'feature') | |
20 >>> objects[0].getNum() == o1.num | |
21 True | |
22 >>> objects[1].getNum() == o2.num | |
23 True | |
24 >>> o1.getTimeInterval() == objects[0].getTimeInterval() | |
25 True | |
26 >>> o2.getTimeInterval() == objects[1].getTimeInterval() | |
27 True | |
28 >>> o1.getVelocities().length() == objects[0].getVelocities().length() | |
29 True | |
30 >>> o2.getVelocities().length() == objects[1].getVelocities().length() | |
31 True | |
32 >>> o1.getVelocities() == objects[0].getVelocities() | |
33 True | |
34 >>> o2.getVelocities() == objects[1].getVelocities() | |
35 True | |
36 >>> o1.getPositions() == objects[0].getPositions() | |
37 True | |
38 >>> o2.getPositions() == objects[1].getPositions() | |
39 True | |
40 >>> objects = loadTrajectoriesFromSqlite('test.sqlite', 'feature', timeStep = 2) | |
41 >>> objects[0].positions.length() | |
42 6 | |
43 >>> objects[1].positions.length() | |
44 5 | |
45 >>> objects = loadTrajectoriesFromSqlite('test.sqlite', 'feature', timeStep = 3) | |
46 >>> objects[0].positions.length() | |
47 4 | |
48 >>> objects[1].positions.length() | |
49 4 | |
50 >>> align1 = Trajectory.fromPointList([Point(-1, 0), Point(20, 0)]) | |
51 >>> align2 = Trajectory.fromPointList([Point(-9, -3), Point(6, 3)]) | |
52 >>> align1.computeCumulativeDistances() | |
53 >>> align2.computeCumulativeDistances() | |
54 >>> prepareSplines([align1, align2]) | |
55 >>> o1.projectCurvilinear([align1, align2]) | |
56 >>> o2.projectCurvilinear([align1, align2]) | |
57 >>> saveTrajectoriesToSqlite('test.sqlite', [o1, o2], 'curvilinear') | |
58 >>> addCurvilinearTrajectoriesFromSqlite('test.sqlite', {o.num: o for o in objects}) | |
59 >>> o1.curvilinearPositions[3][:2] == objects[0].curvilinearPositions[3][:2] | |
60 True | |
61 >>> o1.curvilinearPositions[7][:2] == objects[0].curvilinearPositions[7][:2] | |
62 True | |
63 >>> [str(l) for l in o1.curvilinearPositions.getLanes()] == objects[0].curvilinearPositions.getLanes() | |
64 True | |
65 >>> o2.curvilinearPositions[2][:2] == objects[1].curvilinearPositions[2][:2] | |
66 True | |
67 >>> o2.curvilinearPositions[6][:2] == objects[1].curvilinearPositions[6][:2] | |
68 True | |
69 >>> [str(l) for l in o2.curvilinearPositions.getLanes()] == objects[1].curvilinearPositions.getLanes() | |
70 True | |
71 >>> remove('test.sqlite') | |
72 | |
73 >>> f1 = MovingObject.generate(3, Point(0.,0.), Point(1.,0.), TimeInterval(0,10)) | |
74 >>> f2 = MovingObject.generate(4, Point(1.,1.), Point(-0.5,-0.2), TimeInterval(0,9)) | |
75 >>> o1 = MovingObject(num = 1, userType = 1) | |
76 >>> o1.features = [f1, f2] | |
77 >>> saveTrajectoriesToSqlite('test.sqlite', [o1], 'object') | |
78 >>> objects = loadTrajectoriesFromSqlite('test.sqlite', 'object', withFeatures = True) | |
79 >>> len(objects) | |
80 1 | |
81 >>> reloaded1 = objects[0] | |
82 >>> reloaded1.getNum() == o1.getNum() | |
83 True | |
84 >>> reloaded1.getUserType() == o1.getUserType() | |
85 True | |
86 >>> len(reloaded1.featureNumbers) | |
87 2 | |
88 >>> len(reloaded1.features) | |
89 2 | |
90 >>> reloaded1.getPositionAt(0) == Point.midPoint(f1.getPositionAt(0), f2.getPositionAt(0)) | |
91 True | |
92 >>> reloaded1.getPositionAt(5) == Point.midPoint(f1.getPositionAt(5), f2.getPositionAt(5)) | |
93 True | |
94 >>> reloaded1.getPositionAt(10) == f1.getPositionAt(10) | |
95 True | |
96 >>> set(reloaded1.featureNumbers) == set([f1.num, f2.num]) | |
97 True | |
98 >>> remove('test.sqlite') | |
99 | |
100 >>> strio = StringIO('# asdlfjasdlkj0\nsadlkfjsdlakjf') | |
101 >>> readline(strio) | |
102 'sadlkfjsdlakjf' | |
103 >>> strio = StringIO('# asdlfjasdlkj0\nsadlkfjsdlakjf') | |
104 >>> readline(strio, ['#']) | |
105 'sadlkfjsdlakjf' | |
106 >>> strio = StringIO('# asdlfjasdlkj0\nsadlkfjsdlakjf') | |
107 >>> readline(strio, ['%']) | |
108 '# asdlfjasdlkj0' | |
109 >>> strio = StringIO('# asdlfjasdlkj0\nsadlkfjsdlakjf') | |
110 >>> readline(strio, '%*$') | |
111 '# asdlfjasdlkj0' | |
112 >>> readline(strio, '%#') | |
113 'sadlkfjsdlakjf' | |
114 | |
115 >>> from sklearn.mixture import GaussianMixture | |
116 >>> from numpy.random import random_sample | |
117 >>> nPoints = 50 | |
118 >>> points = random_sample(nPoints*2).reshape(nPoints,2) | |
119 >>> gmm = GaussianMixture(4, covariance_type = 'full') | |
120 >>> tmp = gmm.fit(points) | |
121 >>> gmmId = 0 | |
122 >>> savePOIsToSqlite('pois-tmp.sqlite', gmm, 'end', gmmId) | |
123 >>> reloadedGmm = loadPOIsFromSqlite('pois-tmp.sqlite') | |
124 >>> sum(gmm.predict(points) == reloadedGmm[gmmId].predict(points)) == nPoints | |
125 True | |
126 >>> reloadedGmm[gmmId].gmmTypes[0] == 'end' | |
127 True | |
128 >>> remove('pois-tmp.sqlite') |