Browse Source

Fall tolereance segments are counted only if it's recovered

Gamaliel Espinoza 6 years ago
parent
commit
72b4216a36
3 changed files with 22 additions and 2 deletions
  1. 1 1
      ondemand/__init__.py
  2. 5 1
      ondemand/service.py
  3. 16 0
      tests/test_general.py

+ 1 - 1
ondemand/__init__.py

@@ -1 +1 @@
-__version__ = '1.3.2-rc4'
+__version__ = '1.3.2-rc5'

+ 5 - 1
ondemand/service.py

@@ -308,6 +308,7 @@ def process_segment(item, audios=None, calibration=None):
 
 
 def find_repetitions(results, segments_needed=2, calibration=None):
 def find_repetitions(results, segments_needed=2, calibration=None):
     found_counter = 0
     found_counter = 0
+    found_down_counter = 0
     found_index = None
     found_index = None
     expect_space = False
     expect_space = False
     expect_recover = False
     expect_recover = False
@@ -332,6 +333,7 @@ def find_repetitions(results, segments_needed=2, calibration=None):
                 if found_index is None:
                 if found_index is None:
                     found_index = index
                     found_index = index
                 if expect_recover:
                 if expect_recover:
+                    found_counter += found_down_counter
                     expect_recover = False
                     expect_recover = False
 
 
             elif fall_tolerance:
             elif fall_tolerance:
@@ -341,7 +343,7 @@ def find_repetitions(results, segments_needed=2, calibration=None):
                         un valor en el rango del threshold, es cuando
                         un valor en el rango del threshold, es cuando
                         se podrá esperar un valor bajo """
                         se podrá esperar un valor bajo """
                         expect_recover = True
                         expect_recover = True
-                        found_counter += 1
+                        found_down_counter += 1
                     else:
                     else:
                         pass
                         pass
                 else:
                 else:
@@ -349,11 +351,13 @@ def find_repetitions(results, segments_needed=2, calibration=None):
                     vuelve a salir otro fuera del threshold continuo,
                     vuelve a salir otro fuera del threshold continuo,
                     entonces ya se da por perdido """
                     entonces ya se da por perdido """
                     found_counter = 0
                     found_counter = 0
+                    found_down_counter = 0
                     found_index = None
                     found_index = None
                     expect_recover = False
                     expect_recover = False
 
 
             else:
             else:
                 found_counter = 0
                 found_counter = 0
+                found_down_counter = 0
                 found_index = None
                 found_index = None
                 expect_recover = False
                 expect_recover = False
         else:
         else:

+ 16 - 0
tests/test_general.py

@@ -82,6 +82,22 @@ class TestGeneral(unittest.TestCase):
 
 
         print(found)
         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__':
 if __name__ == '__main__':
     unittest.main()
     unittest.main()