Gamaliel Espinoza Macedo 6 lat temu
rodzic
commit
40e6041a5b
3 zmienionych plików z 48 dodań i 11 usunięć
  1. 14 9
      ondemand/calibration.py
  2. 1 1
      ondemand/service.py
  3. 33 1
      tests/test_general.py

+ 14 - 9
ondemand/calibration.py

@@ -16,7 +16,8 @@ class Calibrations(object):
     # ceil = la duracion del audio en segmentos de 5
     # integer = la duracion exacto del audio 
 
-    def __init__(self, device_id):
+    def __init__(self, device_id, client=None):
+        self.client = client
         self.dev_ref = fbdb.reference('devices').child(device_id)
         self.calibrations_ref = self.dev_ref.child('calibrations')
         self.thread = None
@@ -24,14 +25,7 @@ class Calibrations(object):
         self.items = {}
 
     def get(self, station):
-        calref = self.calibrations_ref.child(station)
-
-        try:
-            remote = calref.get()
-        except fbdb.ApiCallError as err:
-            log.error('[get] {}'.format(err))
-            remote = None
-
+        remote = self.get_remote(station)
         local  = self.items.get(station, None)
 
         if not remote and not local:
@@ -80,3 +74,14 @@ class Calibrations(object):
 
         return self.items[station]
 
+    def get_remote(self, station):
+        try:
+            if self.client:
+                return self.client.get_calibrations(station=station)
+            else:
+                calref = self.calibrations_ref.child(station)
+                return calref.get()
+
+        except Exception as err:
+            log.error('[Calibrations.get_remote] {}'.format(err))
+            return None

+ 1 - 1
ondemand/service.py

@@ -72,7 +72,7 @@ dejavu = Dejavu({"database_type":"mem"})
 device_id = config['device_id']
 device_path = os.path.join(base_path, device_id)
 recognizer = FilePerSecondRecognizer
-calibrations = Calibrations(config['device_id'])
+calibrations = Calibrations(config['device_id'], client=client)
 
 # settings
 queue_mode = QUEUE_THREAD

+ 33 - 1
tests/test_general.py

@@ -6,7 +6,7 @@ import time
 
 
 class TestGeneral(unittest.TestCase):
-
+    """
     def test_find_repetitions(self):
         found = find_repetitions([
             {'timestamp': 1519769650, 'confidence': 5},
@@ -49,6 +49,38 @@ class TestGeneral(unittest.TestCase):
         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)
 
 
 if __name__ == '__main__':