1# coding=utf-8
2"""
3© 2014 LinkedIn Corp. All rights reserved.
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0
7
8Unless required by applicable law or agreed to in writing, software
9distributed under the License is distributed on an "AS IS" BASIS,
10WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11"""
12"""
13Constants to use for luminol
14"""
15
16"""
17Detector Constants
18"""
19# Indicate which algorithm to use to calculate anomaly scores.
20ANOMALY_DETECTOR_ALGORITHM = 'bitmap_detector'
21
22# Indicate which algorithm to use to get refined maximal score within each anomaly.
23ANOMALY_DETECTOR_REFINE_ALGORITHM = 'exp_avg_detector'
24
25# Default percent threshold value on anomaly score above which is considered an anomaly.
26DEFAULT_SCORE_PERCENT_THRESHOLD = 0.2
27
28# Constants for BitmapDetector.
29# Window sizes as percentiles of the whole data length.
30DEFAULT_BITMAP_LEADING_WINDOW_SIZE_PCT = 0.2 / 16
31
32DEFAULT_BITMAP_LAGGING_WINDOW_SIZE_PCT = 0.2 / 16
33
34DEFAULT_BITMAP_MINIMAL_POINTS_IN_WINDOWS = 50
35
36DEFAULT_BITMAP_MAXIMAL_POINTS_IN_WINDOWS = 200
37
38# Chunk size.
39# Data points form chunks and frequencies of similar chunks are used to determine anomaly scores.
40DEFAULT_BITMAP_CHUNK_SIZE = 2
41
42DEFAULT_BITMAP_PRECISION = 4
43
44# Constants for ExpAvgDetector.
45DEFAULT_EMA_SMOOTHING_FACTOR = 0.2
46
47DEFAULT_EMA_WINDOW_SIZE_PCT = 0.2
48
49# Constants for DerivativeDetector.
50DEFAULT_DERI_SMOOTHING_FACTOR = 0.2
51
52ANOMALY_THRESHOLD = {
53    'exp_avg_detector': 3,
54    'default_detector': 3
55}
56
57# Percentage threshold on anomaly score below which is considered noises.
58DEFAULT_NOISE_PCT_THRESHOLD = 0.001
59
60# The score weight default detector uses.
61DEFAULT_DETECTOR_EMA_WEIGHT = 0.65
62
63# The default minimal ema score for the deault detector to use weighted score.
64DEFAULT_DETECTOR_EMA_SIGNIFICANT = 0.94
65
66"""
67Correlator Constants
68"""
69CORRELATOR_ALGORITHM = 'cross_correlator'
70
71# Since anomalies take time to propagate between two different timeseries,
72# similar irregularities may happen close in time but not exactly at the same point in time.
73# To take this into account, when correlates, we allow a "shift room".
74DEFAULT_ALLOWED_SHIFT_SECONDS = 60
75
76# The threshold above which is considered "correlated".
77DEFAULT_CORRELATE_THRESHOLD = 0.7
78
79# The impact of shift on shifted correlation coefficient.
80DEFAULT_SHIFT_IMPACT = 0.05
81
82TIMESTAMP_STR_FORMATS = [
83    '%Y%m%d_%H:%M:%S',
84    '%Y-%m-%d %H:%M:%S.%f',
85    '%Y%m%d %H:%M:%S',
86    '%Y-%m-%d_%H:%M:%S',
87    '%Y-%m-%dT%H:%M:%S.%f',
88    '%H:%M:%S.%f',
89    '%Y-%m-%dT%H:%M:%S.%f%z',
90    '%Y%m%dT%H:%M:%S',
91    '%Y-%m-%d_%H:%M:%S.%f',
92    '%Y%m%d_%H:%M:%S.%f',
93    '%Y-%m-%dT%H:%M:%S',
94    '%Y-%m-%d %H:%M:%S',
95    '%Y%m%dT%H:%M:%S.%f',
96    '%H:%M:%S',
97    '%Y%m%d %H:%M:%S.%f']
98