From 6b4b7b7e4e37f1c5cc8b446997d1961e37f60c13 Mon Sep 17 00:00:00 2001 From: earthgecko Date: Sun, 7 Jan 2018 12:49:50 +0000 Subject: [PATCH 1/2] Passed max_shift_seconds to milliseconds As per https://github.com/linkedin/luminol/issues/38 --- .../algorithms/correlator_algorithms/cross_correlator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/luminol/algorithms/correlator_algorithms/cross_correlator.py b/src/luminol/algorithms/correlator_algorithms/cross_correlator.py index 0bbbb00..21c9724 100644 --- a/src/luminol/algorithms/correlator_algorithms/cross_correlator.py +++ b/src/luminol/algorithms/correlator_algorithms/cross_correlator.py @@ -26,13 +26,13 @@ def __init__(self, time_series_a, time_series_b, max_shift_seconds=None, shift_i Initializer :param TimeSeries time_series_a: TimeSeries a. :param TimeSeries time_series_b: TimeSeries b. - :param int max_shift_milliseconds: allowed maximal shift seconds. + :param int max_shift_seconds: allowed maximal shift seconds. :param time_period: if given, correlate the data inside the time period only. """ super(CrossCorrelator, self).__init__(self.__class__.__name__, time_series_a, time_series_b) self.shift_impact = shift_impact or DEFAULT_SHIFT_IMPACT if max_shift_seconds is not None: - self.max_shift_milliseconds = max_shift_seconds + self.max_shift_milliseconds = max_shift_seconds * 1000 else: self.max_shift_milliseconds = DEFAULT_ALLOWED_SHIFT_SECONDS * 1000 From 4e20ba5162bed65c39469fef21ee2cf9a81bdb6e Mon Sep 17 00:00:00 2001 From: earthgecko Date: Mon, 8 Jan 2018 14:28:38 +0000 Subject: [PATCH 2/2] Remove milliseconds Changed the use of milliseconds to seconds and removed reference to milliseconds as it is not really used and when it is used it is used somewhat erroneously. --- .../correlator_algorithms/cross_correlator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/luminol/algorithms/correlator_algorithms/cross_correlator.py b/src/luminol/algorithms/correlator_algorithms/cross_correlator.py index 21c9724..5c08b88 100644 --- a/src/luminol/algorithms/correlator_algorithms/cross_correlator.py +++ b/src/luminol/algorithms/correlator_algorithms/cross_correlator.py @@ -32,9 +32,9 @@ def __init__(self, time_series_a, time_series_b, max_shift_seconds=None, shift_i super(CrossCorrelator, self).__init__(self.__class__.__name__, time_series_a, time_series_b) self.shift_impact = shift_impact or DEFAULT_SHIFT_IMPACT if max_shift_seconds is not None: - self.max_shift_milliseconds = max_shift_seconds * 1000 + self.max_shift_seconds = max_shift_seconds else: - self.max_shift_milliseconds = DEFAULT_ALLOWED_SHIFT_SECONDS * 1000 + self.max_shift_seconds = DEFAULT_ALLOWED_SHIFT_SECONDS def _detect_correlation(self): """ @@ -73,8 +73,8 @@ def _detect_correlation(self): r = s / denom if denom != 0 else s correlations.append([delay_in_seconds, r]) # Take shift into account to create a "shifted correlation coefficient". - if self.max_shift_milliseconds: - shifted_correlations.append(r * (1 + float(delay_in_seconds) / self.max_shift_milliseconds * self.shift_impact)) + if self.max_shift_seconds: + shifted_correlations.append(r * (1 + float(delay_in_seconds) / self.max_shift_seconds * self.shift_impact)) else: shifted_correlations.append(r) max_correlation = list(max(correlations, key=lambda k: k[1])) @@ -84,13 +84,13 @@ def _detect_correlation(self): def _find_allowed_shift(self, timestamps): """ - Find the maximum allowed shift steps based on max_shift_milliseconds. + Find the maximum allowed shift steps based on max_shift_seconds. param list timestamps: timestamps of a time series. """ init_ts = timestamps[0] residual_timestamps = [ts - init_ts for ts in timestamps] n = len(residual_timestamps) - return self._find_first_bigger(residual_timestamps, self.max_shift_milliseconds, 0, n) + return self._find_first_bigger(residual_timestamps, self.max_shift_seconds, 0, n) def _find_first_bigger(self, timestamps, target, lower_bound, upper_bound): """