def segment_heuristically(self, sensors, reference_signal, label=None):
        p = PeakAnalysis(self.view)
        peaks = p.get_peaks(reference_signal)

        timestamps = []
        for peak_position in peaks:
            timestamps.append(sensors[0].timestamp[peak_position])

        if label:
            label_timestamps = label.timestamp
            labels = label.label
            closer_labels = []
            closer_timestamps = []

            for i in range(0, len(label_timestamps)):
                min_dist = label_timestamps[len(label_timestamps) - 1] - label_timestamps[0]
                closer_label = None
                closer_timestamp = None

                for heuristic_timestamp in timestamps:
                    dist = sqrt(np.square(label_timestamps[i] - heuristic_timestamp))

                    if dist < min_dist:
                        min_dist = dist
                        closer_label = labels[i]
                        closer_timestamp = heuristic_timestamp

                closer_labels.append(closer_label)
                closer_timestamps.append(closer_timestamp)

            self.segment(sensors, closer_timestamps, closer_labels)
        else:
            self.segment(sensors, timestamps)
dataset/ETHPy150Open tonybeltramelli/Deep-Spying/server/analytics/modules/feature/FeatureExtractor.py/FeatureExtractor.segment_heuristically/original