def testCreateResponse(self): settings = similarity_pb2.SimilaritySettings() settings.top_n = 7 settings.merge_close_results = False response = similarity.CreateSimilarPatternsResponse( self.base_data, 1, 2, [], sampling_freq, settings) self.assertIsInstance(response, similarity_pb2.SimilarPatternsResponse) self.assertLen(response.similar_patterns, 7)
def SearchSimilarPatterns(similar_patterns_request): """Searches through a file for similar patterns. Args: similar_patterns_request: SimilarPatternsRequest instance defining the search to perform. Returns: SimilarPatternsResponse instance with the found similar patterns, and no extra headers. Raises: ValueError: No channel selected. """ requested_channels = similar_patterns_request.channel_data_ids if not requested_channels: raise ValueError('Must select at least one channel') file_params = similar_patterns_request.file_params waveform_data_source = GetWaveformDataSource(file_params) filter_params = similar_patterns_request.filter_params data = waveform_data_service.GetChunkDataAsNumpy(waveform_data_source, requested_channels, filter_params.low_cut, filter_params.high_cut, filter_params.notch) sampling_freq = waveform_data_service.GetSamplingFrequency( waveform_data_source, requested_channels) seen_events = similar_patterns_request.seen_events settings = similar_patterns_request.settings similar_patterns_response = similarity.CreateSimilarPatternsResponse( data, similar_patterns_request.start_time, similar_patterns_request.duration, seen_events, sampling_freq, settings) return similar_patterns_response, {}
def testCreateResponse(self): response = similarity.CreateSimilarPatternsResponse( self.base_data, 1, 2, sampling_freq) self.assertIsInstance(response, similarity_pb2.SimilarPatternsResponse) self.assertLen(response.similar_patterns, 5)