| 
					
				 | 
			
			
				@@ -100,31 +100,50 @@ def process_segment(item): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 results.append({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     'confidence': match['confidence'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    'timestamp': ts 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    'timestamp': ts, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    'offset': match['offset'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 print("{} {}".format(ts, match['confidence'])) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             except KeyError as ex: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 print(ex, file=sys.stderr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ts += match['length'] / 1000 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        response = client.put_schedule_results( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            item['schedule'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            item['id'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            None, # TODO: send results again 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            found=find_repetitions(results), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 3. Look for success or failure 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    ts = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        print("api response: {}".format(response)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    except ConnectionError as ex: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        print(ex, file=sys.stderr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    except UserWarning as warn: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        print(str(warn), file=sys.stderr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+def find_repetitions(results): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     found_counter = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     found_index = None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     segments_needed = 2 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     seconds_needed = 9 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     threshold = 20 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    found = None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    expect_space = False 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    found = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for index, result in enumerate(results): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if result['confidence'] > threshold: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            found_counter += 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if found_index is None: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                found_index = index 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if not expect_space: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if result['confidence'] > threshold: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                found_counter += 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if found_index is None: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    found_index = index 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                found_counter = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                found_index = None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            found_counter = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            found_index = None 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if result['confidence'] <= threshold: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                expect_space = False 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if found_counter >= segments_needed: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             """ TODO: It will be neccessary to improve this 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -132,22 +151,11 @@ def process_segment(item): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             audio in the same segment of 1 hour. Also the 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             seconds transcurred is important; a time 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             difference is needed """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            found = results[found_index] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            break 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        response = client.put_schedule_results( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            item['schedule'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            item['id'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            None, # TODO: send results again 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            found=found['timestamp'] if found else None, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            found.append(results[found_index]['timestamp']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            found_counter = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            expect_space = True 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print("api response: {}".format(response)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    except ConnectionError as ex: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print(ex, file=sys.stderr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    except UserWarning as warn: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print(str(warn), file=sys.stderr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return found 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def iterate_audios(dt, station): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """ Given a datetime object and an station, 
			 |