Explorar el Código

Fall tolereance segments are counted only if it's recovered

Gamaliel Espinoza hace 6 años
padre
commit
72b4216a36
Se han modificado 3 ficheros con 22 adiciones y 2 borrados
  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):
     found_counter = 0
+    found_down_counter = 0
     found_index = None
     expect_space = False
     expect_recover = False
@@ -332,6 +333,7 @@ def find_repetitions(results, segments_needed=2, calibration=None):
                 if found_index is None:
                     found_index = index
                 if expect_recover:
+                    found_counter += found_down_counter
                     expect_recover = False
 
             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
                         se podrá esperar un valor bajo """
                         expect_recover = True
-                        found_counter += 1
+                        found_down_counter += 1
                     else:
                         pass
                 else:
@@ -349,11 +351,13 @@ def find_repetitions(results, segments_needed=2, calibration=None):
                     vuelve a salir otro fuera del threshold continuo,
                     entonces ya se da por perdido """
                     found_counter = 0
+                    found_down_counter = 0
                     found_index = None
                     expect_recover = False
 
             else:
                 found_counter = 0
+                found_down_counter = 0
                 found_index = None
                 expect_recover = False
         else:

+ 16 - 0
tests/test_general.py

@@ -82,6 +82,22 @@ class TestGeneral(unittest.TestCase):
 
         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()