Ejemplo n.º 1
0
 def test_create_table(self):
     """
     测试创建表
     :return:
     """
     # 创建表之前确定表不存在
     self.assertEqual(False, query_table(self.db, self.table_name))
     # 创建表操作
     create_table(self.db, self.np_array[0], self.np_array[1, 0])
     # 创建表之后确定表已经存在
     self.assertEqual(True, query_table(self.db, self.table_name))
Ejemplo n.º 2
0
 def test_drop_table(self):
     """
     测试删除表
     :return:
     """
     # 创建表操作
     create_table(self.db, self.np_array[0], self.np_array[1, 0])
     # 创建表后能查到表的存在
     self.assertEqual(True, query_table(self.db, self.table_name))
     # 删除表
     drop_table(self.db, self.table_name)
     # 删除表后查不到表
     self.assertEqual(False, query_table(self.db, self.table_name))
Ejemplo n.º 3
0
def save_datas_with_labels(file_name, abnormal_rate):
    """
    存储已经由孤立森林学习过的带有标签的数据
    :return:True or False
    """
    cases = load_csv(file_name)
    # file_name是文件路径名
    print("file name", file_name)
    # 文件名
    title = file_name.split("/")[-1]
    print(type(title), title)
    isolate1 = Isolate('isolate', cases, rate=abnormal_rate)
    np_array = isolate1.merge_arrays()
    table_name = np_array[1, 0]
    db = connectdb()
    if not query_table(db, table_name):
        create_table(db, np_array[0], table_name)
    # 插入数据,表名为uuid
    if insert_train_datas(db, table_name, np_array[1:]):
        # 数据集列表存储表名(redis存储),断电就清空
        redis_conn = get_redis_connection("default")
        redis_conn.sadd('data_set_name', title)
        # sv.data_set.append(title)
        # 存储数据集表名(磁盘存储),断电可恢复
        save_dataset_name_to_file(title)
        # 存储文件与UUID对应关系到file2uuid表中
        insert_file2uuid(title, table_name)
        return True
    return False
Ejemplo n.º 4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2019/1/11 17:52
# @Author  : zsj
# @File    : xgb_func_test.py
# @Description:
from db.mysql_operation import insert_train_datas, connectdb, query_table, create_table
from isolate_model.base_function import load_csv, translate_to_xgboost_datas, save_xgboost_class, load_xgboost_class
from isolate_model.isolate_class import Isolate
from xgboost_model.xgboost_class import XGBoost

cases = load_csv("../file/customs_cpu_test.csv")
isolate1 = Isolate('2_7', cases)
np_array = isolate1.merge_arrays()
table_name = np_array[1, 0]
db = connectdb()
if not query_table(db, table_name):
    create_table(db, np_array[0], table_name)

insert_train_datas(db, table_name, np_array[1:])

xgb1 = XGBoost(table_name)
print(xgb1.name)
save_xgboost_class(xgb1)
pre = load_xgboost_class("982c78b5-435a-40b3-9a31-9fb5fbf8b16")
print(pre.precision, pre.recall, pre.lasted_update)
Ejemplo n.º 5
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2019/1/5 17:45
# @Author  : zsj
# @File    : db_test.py
# @Description:
from db.mysql_operation import connectdb, create_table, query_table, query_datas, update_datas, delete_datas, \
    drop_table, insert_train_datas, closedb
from isolate_model.base_function import load_csv
from isolate_model.isolate_class import Isolate

cases = load_csv("../file/customs_msmq_test.csv")
isolate1 = Isolate('2_7', cases)
np_array = isolate1.merge_arrays()

db = connectdb()
table_name = np_array[1, 0]
# 判断是否存在该表
is_exists = query_table(db, table_name)
# 如果不存在则创建该表
if not is_exists:
    create_table(db, np_array[0], table_name)
# 插入数据
insert_train_datas(db, table_name, np_array[1:])
result = query_datas(db, table_name)
print(len(result))