Mercurial > hg > nsaunier > traffic-intelligence
view trafficintelligence/tests/utils.txt @ 1306:4bc0651d91f9 default tip
bug corrected generating last velocity twice and saving it (not saved, duplicated at loading time
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 30 Mar 2026 15:31:34 -0400 |
| parents | 76f5693b530c |
| children |
line wrap: on
line source
>>> from trafficintelligence.utils import * >>> from trafficintelligence.moving import Point >>> from numpy import array, arange >>> upperCaseFirstLetter('mmmm... donuts') 'Mmmm... Donuts' >>> s = upperCaseFirstLetter('much ado about nothing') >>> s == 'Much Ado About Nothing' True >>> upperCaseFirstLetter(s) == s True >>> computeChi2([],[]) 0 >>> computeChi2(list(range(1,10)),list(range(1,10))) 0.0 >>> computeChi2(list(range(1,9)),list(range(1,10))) 0.0 >>> ceilDecimals(1.23, 0) 2.0 >>> ceilDecimals(1.23, 1) 1.3 >>> inBetween(1,2,1.5) True >>> inBetween(2.1,1,1.5) True >>> inBetween(1,2,0) False >>> removeExtension('test-adfasdf.asdfa.txt') 'test-adfasdf.asdfa' >>> removeExtension('test-adfasdf') 'test-adfasdf' >>> values = line2Ints('1 2 3 5 6') >>> values[0] 1 >>> values[-1] 6 >>> values = line2Floats('1.3 2.45 7.158e+01 5 6') >>> values[0] 1.3 >>> values[2] #doctest: +ELLIPSIS 71.5... >>> values[-1] 6.0 >>> filterCategoricalMovingWindow([3]*3 + [4]*4, 2) [3, 3, 3, 4, 4, 4, 4] >>> filterCategoricalMovingWindow([3]*6 + [4], 2) [3, 3, 3, 3, 3, 3, 3] >>> 'c' in filterCategoricalMovingWindow(['a']*3 + ['c'] + ['b']*3, 2) False >>> filterCategoricalMovingWindow([3], 2) [3] >>> filterMovingWindow(arange(10), 3) array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) >>> filterMovingWindow(list(range(10)), 3) array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) >>> filterMovingWindow(arange(10.), 3) array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) >>> filterMovingWindow(arange(10.), 2) array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) >>> stepPlot([3, 5, 7, 8], 1, 10, 0) ([1, 3, 3, 5, 5, 7, 7, 8, 8, 10], [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]) >>> mostCommon(['a','b','c','b']) 'b' >>> mostCommon(['a','b','c','b', 'c']) 'b' >>> mostCommon(list(range(10))+[1]) 1 >>> mostCommon([(1,2), (2,3), (1,2)]) (1, 2) >>> res = sortByLength([list(range(3)), list(range(4)), list(range(1))]) >>> [len(r) for r in res] [1, 3, 4] >>> res = sortByLength([list(range(3)), list(range(4)), list(range(1)), list(range(5))], reverse = True) >>> [len(r) for r in res] [5, 4, 3, 1] >>> lcss = LCSS(similarityFunc = lambda x,y: abs(x-y) <= 0.1) >>> lcss.compute(list(range(5)), list(range(5))) np.int64(5) >>> lcss.compute(list(range(1,5)), list(range(5))) np.int64(4) >>> lcss.compute(list(range(5,10)), list(range(5))) np.int64(0) >>> lcss.compute(list(range(5)), list(range(10))) np.int64(5) >>> lcss.similarityFunc = lambda x,y: x == y >>> lcss.compute(['a','b','c'], ['a','b','c', 'd']) np.int64(3) >>> lcss.computeNormalized(['a','b','c'], ['a','b','c', 'd']) #doctest: +ELLIPSIS 1.0 >>> lcss.computeNormalized(['a','b','c','x'], ['a','b','c', 'd']) #doctest: +ELLIPSIS 0.75 >>> lcss.compute(['a','b','c'], ['a','b','c', 'd']) np.int64(3) >>> lcss.compute(['a','x','b','c'], ['a','b','c','d','x']) np.int64(3) >>> lcss.compute(['a','b','c','x','d'], ['a','b','c','d','x']) np.int64(4) >>> lcss.delta = 1 >>> lcss.compute(['a','b','c'], ['a','b','x','x','c']) np.int64(2) >>> lcss.delta = float('inf') >>> lcss.compute(['a','b','c'], ['a','b','c', 'd'], computeSubSequence = True) np.int64(3) >>> lcss.subSequenceIndices [(0, 0), (1, 1), (2, 2)] >>> lcss.compute(['a','b','c'], ['x','a','b','c'], computeSubSequence = True) np.int64(3) >>> lcss.subSequenceIndices [(0, 1), (1, 2), (2, 3)] >>> lcss.compute(['a','g','b','c'], ['a','b','c', 'd'], computeSubSequence = True) np.int64(3) >>> lcss.subSequenceIndices [(0, 0), (2, 1), (3, 2)] >>> alignedLcss = LCSS(lambda x,y:(abs(x-y) <= 0.1), delta = 2, aligned = True) >>> alignedLcss.compute(list(range(5)), list(range(5))) np.int64(5) >>> alignedLcss.compute(list(range(1,5)), list(range(5))) np.int64(4) >>> alignedLcss.compute(list(range(5,10)), list(range(10))) np.int64(5) >>> lcss.delta = 2 >>> lcss.compute(list(range(5,10)), list(range(10))) np.int64(0) >>> alignedLcss.delta = 6 >>> alignedLcss.compute(list(range(5)), list(range(5))) np.int64(5) >>> alignedLcss.compute(list(range(5)), list(range(6))) np.int64(5) >>> lcss.delta = 10 >>> alignedLcss.compute(list(range(1,7)), list(range(6))) np.int64(5) >>> lcss = LCSS(lambda x,y: x == y, delta = 2, aligned = True) >>> lcss.compute(list(range(20)), [2,4,6,7,8,9,11,13], True) np.int64(8) >>> lcss.subSequenceIndices [(2, 0), (4, 1), (6, 2), (7, 3), (8, 4), (9, 5), (11, 6), (13, 7)] >>> lcss = LCSS(metric = 'cityblock', epsilon = 0.1) >>> lcss.compute([[i] for i in range(5)], [[i] for i in range(5)]) np.int64(5) >>> lcss.compute([[i] for i in range(1,5)], [[i] for i in range(5)]) np.int64(4) >>> lcss.compute([[i] for i in range(5,10)], [[i] for i in range(5)]) np.int64(0) >>> lcss.compute([[i] for i in range(5)], [[i] for i in range(10)]) np.int64(5)
