diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..3f322e3
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..49d2040
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,562 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 18
+ 180
+ delete
+
+
+ E:\Metis\app
+ E:\Metis\app\dao
+ E:\Metis\app\service
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1541053168778
+
+
+ 1541053168778
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/config/common.py b/app/config/common.py
index c8dc035..4562ea6 100644
--- a/app/config/common.py
+++ b/app/config/common.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
@@ -13,6 +14,6 @@ INPUT_LEN_CH_MAX = 64
INPUT_ITEM_PER_PAGE_MAX = 100
INPUT_LIST_LEN_MAX = 5
VALUE_LEN_MAX = 50000
-UPLOAD_PATH = '/tmp/tmpfile_%s.csv'
+UPLOAD_FILE = '/tmp/tmpfile_%s.csv'
MARK_POSITIVE = 1
MARK_NEGATIVE = 2
diff --git a/app/config/database.py b/app/config/database.py
index 3e96f1e..8de3ee8 100644
--- a/app/config/database.py
+++ b/app/config/database.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
@@ -7,8 +8,8 @@ https://opensource.org/licenses/BSD-3-Clause
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
"""
-db = 'metis'
-user = 'metis'
-passwd = 'metis@123'
-host = '127.0.0.1'
-port = 3306
\ No newline at end of file
+DB = 'metis'
+USER = 'metis'
+PASSWD = 'metis@123'
+HOST = '127.0.0.1'
+PORT = 3306
\ No newline at end of file
diff --git a/app/config/errorcode.py b/app/config/errorcode.py
index fc047f1..b1c312b 100644
--- a/app/config/errorcode.py
+++ b/app/config/errorcode.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
@@ -20,15 +21,15 @@ TRAIN_ERR = 2003
LACK_SAMPLE = 2004
ERR_CODE = {
- 0: "操作成功",
- 1000: "抛出异常",
- 1001: "数据库操作失败",
- 1002: "参数检查失败",
- 1003: "文件格式有误",
- 1004: "非post请求",
- 1005: "非get请求",
- 2001: "特征计算出错",
- 2002: "读取特征数据失败",
- 2003: "训练出错",
- 2004: "缺少正样本或负样本"
+ OP_SUCCESS: "操作成功",
+ THROW_EXP: "抛出异常",
+ OP_DB_FAILED: "数据库操作失败",
+ CHECK_PARAM_FAILED: "参数检查失败",
+ FILE_FORMAT_ERR: "文件格式有误",
+ NOT_POST: "非post请求",
+ NOT_GET: "非get请求",
+ CAL_FEATURE_ERR: "特征计算出错",
+ READ_FEATURE_FAILED: "读取特征数据失败",
+ TRAIN_ERR: "训练出错",
+ LACK_SAMPLE: "缺少正样本或负样本"
}
\ No newline at end of file
diff --git a/app/controller/api/views.py b/app/controller/api/views.py
index d27c87f..0e4aee4 100644
--- a/app/controller/api/views.py
+++ b/app/controller/api/views.py
@@ -23,7 +23,7 @@ def check_post(func):
return render_json(return_dict)
return f
-
+
@check_post
def search_anomaly(request):
anomaly_service = AnomalyService()
diff --git a/app/controller/manage.py b/app/controller/manage.py
index 14c5d38..c72e868 100644
--- a/app/controller/manage.py
+++ b/app/controller/manage.py
@@ -1,30 +1,9 @@
#!/usr/bin/env python
import os
import sys
-import signal
-import errno
-
-
-def wait_child(signum, frame):
- print('receive SIGCHLD')
- try:
- while True:
- cpid, status = os.waitpid(-1, os.WNOHANG)
- if cpid == 0:
- print('no child process was immediately available')
- break
- exitcode = status >> 8
- print('child process %s exit with exitcode %s', cpid, exitcode)
- except OSError as e:
- if e.errno == errno.ECHILD:
- print ('current process has no existing unwaited-for child processes.')
- else:
- raise
- print('handle SIGCHLD end')
if __name__ == "__main__":
- signal.signal(signal.SIGCHLD, wait_child)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")
try:
from django.core.management import execute_from_command_line
diff --git a/app/dao/time_series_detector/anomaly_op.py b/app/dao/time_series_detector/anomaly_op.py
index e702442..1facf0c 100644
--- a/app/dao/time_series_detector/anomaly_op.py
+++ b/app/dao/time_series_detector/anomaly_op.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
@@ -19,7 +20,7 @@ from app.config.errorcode import *
class AbnormalOperation(object):
def __init__(self):
- self.__conn = MySQLdb.connect(host=database.host, port=database.port, user=database.user, passwd=database.passwd, db=database.db)
+ self.__conn = MySQLdb.connect(host=database.HOST, port=database.PORT, user=database.USER, passwd=database.PASSWD, db=database.DB)
self.__cur = self.__conn.cursor()
self.__cur.execute("SET NAMES UTF8")
self.__sample = SampleOperation()
diff --git a/app/dao/time_series_detector/sample_op.py b/app/dao/time_series_detector/sample_op.py
index 37ae8f2..ad9afd1 100644
--- a/app/dao/time_series_detector/sample_op.py
+++ b/app/dao/time_series_detector/sample_op.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
@@ -20,7 +21,7 @@ from app.config.errorcode import *
class SampleOperation(object):
def __init__(self):
- self.__conn = MySQLdb.connect(host=database.host, port=database.port, user=database.user, passwd=database.passwd, db=database.db)
+ self.__conn = MySQLdb.connect(host=database.HOST, port=database.PORT, user=database.USER, passwd=database.PASSWD, db=database.DB)
self.__cur = self.__conn.cursor()
self.__cur.execute("SET NAMES UTF8")
@@ -179,7 +180,7 @@ class SampleOperation(object):
])
head = ['指标集名称', '指标集id', '指标名称', '指标id', '样本来源', '训练集_测试集', '正样本_负样本', '样本窗口', 'dataC', 'dataB', 'dataA', '数据时间戳']
uuid_str = uuid.uuid4().hex[:8]
- download_file_path = UPLOAD_PATH % uuid_str
+ download_file_path = UPLOAD_FILE % uuid_str
with open(download_file_path, 'w') as pfile:
pfile.write(codecs.BOM_UTF8)
writer = csv.writer(pfile)
@@ -261,7 +262,7 @@ class SampleOperation(object):
command = "delete from sample_dataset where id = %s "
num = self.__cur.execute(command, id_num)
self.__conn.commit()
- return OP_SUCCESS, {"count":num}
+ return OP_SUCCESS, {"count": num}
def delete_sample_by_anomaly_id(self, data):
id_num = data['id']
diff --git a/app/dao/time_series_detector/train_op.py b/app/dao/time_series_detector/train_op.py
index e4d0fa1..527adc1 100644
--- a/app/dao/time_series_detector/train_op.py
+++ b/app/dao/time_series_detector/train_op.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
@@ -16,7 +17,7 @@ from app.config.errorcode import *
class TrainOperation(object):
def __init__(self):
- self.__conn = MySQLdb.connect(host=database.host, port=database.port, user=database.user, passwd=database.passwd, db=database.db)
+ self.__conn = MySQLdb.connect(host=database.HOST, port=database.PORT, user=database.USER, passwd=database.PASSWD, db=database.DB)
self.__cur = self.__conn.cursor()
self.__cur.execute("SET NAMES UTF8")
diff --git a/app/service/time_series_detector/algorithm/ewma_and_polynomial.py b/app/service/time_series_detector/algorithm/ewma_and_polynomial.py
index 4b89755..1d35dbd 100644
--- a/app/service/time_series_detector/algorithm/ewma_and_polynomial.py
+++ b/app/service/time_series_detector/algorithm/ewma_and_polynomial.py
@@ -10,6 +10,7 @@ Unless required by applicable law or agreed to in writing, software distributed
from app.service.time_series_detector.algorithm import ewma
from app.service.time_series_detector.algorithm import polynomial_interpolation
+from app.config.common import *
class EwmaAndPolynomialInterpolation(object):
@@ -26,7 +27,7 @@ class EwmaAndPolynomialInterpolation(object):
self.degree = degree
self.threshold = threshold
- def predict(self, X, window=180):
+ def predict(self, X, window=DEFAULT_WINDOW):
"""
Predict if a particular sample is an outlier or not.
diff --git a/app/service/time_series_detector/algorithm/gbdt.py b/app/service/time_series_detector/algorithm/gbdt.py
index 7a20365..7675084 100644
--- a/app/service/time_series_detector/algorithm/gbdt.py
+++ b/app/service/time_series_detector/algorithm/gbdt.py
@@ -16,6 +16,8 @@ from sklearn.externals import joblib
from app.service.time_series_detector.feature import feature_service
from app.utils.utils import *
from app.config.errorcode import *
+from app.config.common import *
+
MODEL_PATH = os.path.join(os.path.dirname(__file__), '../../../model/time_series_detector/')
DEFAULT_MODEL = MODEL_PATH + "gbdt_default_model"
@@ -43,7 +45,7 @@ class Gbdt(object):
self.max_depth = max_depth
self.learning_rate = learning_rate
- def __calculate_features(self, data, window=180):
+ def __calculate_features(self, data, window=DEFAULT_WINDOW):
"""
Caculate time features.
@@ -59,7 +61,7 @@ class Gbdt(object):
features.append(temp)
return features
- def gbdt_train(self, data, task_id, window=180):
+ def gbdt_train(self, data, task_id, window=DEFAULT_WINDOW):
"""
Train a gbdt model.
@@ -86,7 +88,7 @@ class Gbdt(object):
return TRAIN_ERR, str(ex)
return OP_SUCCESS, ""
- def predict(self, X, window=180, model_name=DEFAULT_MODEL):
+ def predict(self, X, window=DEFAULT_WINDOW, model_name=DEFAULT_MODEL):
"""
Predict if a particular sample is an outlier or not.
diff --git a/app/service/time_series_detector/algorithm/isolation_forest.py b/app/service/time_series_detector/algorithm/isolation_forest.py
index 3094cc8..9aff256 100644
--- a/app/service/time_series_detector/algorithm/isolation_forest.py
+++ b/app/service/time_series_detector/algorithm/isolation_forest.py
@@ -9,6 +9,7 @@ Unless required by applicable law or agreed to in writing, software distributed
"""
from sklearn.ensemble import IsolationForest
+from app.config.common import *
class IForest(object):
@@ -48,7 +49,7 @@ class IForest(object):
self.random_state = random_state
self.verbose = verbose
- def predict(self, X, window=180):
+ def predict(self, X, window=DEFAULT_WINDOW):
"""
Predict if a particular sample is an outlier or not.
diff --git a/app/service/time_series_detector/algorithm/polynomial_interpolation.py b/app/service/time_series_detector/algorithm/polynomial_interpolation.py
index 2ac4ca2..5efdd3d 100644
--- a/app/service/time_series_detector/algorithm/polynomial_interpolation.py
+++ b/app/service/time_series_detector/algorithm/polynomial_interpolation.py
@@ -12,6 +12,7 @@ import numpy as np
from sklearn.linear_model import Ridge
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
+from app.config.common import *
class PolynomialInterpolation(object):
@@ -30,7 +31,7 @@ class PolynomialInterpolation(object):
self.degree = degree
self.threshold = threshold
- def predict(self, X, window=180):
+ def predict(self, X, window=DEFAULT_WINDOW):
"""
Predict if a particular sample is an outlier or not.
diff --git a/app/service/time_series_detector/algorithm/xgboosting.py b/app/service/time_series_detector/algorithm/xgboosting.py
index 3b956c9..72f5a86 100644
--- a/app/service/time_series_detector/algorithm/xgboosting.py
+++ b/app/service/time_series_detector/algorithm/xgboosting.py
@@ -13,6 +13,7 @@ import xgboost as xgb
from app.service.time_series_detector.feature import feature_service
from app.utils.utils import *
from app.config.errorcode import *
+from app.config.common import *
MODEL_PATH = os.path.join(os.path.dirname(__file__), '../../../model/time_series_detector/')
DEFAULT_MODEL = MODEL_PATH + "xgb_default_model"
@@ -87,7 +88,7 @@ class XGBoosting(object):
times = times + 1
return OP_SUCCESS, ""
- def __calculate_features(self, data, feature_file_name, window=180):
+ def __calculate_features(self, data, feature_file_name, window=DEFAULT_WINDOW):
"""
Caculate time features and save as libsvm format.
@@ -145,7 +146,7 @@ class XGBoosting(object):
return TRAIN_ERR, str(ex)
return OP_SUCCESS, ""
- def predict(self, X, window=180, model_name=DEFAULT_MODEL):
+ def predict(self, X, window=DEFAULT_WINDOW, model_name=DEFAULT_MODEL):
"""
:param X: the time series to detect of
:type X: pandas.Series
diff --git a/app/service/time_series_detector/anomaly_service.py b/app/service/time_series_detector/anomaly_service.py
index 0da693c..8e170fd 100644
--- a/app/service/time_series_detector/anomaly_service.py
+++ b/app/service/time_series_detector/anomaly_service.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
diff --git a/app/service/time_series_detector/detect_service.py b/app/service/time_series_detector/detect_service.py
index be67b51..7252f8e 100644
--- a/app/service/time_series_detector/detect_service.py
+++ b/app/service/time_series_detector/detect_service.py
@@ -17,6 +17,7 @@ from app.dao.time_series_detector import train_op
from app.utils.utils import *
from app.service.time_series_detector.algorithm import isolation_forest, ewma, polynomial_interpolation, statistic, xgboosting
from app.config.errorcode import *
+from app.config.common import *
MODEL_PATH = os.path.join(os.path.dirname(__file__), '../../model/time_series_detector/')
@@ -139,7 +140,7 @@ class DetectService(object):
if "window" in data:
window = data["window"]
else:
- window = 180
+ window = DEFAULT_WINDOW
if len(data['dataC'].split(',')) != (2 * window + 1):
return CHECK_PARAM_FAILED, "dataC is not long enough"
if len(data['dataB'].split(',')) != (2 * window + 1):
@@ -166,7 +167,7 @@ class DetectService(object):
if "window" in data:
window = data["window"]
else:
- window = 180
+ window = DEFAULT_WINDOW
statistic_result = self.statistic_obj.predict(time_series)
ewma_result = self.ewma_obj.predict(time_series)
polynomial_result = self.polynomial_obj.predict(time_series, window)
diff --git a/app/service/time_series_detector/feature/classification_features.py b/app/service/time_series_detector/feature/classification_features.py
index e7ddf5b..6d53dab 100644
--- a/app/service/time_series_detector/feature/classification_features.py
+++ b/app/service/time_series_detector/feature/classification_features.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
diff --git a/app/service/time_series_detector/feature/feature_service.py b/app/service/time_series_detector/feature/feature_service.py
index 22f22dc..ed0b04f 100644
--- a/app/service/time_series_detector/feature/feature_service.py
+++ b/app/service/time_series_detector/feature/feature_service.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
diff --git a/app/service/time_series_detector/feature/fitting_features.py b/app/service/time_series_detector/feature/fitting_features.py
index 5a96ebf..55dee90 100644
--- a/app/service/time_series_detector/feature/fitting_features.py
+++ b/app/service/time_series_detector/feature/fitting_features.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
@@ -9,8 +9,9 @@ Unless required by applicable law or agreed to in writing, software distributed
"""
import numpy as np
+from app.config.common import *
-
+`
def time_series_moving_average(x):
"""
Returns the difference between the last element of x and the smoothed value after Moving Average Algorithm
@@ -25,7 +26,7 @@ def time_series_moving_average(x):
:return type: list with float
"""
temp_list = []
- for w in range(1, 50, 5):
+ for w in range(1, min(50, DEFAULT_WINDOW), 5):
temp = np.mean(x[-w:])
temp_list.append(temp)
return list(np.array(temp_list) - x[-1])
@@ -45,7 +46,7 @@ def time_series_weighted_moving_average(x):
:return type: list with float
"""
temp_list = []
- for w in range(1, 50, 5):
+ for w in range(1, min(50, DEFAULT_WINDOW), 5):
w = min(len(x), w) # avoid the case len(value_list) < w
coefficient = np.array(range(1, w + 1))
temp_list.append((np.dot(coefficient, x[-w:])) / (w * (w + 1) / 2))
@@ -167,7 +168,7 @@ def time_series_periodic_features(data_c_left, data_c_right, data_b_left, data_b
Others are similar.
'''
- for w in range(1, 180, 30):
+ for w in range(1, DEFAULT_WINDOW, DEFAULT_WINDOW / 6):
periodic_features.append(min(max(data_c_left[-w:]) - data_a[-1], 0))
periodic_features.append(min(max(data_c_right[:w]) - data_a[-1], 0))
periodic_features.append(min(max(data_b_left[-w:]) - data_a[-1], 0))
@@ -181,7 +182,7 @@ def time_series_periodic_features(data_c_left, data_c_right, data_b_left, data_b
Add the difference of mean values between two subsequences
'''
- for w in range(1, 180, 20):
+ for w in range(1, DEFAULT_WINDOW, DEFAULT_WINDOW / 9):
temp_value = np.mean(data_c_left[-w:]) - np.mean(data_a[-w:])
periodic_features.append(abs(temp_value))
if temp_value < 0:
diff --git a/app/service/time_series_detector/feature/statistical_features.py b/app/service/time_series_detector/feature/statistical_features.py
index 9ec4d3c..c62b9c4 100644
--- a/app/service/time_series_detector/feature/statistical_features.py
+++ b/app/service/time_series_detector/feature/statistical_features.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
diff --git a/app/service/time_series_detector/sample_service.py b/app/service/time_series_detector/sample_service.py
index 5668ff4..e2f3a14 100644
--- a/app/service/time_series_detector/sample_service.py
+++ b/app/service/time_series_detector/sample_service.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
@@ -22,7 +22,7 @@ class SampleService(object):
def __init__(self):
self.__sample = SampleOperation()
uuid_str = uuid.uuid4().hex[:8]
- self.__upload_file_path = UPLOAD_PATH % uuid_str
+ self.__upload_file_path = UPLOAD_FILE % uuid_str
@exce_service
def import_sample(self, data):
@@ -82,7 +82,7 @@ class SampleService(object):
return self.__sample.query_sample(json.loads(body))
def sample_download(self, body):
- ret_code = 1000
+ ret_code = THROW_EXP
try:
if len(body) > VALUE_LEN_MAX:
return ""
diff --git a/app/service/time_series_detector/task_service.py b/app/service/time_series_detector/task_service.py
index dadb3a8..73e1cc5 100644
--- a/app/service/time_series_detector/task_service.py
+++ b/app/service/time_series_detector/task_service.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
diff --git a/app/utils/utils.py b/app/utils/utils.py
index c95771d..e9903cc 100644
--- a/app/utils/utils.py
+++ b/app/utils/utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Tencent is pleased to support the open source community by making Metis available.
@@ -10,13 +10,12 @@ Unless required by applicable law or agreed to in writing, software distributed
import numpy as np
import traceback
-import json
from functools import wraps
from app.config.errorcode import *
from app.config.common import *
-def is_standard_time_series(time_series, window=180):
+def is_standard_time_series(time_series, window=DEFAULT_WINDOW):
"""
Check the length of time_series. If window = 180, then the length of time_series should be 903.
The mean value of last window should be larger than 0.
@@ -30,7 +29,7 @@ def is_standard_time_series(time_series, window=180):
return bool(len(time_series) == 5 * window + 3 and np.mean(time_series[(4 * window + 2):]) > 0)
-def split_time_series(time_series, window=180):
+def split_time_series(time_series, window=DEFAULT_WINDOW):
"""
Spilt the time_series into five parts. Each has a length of window + 1
diff --git a/docker/start.sh b/docker/start.sh
index 00155dc..7aead95 100644
--- a/docker/start.sh
+++ b/docker/start.sh
@@ -1,7 +1,8 @@
+#!/bin/bash
if [ $# == 0 ]
then
- echo "Need at least 1 argument!"
- exit
+ echo "Usage:$0 "
+ exit 1
fi
ip=$1
@@ -9,7 +10,7 @@ docker rm -f metis-db
docker rm -f metis-svr
docker rm -f metis-web
-docker run --net=host --name=metis-db -i -t -d -p 3306:3306 -v /data/metis/mysql/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=metis@123 zhiyunmetis/metis-db
+docker run --net=host --name=metis-db -d -p 3306:3306 -v /data/metis/mysql/:/var/lib/mysql:Z -e MYSQL_ROOT_PASSWORD=metis@123 zhiyunmetis/metis-db
sleep 6
-docker run --net=host --name=metis-svr -i -t -d -p 8080:8080 -v /data/metis/module/:/metis/app/model/time_series_detector zhiyunmetis/metis-svr /bin/sh /metis/init.sh
-docker run --net=host --name=metis-web -i -t -d -p 80:80 zhiyunmetis/metis-web /bin/sh /metis/init.sh ${ip}
+docker run --net=host --name=metis-svr -d -p 8080:8080 -v /data/metis/module/:/metis/app/model/time_series_detector:Z zhiyunmetis/metis-svr /bin/sh /metis/init.sh
+docker run --net=host --name=metis-web -d -p 80:80 zhiyunmetis/metis-web /bin/sh /metis/init.sh ${ip}
\ No newline at end of file