test_general.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from __future__ import absolute_import
  2. from ondemand.service import find_repetitions
  3. from ondemand.service import cloud_download
  4. import unittest
  5. import time
  6. class TestGeneral(unittest.TestCase):
  7. """
  8. def test_find_repetitions(self):
  9. found = find_repetitions([
  10. {'timestamp': 1519769650, 'confidence': 5},
  11. {'timestamp': 1519769655, 'confidence': 5},
  12. {'timestamp': 1519769660, 'confidence': 15},
  13. {'timestamp': 1519769665, 'confidence': 15},
  14. {'timestamp': 1519769670, 'confidence': 25},
  15. {'timestamp': 1519769675, 'confidence': 47},
  16. {'timestamp': 1519769680, 'confidence': 150},
  17. {'timestamp': 1519769685, 'confidence': 47},
  18. {'timestamp': 1519769690, 'confidence': 19},
  19. {'timestamp': 1519769695, 'confidence': 15},
  20. {'timestamp': 1519769700, 'confidence': 15},
  21. {'timestamp': 1519769705, 'confidence': 15},
  22. {'timestamp': 1519769710, 'confidence': 15},
  23. {'timestamp': 1519769720, 'confidence': 15},
  24. {'timestamp': 1519769725, 'confidence': 150},
  25. {'timestamp': 1519769730, 'confidence': 300},
  26. {'timestamp': 1519769735, 'confidence': 5},
  27. ])
  28. self.assertEquals(len(found), 2)
  29. self.assertEquals(found[0], 1519769670)
  30. self.assertEquals(found[1], 1519769725)
  31. def test_find_empty_repetitions(self):
  32. found = find_repetitions([])
  33. self.assertTrue(not found)
  34. def test_find_not_enough_data(self):
  35. found = find_repetitions([
  36. {'timestamp': 1519769650, 'confidence': 5},
  37. {'timestamp': 1519769655, 'confidence': 5},
  38. {'timestamp': 1519769660, 'confidence': 100},
  39. {'timestamp': 1519769665, 'confidence': 15},
  40. {'timestamp': 1519769670, 'confidence': 25}
  41. ])
  42. self.assertTrue(not found)
  43. def test_cloud_download(self):
  44. filename, md5hash = cloud_download(ad_key='-L6EoklO90painUCd7df')
  45. print(filename, md5hash)
  46. pass
  47. """
  48. def test_repetitions_new_model(self):
  49. found = find_repetitions([
  50. {'timestamp': 1519769650, 'confidence': 5},
  51. {'timestamp': 1519769655, 'confidence': 1},
  52. {'timestamp': 1519769660, 'confidence': 1},
  53. {'timestamp': 1519769665, 'confidence': 5},
  54. {'timestamp': 1519769670, 'confidence': 3},
  55. {'timestamp': 1519769675, 'confidence': 3},
  56. {'timestamp': 1519769680, 'confidence': 2},
  57. {'timestamp': 1519769685, 'confidence': 3},
  58. {'timestamp': 1519769690, 'confidence': 9},
  59. {'timestamp': 1519769695, 'confidence': 1},
  60. {'timestamp': 1519769700, 'confidence': 2},
  61. {'timestamp': 1519769705, 'confidence': 2},
  62. {'timestamp': 1519769710, 'confidence': 2},
  63. {'timestamp': 1519769720, 'confidence': 3},
  64. {'timestamp': 1519769725, 'confidence': 3},
  65. {'timestamp': 1519769730, 'confidence': 66},
  66. {'timestamp': 1519769735, 'confidence': 12},
  67. {'timestamp': 1519769735, 'confidence': 30},
  68. {'timestamp': 1519769740, 'confidence': 8},
  69. {'timestamp': 1519769745, 'confidence': 34},
  70. {'timestamp': 1519769750, 'confidence': 3},
  71. {'timestamp': 1519769755, 'confidence': 3},
  72. {'timestamp': 1519769760, 'confidence': 3},
  73. {'timestamp': 1519769765, 'confidence': 6},
  74. {'timestamp': 1519769770, 'confidence': 4},
  75. ])
  76. print(found)
  77. def test_case_2(self):
  78. pre = [
  79. 6,4,4,3,4,4,6,2,10,8,16,9,6,5,16,3,6,7,12,
  80. 2,6,6,2,6,6,6,2,2,10,3,4,2,4,6,8,6,6,8,2,2,
  81. 2,4,9,2,4,6,2,3,4,4,12,4,2,28,8,6,6,8,9,2
  82. ]
  83. values = [
  84. {'timestamp': index, 'confidence': x} for index, x in enumerate(pre)
  85. ]
  86. found = find_repetitions(values,
  87. calibration={
  88. 'threshold': 25,
  89. 'fallTolerance': 1,
  90. }
  91. )
  92. self.assertEqual(found, [])
  93. if __name__ == '__main__':
  94. unittest.main()