1- from io import StringIO
21import unittest
3- import tsfresh
4- from src .edgeml .predictor import Predictor
5- from pandas .util .testing import assert_frame_equal
6- from numpy .testing import assert_array_equal
7- import pandas as pd
82
9- class TestInterpolation (unittest .TestCase ):
10- def setUp (self ):
11- self ._time = 1652044007265
3+ class TestStringMethods (unittest .TestCase ):
124
13- self ._p = Predictor (
14- lambda input : 5 ,
15- ['ACC_RAW_z' , 'ACC_RAW_y' , 'ACC_RAW_x' ],
16- 5 ,
17- ['62536901f2e49867b6936d9b' , '62536901f2e49867b6936d9c' ]
18- )
5+ def test_upper (self ):
6+ self .assertEqual ('foo' .upper (), 'FOO' )
197
20- self ._z = [ 5 , None , None , None , None , None , None , 45 , None , 49 ]
21- self ._y = [None , None , 9 , 10 , 11 , 12 , None , 1 , None , 2 ]
22- self ._x = [ 5 , 6 , None , 41 , 42 , 43 , 44 , 45 , 46 , None ]
23-
24- def test_end (self ):
25- i = 0
26-
27- while i < len (self ._x ):
28- t = self ._time + i * 1000
29- self ._z [i ] and self ._p .add_datapoint ('ACC_RAW_z' , float (self ._z [i ]), t )
30- self ._y [i ] and self ._p .add_datapoint ('ACC_RAW_y' , float (self ._y [i ]), t )
31- self ._x [i ] and self ._p .add_datapoint ('ACC_RAW_x' , float (self ._x [i ]), t )
32- i = i + 1
33-
34- samples = Predictor ._merge (self ._p .store )
35- interp = Predictor ._interpolate (samples )
36-
37- assert_frame_equal (pd .read_csv (StringIO (interp .to_csv ())), pd .read_csv (StringIO ("""
38- ,ACC_RAW_z,ACC_RAW_y,ACC_RAW_x,id
39- 2022-05-08 21:06:47.265,5.0,9.0,5.0,0
40- 2022-05-08 21:06:48.265,10.714285714285715,9.0,6.0,0
41- 2022-05-08 21:06:49.265,16.42857142857143,9.0,23.5,0
42- 2022-05-08 21:06:50.265,22.142857142857142,10.0,41.0,0
43- 2022-05-08 21:06:51.265,27.857142857142858,11.0,42.0,0
44- 2022-05-08 21:06:52.265,33.57142857142857,12.0,43.0,0
45- 2022-05-08 21:06:53.265,39.285714285714285,6.5,44.0,0
46- 2022-05-08 21:06:54.265,45.0,1.0,45.0,0
47- 2022-05-08 21:06:55.265,47.0,1.5,46.0,0
48- 2022-05-08 21:06:56.265,49.0,2.0,46.0,0""" )))
49-
50- def test_before_window (self ):
51- i = 0
52-
53- while i < 4 :
54- t = self ._time + i * 1000
55- self ._z [i ] and self ._p .add_datapoint ('ACC_RAW_z' , float (self ._z [i ]), t )
56- self ._y [i ] and self ._p .add_datapoint ('ACC_RAW_y' , float (self ._y [i ]), t )
57- self ._x [i ] and self ._p .add_datapoint ('ACC_RAW_x' , float (self ._x [i ]), t )
58- i = i + 1
59-
60- samples = Predictor ._merge (self ._p .store )
61- interp = Predictor ._interpolate (samples )
62-
63- assert_frame_equal (pd .read_csv (StringIO (interp .to_csv ())), pd .read_csv (StringIO ("""
64- ,ACC_RAW_z,ACC_RAW_y,ACC_RAW_x,id
65- 2022-05-08 21:06:47.265,5.0,9.0,5.0,0
66- 2022-05-08 21:06:48.265,5.0,9.0,6.0,0
67- 2022-05-08 21:06:49.265,5.0,9.0,23.5,0
68- 2022-05-08 21:06:50.265,5.0,10.0,41.0,0""" )))
69-
70- def test_after_window (self ):
71- i = 0
72-
73- while i < 7 :
74- t = self ._time + i * 1000
75- self ._z [i ] and self ._p .add_datapoint ('ACC_RAW_z' , float (self ._z [i ]), t )
76- self ._y [i ] and self ._p .add_datapoint ('ACC_RAW_y' , float (self ._y [i ]), t )
77- self ._x [i ] and self ._p .add_datapoint ('ACC_RAW_x' , float (self ._x [i ]), t )
78- i = i + 1
79-
80- samples = Predictor ._merge (self ._p .store )
81- interp = Predictor ._interpolate (samples )
82-
83- assert_frame_equal (pd .read_csv (StringIO (interp .to_csv ())), pd .read_csv (StringIO ("""
84- ,ACC_RAW_z,ACC_RAW_y,ACC_RAW_x,id
85- 2022-05-08 21:06:47.265,5.0,9.0,5.0,0
86- 2022-05-08 21:06:48.265,5.0,9.0,6.0,0
87- 2022-05-08 21:06:49.265,5.0,9.0,23.5,0
88- 2022-05-08 21:06:50.265,5.0,10.0,41.0,0
89- 2022-05-08 21:06:51.265,5.0,11.0,42.0,0
90- 2022-05-08 21:06:52.265,5.0,12.0,43.0,0
91- 2022-05-08 21:06:53.265,5.0,12.0,44.0,0""" )))
92-
93- class TestFeatureExtraction (unittest .TestCase ):
94- def setUp (self ):
95- _time = 1652044007265
96-
97- _p = Predictor (
98- lambda input : 5 ,
99- ['ACC_RAW_z' , 'ACC_RAW_y' , 'ACC_RAW_x' ],
100- 5 ,
101- ['62536901f2e49867b6936d9b' , '62536901f2e49867b6936d9c' ]
102- )
103-
104- _z = [ 5 , None , None , None , None , None , None , 45 , None , 49 ]
105- _y = [None , None , 9 , 10 , 11 , 12 , None , 1 , None , 2 ]
106- _x = [ 5 , 6 , None , 41 , 42 , 43 , 44 , 45 , 46 , None ]
107-
108- i = 0
109-
110- while i < len (_x ):
111- t = _time + i * 1000
112- _z [i ] and _p .add_datapoint ('ACC_RAW_z' , float (_z [i ]), t )
113- _y [i ] and _p .add_datapoint ('ACC_RAW_y' , float (_y [i ]), t )
114- _x [i ] and _p .add_datapoint ('ACC_RAW_x' , float (_x [i ]), t )
115- i = i + 1
116-
117- samples = Predictor ._merge (_p .store )
118- self .interp = Predictor ._interpolate (samples )
119-
120- def test_tsfresh (self ):
121- settings = tsfresh .feature_extraction .settings .MinimalFCParameters ()
122- features = tsfresh .extract_features (
123- self .interp , column_id = "id" , default_fc_parameters = settings , n_jobs = 0 , disable_progressbar = True
124- )
125-
126- # ordering
127- self .assertEqual (features .iloc [0 ].index .tolist (), [
128- 'ACC_RAW_z__sum_values' ,
129- 'ACC_RAW_z__median' ,
130- 'ACC_RAW_z__mean' ,
131- 'ACC_RAW_z__length' ,
132- 'ACC_RAW_z__standard_deviation' ,
133- 'ACC_RAW_z__variance' ,
134- 'ACC_RAW_z__root_mean_square' ,
135- 'ACC_RAW_z__maximum' ,
136- 'ACC_RAW_z__absolute_maximum' ,
137- 'ACC_RAW_z__minimum' , 'ACC_RAW_y__sum_values' , 'ACC_RAW_y__median' , 'ACC_RAW_y__mean' , 'ACC_RAW_y__length' , 'ACC_RAW_y__standard_deviation' , 'ACC_RAW_y__variance' , 'ACC_RAW_y__root_mean_square' , 'ACC_RAW_y__maximum' , 'ACC_RAW_y__absolute_maximum' , 'ACC_RAW_y__minimum' , 'ACC_RAW_x__sum_values' , 'ACC_RAW_x__median' , 'ACC_RAW_x__mean' , 'ACC_RAW_x__length' , 'ACC_RAW_x__standard_deviation' , 'ACC_RAW_x__variance' , 'ACC_RAW_x__root_mean_square' , 'ACC_RAW_x__maximum' , 'ACC_RAW_x__absolute_maximum' , 'ACC_RAW_x__minimum' ])
138- # values
139- assert_array_equal (features .iloc [0 ].values .tolist (), [
140- 296.0 ,
141- 30.714285714285715 ,
142- 29.6 ,
143- 10.0 ,
144- 14.89908913802643 ,
145- 221.9828571428571 ,
146- 33.13823859445244 ,
147- 49.0 ,
148- 49.0 ,
149- 5.0 , 71.0 , 9.0 , 7.1 , 10.0 , 3.916631205513228 , 15.34 , 8.108637370113428 , 12.0 , 12.0 , 1.0 , 341.5 , 42.5 , 34.15 , 10.0 , 15.614176251086706 , 243.80250000000007 , 37.55029959933742 , 46.0 , 46.0 , 5.0 ]
150- )
8+ def test_isupper (self ):
9+ self .assertTrue ('FOO' .isupper ())
10+ self .assertFalse ('Foo' .isupper ())
15111
12+ def test_split (self ):
13+ s = 'hello world'
14+ self .assertEqual (s .split (), ['hello' , 'world' ])
15+ # check that s.split fails when the separator is not a string
16+ with self .assertRaises (TypeError ):
17+ s .split (2 )
15218
15319if __name__ == '__main__' :
15420 unittest .main ()
0 commit comments