123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- from __future__ import absolute_import
- from ondemand.service import find_repetitions
- from ondemand.service import cloud_download
- import unittest
- import time
- class TestGeneral(unittest.TestCase):
- """
- def test_find_repetitions(self):
- found = find_repetitions([
- {'timestamp': 1519769650, 'confidence': 5},
- {'timestamp': 1519769655, 'confidence': 5},
- {'timestamp': 1519769660, 'confidence': 15},
- {'timestamp': 1519769665, 'confidence': 15},
- {'timestamp': 1519769670, 'confidence': 25},
- {'timestamp': 1519769675, 'confidence': 47},
- {'timestamp': 1519769680, 'confidence': 150},
- {'timestamp': 1519769685, 'confidence': 47},
- {'timestamp': 1519769690, 'confidence': 19},
- {'timestamp': 1519769695, 'confidence': 15},
- {'timestamp': 1519769700, 'confidence': 15},
- {'timestamp': 1519769705, 'confidence': 15},
- {'timestamp': 1519769710, 'confidence': 15},
- {'timestamp': 1519769720, 'confidence': 15},
- {'timestamp': 1519769725, 'confidence': 150},
- {'timestamp': 1519769730, 'confidence': 300},
- {'timestamp': 1519769735, 'confidence': 5},
- ])
- self.assertEquals(len(found), 2)
- self.assertEquals(found[0], 1519769670)
- self.assertEquals(found[1], 1519769725)
- def test_find_empty_repetitions(self):
- found = find_repetitions([])
- self.assertTrue(not found)
- def test_find_not_enough_data(self):
- found = find_repetitions([
- {'timestamp': 1519769650, 'confidence': 5},
- {'timestamp': 1519769655, 'confidence': 5},
- {'timestamp': 1519769660, 'confidence': 100},
- {'timestamp': 1519769665, 'confidence': 15},
- {'timestamp': 1519769670, 'confidence': 25}
- ])
- self.assertTrue(not found)
- def test_cloud_download(self):
- filename, md5hash = cloud_download(ad_key='-L6EoklO90painUCd7df')
- print(filename, md5hash)
- pass
- """
- def test_repetitions_new_model(self):
- found = find_repetitions([
- {'timestamp': 1519769650, 'confidence': 5},
- {'timestamp': 1519769655, 'confidence': 1},
- {'timestamp': 1519769660, 'confidence': 1},
- {'timestamp': 1519769665, 'confidence': 5},
- {'timestamp': 1519769670, 'confidence': 3},
- {'timestamp': 1519769675, 'confidence': 3},
- {'timestamp': 1519769680, 'confidence': 2},
- {'timestamp': 1519769685, 'confidence': 3},
- {'timestamp': 1519769690, 'confidence': 9},
- {'timestamp': 1519769695, 'confidence': 1},
- {'timestamp': 1519769700, 'confidence': 2},
- {'timestamp': 1519769705, 'confidence': 2},
- {'timestamp': 1519769710, 'confidence': 2},
- {'timestamp': 1519769720, 'confidence': 3},
- {'timestamp': 1519769725, 'confidence': 3},
- {'timestamp': 1519769730, 'confidence': 66},
- {'timestamp': 1519769735, 'confidence': 12},
- {'timestamp': 1519769735, 'confidence': 30},
- {'timestamp': 1519769740, 'confidence': 8},
- {'timestamp': 1519769745, 'confidence': 34},
- {'timestamp': 1519769750, 'confidence': 3},
- {'timestamp': 1519769755, 'confidence': 3},
- {'timestamp': 1519769760, 'confidence': 3},
- {'timestamp': 1519769765, 'confidence': 6},
- {'timestamp': 1519769770, 'confidence': 4},
- ])
- print(found)
- def test_case_2(self):
- pre = [
- 6,4,4,3,4,4,6,2,10,8,16,9,6,5,16,3,6,7,12,
- 2,6,6,2,6,6,6,2,2,10,3,4,2,4,6,8,6,6,8,2,2,
- 2,4,9,2,4,6,2,3,4,4,12,4,2,28,8,6,6,8,9,2
- ]
- values = [
- {'timestamp': index, 'confidence': x} for index, x in enumerate(pre)
- ]
- found = find_repetitions(values,
- calibration={
- 'threshold': 25,
- 'fallTolerance': 1,
- }
- )
- self.assertEqual(found, [])
- if __name__ == '__main__':
- unittest.main()
|