Ejemplo n.º 1
0
class MyHttpHandler(BaseHTTPRequestHandler):
    def __init__(self):
        # 连接数据库
        self.conn = ConnectMysql()
        # 如果表不存在则创建表
        self.conn.create_table()

    def do_POST(self):
        length = int(self.headers['Content-Length'])
        readdata = self.rfile.read(length).decode('utf-8')
        post_data = json.loads(readdata)
        cur_thread = threading.current_thread()
        # 解析post信息
        # print(cur_thread.name)
        # print(post_data)
        # post_num ==
        #
        #
        #
        if post_num == 0:  # 原始数据输入
            #单行指纹输入,输入信息都应来自于post数据
            flag = self.conn.insert_data(model, addr, phoneIP, 1, strx, stry,
                                         direction, line_time, mac, ap)
            if flag == -1:
                data = json.dumps({'result': 'false'})
            else:
                data = json.dumps({'result': 'true'})
        elif post_num == 1:  # 请求指纹更新结果
            g = GuiContent()
            # 数据处理
            # 此部分可以预先进行,只要在所有原始数据都保存完成后,
            # 放在此处的话每次调用都是产生的重复数据
            # 可能需要传入地址信息
            g.data_process(ap_mac, x, y)
            # 指纹更新
            # 第二个参数为增量训练的模型位置
            ap_m = g.fingerprint_update(ap_mac, 10, x, y)
            data = json.dumps({'result': ap_m})
        else:
            data = json.dumps({'result': {'###'}})
        #
        #
        #

        enc = "UTF-8"
        encoded = ''.join(data).encode(enc)
        f = io.BytesIO()
        f.write(encoded)
        f.seek(0)
        self.send_response(200)
        self.send_header("Content-type", "text/html; charset=%s" % enc)
        self.send_header("Content-Length", str(len(encoded)))
        self.end_headers()
        shutil.copyfileobj(f, self.wfile)
Ejemplo n.º 2
0
class SaveData:
    def __init__(self):
        # 连接数据库
        self.conn = ConnectMysql()
        # 如果表不存在则创建表
        self.conn.create_table()

    # 完整数据保存
    def data_save(self, path, file, phone_model):
        with open(path + file, 'r') as file_read:
            file_a = file.split('.')
            file_b = file_a[0].split('-')
            addr = "C204"
            phoneIP = phone_model
            model = file_b[0]
            coordinate = file_b[1]  # 注意x,y的先后
            strx = coordinate[len(coordinate) - 1]
            stry = coordinate[0:(len(coordinate) - 1)]
            direction = file_b[2]
            line_datas = []
            while True:
                lines = file_read.readline()  # 读取整行数据
                if not lines:
                    break
                line_datas.append(lines.split())
            if int(model) == 0:  # 模型0为底图采集,只保存中间三分之一数据
                one = int(len(line_datas) / 3)
                line_datas = line_datas[one:one * 2]
            for line_data in line_datas:
                line_time = line_data.pop(0)
                line_time = line_time + " " + line_data.pop(0)
                mac = []
                ap = []
                if line_data:
                    for x in range(0, len(line_data), 2):
                        mac.append(line_data[x])
                        ap.append(line_data[x + 1])
                flag = self.conn.insert_data(model, addr, phoneIP, 1, strx,
                                             stry, direction, line_time, mac,
                                             ap)
                if flag == -1:
                    return line_time
        return 1

    # 读取数据
    def data_read(self):
        data = self.conn.select_data()
        return data

    #关闭连接
    def close_connect(self):
        self.conn.close_conn()
Ejemplo n.º 3
0
class DataProcess:
    def __init__(self):
        # 连接数据库
        self.conn = ConnectMysql()
        # 如果表不存在则创建表
        self.conn.create_table()

    # 数据处理
    def process_data(self,ap_mac,model_num,c_x,c_y):
        ap_m = self.conn.select_data(ap_mac,model_num,c_x,c_y)
        # c204底图数据额外处理
        if model_num == 0:
            for t in range(len(ap_mac)):
                for x in range(c_x):
                    for y in range(c_y):
                        if x == 0 or x == 1 or x == 9 or y == 0 or y == 12:
                            pass
                        elif ap_m[t][x][y] != -1:
                            pass
                        elif (x % 2) == 1 and (y % 2) == 1:
                            ap_m[t][x][y] = int((ap_m[t][x-1][y]+ap_m[t][x+1][y])/2)
                        elif (x % 2) == 1 and (y % 2) == 0:
                            ap_m[t][x][y] = int((ap_m[t][x-1][y-1]+ap_m[t][x-1][y+1]+ap_m[t][x+1][y-1]+ap_m[t][x+1][y+1])/4)
                        else:
                            ap_m[t][x][y] = int((ap_m[t][x][y-1]+ap_m[t][x][y+1])/2)
        return ap_m

    # 指纹库保存到数据库中
    # update_num:更新次数,原数据更新次数为0,每次更新后更新次数加一并保存
    def save_data(self,model_num,update_num,ap_mac,ap_m):
        addr = "c204"
        signal_type = 1
        flag = self.conn.insert_fingerprint_data(model_num,update_num,addr,signal_type,ap_mac,ap_m)
        return flag

    # 获取指定指纹库
    def get_data(self,model_num,update_num,signal_mac_address,c_x,c_y):
        results = self.conn.select_fingerprint_data(model_num,update_num,signal_mac_address)        
        mid_data = []
        for i in range(c_x):
            mid_data.append([])
            for j in range(c_y):
                mid_data[i].append(-1)
        for r in results:
            mid_data[r[0]][r[1]] = r[2]
        return mid_data

    
    #关闭连接
    def close_connect(self):
        self.conn.close_conn()
Ejemplo n.º 4
0
class DataProcess:
    def __init__(self):
        # 连接数据库
        self.conn = ConnectMysql()
        # 如果表不存在则创建表
        self.conn.create_table()

    # 数据提取,预处理,保存指纹库
    # 
    def process_data(self,address,begin_time,end_time):
        ap_m = self.conn.select_data(address,begin_time,end_time)
        # 底图处理
        if end_time == global_begin_time: 
            #***与上一次底图进行比较,更新ap_mac(包含其中的无效化值)
        # 历史数据匹配
        else:
            #**历史数据匹配
            #
            match = Matching("信号类型0或1")
            # 匹配历史数据的时间范围
            match.history_division("开始时间", "结束时间")
            # 匹配的结果
            aps,result = match.match.history_matching(begin_time,end_time)
            #**两部分数据整合:ap_m和result
        return ap_m

    # 指纹库保存到数据库中
    # model_num模型序号,初始为0,每次底图采集递加1
    # update_num:更新次数,原数据更新次数为0,每次更新后更新次数加一并保存
    def save_data(self,attr,model_num,update_num,ap_mac,ap_m):
        signal_type = 1
        flag = self.conn.insert_fingerprint_data(model_num,update_num,addr,signal_type,ap_mac,ap_m)
        return flag

    # 获取指定指纹库
    # 
    def get_data(self,model_num,update_num,signal_mac_address,c_x,c_y):
        results = self.conn.select_fingerprint_data(model_num,update_num,signal_mac_address)        
        mid_data = []
        for i in range(c_x):
            mid_data.append([])
            for j in range(c_y):
                mid_data[i].append(-1)
        for r in results:
            mid_data[r[0]][r[1]] = r[2]
        return mid_data

    
    #关闭连接
    def close_connect(self):
        self.conn.close_conn()
Ejemplo n.º 5
0
class MyHttpHandler(BaseHTTPRequestHandler):
    def __init__(self):
        # 连接数据库
        self.conn = ConnectMysql()
        # 如果表不存在则创建表
        self.conn.create_table()

    def do_POST(self):
        length = int(self.headers['Content-Length'])
        readdata = self.rfile.read(length).decode('utf-8')
        post_data = json.loads(readdata)
        cur_thread = threading.current_thread()
        # 解析post信息
        # print(cur_thread.name)
        # print(post_data)
        # post_num ==
        #
        #
        #
        if post_num == 0:  # 原始数据输入
            #单行指纹输入,输入信息都应来自于post数据
            flag = self.conn.insert_data(addr, signal_type, strx, stry,
                                         line_time, uploading_device, ap_mac,
                                         ap_name, ap_value)
            if flag == -1:
                data = json.dumps({'result': 'false'})
            else:
                data = json.dumps({'result': 'true'})
        elif post_num == 1:  # 请求指纹更新结果
            # ap_m = 从指纹数据库获取最新指纹库并进行格式整理
            data = json.dumps({'result': ap_m})
        else:
            data = json.dumps({'result': {'错误请求'}})
        #
        #
        #

        enc = "UTF-8"
        encoded = ''.join(data).encode(enc)
        f = io.BytesIO()
        f.write(encoded)
        f.seek(0)
        self.send_response(200)
        self.send_header("Content-type", "text/html; charset=%s" % enc)
        self.send_header("Content-Length", str(len(encoded)))
        self.end_headers()
        shutil.copyfileobj(f, self.wfile)
Ejemplo n.º 6
0
class SaveData:
    def __init__(self):
        # 连接数据库
        self.conn = ConnectMysql()
        # 如果表不存在则创建表
        self.conn.create_table()

    # 完整数据保存
    def data_save(self, path, type_t, addr, coo_x, coo_y, room_device):
        if os.path.getsize(path):  #判断文件是否为空
            with open(path, 'r') as file_read:
                model = 0
                flag = 1
                line_datas = []
                read = csv.reader(file_read)
                for i in read:
                    line_datas.append(i)
                name = line_datas[0][1:]
                # print(name)
                mac = line_datas[1][1:]
                for x in range(2, len(line_datas)):
                    line_data = line_datas[x]
                    line_timet = line_data.pop(0)
                    line_time = line_timet[:-3]
                    line_time = time.strftime("%y-%m-%d %H:%M:%S",
                                              time.localtime(int(line_time)))
                    ap = line_data
                    flag_ap = -1
                    for a in ap:
                        if int(a) != -200:  # 当一行全部都是无效数据时数据库会报错,因此提前检验一次
                            flag_ap = 1
                    if flag_ap == 1:
                        flag = self.conn.insert_data(model, addr, type_t,
                                                     coo_x, coo_y, line_time,
                                                     mac, name, ap,
                                                     room_device)
                    if flag == -1:
                        return line_timet
        return 1

    #关闭连接
    def close_connect(self):
        self.conn.close_conn()
Ejemplo n.º 7
0
class SaveData:
    def __init__(self):
        # 连接数据库
        self.conn = ConnectMysql()
        # 如果表不存在则创建表
        self.conn.create_table()

    # 完整数据保存
    def complete_data_save(self, path, file):
        with open(path + file, 'r') as file_read:
            file_a = file.split('.')
            file_b = file_a[0].split('-')
            addr = file_b[0]
            strx = file_b[1]  # 注意x,y的先后
            stry = file_b[2]
            phoneIP = strx + ', ' + stry  # ##phoneIP为采集中缺失的参数,暂时用位置和代替
            while True:
                lines = file_read.readline()  # 读取整行数据
                if not lines:
                    break
                line_data = lines.split()
                line_time = line_data.pop(0)
                line_time = line_time + " " + line_data.pop(0)
                mac = []
                ap = []
                if line_data:
                    for x in range(0, len(line_data), 2):
                        mac.append(line_data[x])
                        ap.append(line_data[x + 1])
                flag = self.conn.insert_data(addr, phoneIP, 1, strx, stry,
                                             line_time, mac, ap)
                if flag == -1:
                    return line_time
        return 1

    #底图数据,只保存中间三分之一
    def initial_data_save(self, path, file):
        with open(path + file, 'r') as file_read:
            file_a = file.split('.')
            file_b = file_a[0].split('-')
            addr = file_b[0]
            strx = file_b[1]  # 注意x,y的先后
            stry = file_b[2]
            phoneIP = strx + ', ' + stry  # ##phoneIP为采集中缺失的参数,暂时用位置和代替
            line_datas = []
            while True:
                lines = file_read.readline()  # 读取整行数据
                if not lines:
                    break
                line_datas.append(lines.split())
            one = int(len(line_datas) / 3)
            line_datas = line_datas[one:one * 2]
            for line_data in line_datas:
                line_time = line_data.pop(0)
                line_time = line_time + " " + line_data.pop(0)
                mac = []
                ap = []
                if line_data:
                    for x in range(0, len(line_data), 2):
                        mac.append(line_data[x])
                        ap.append(line_data[x + 1])
                flag = self.conn.insert_data(addr, phoneIP, 1, strx, stry,
                                             line_time, mac, ap)
                if flag == -1:
                    return line_time
        return 1

    def close_connect(self):
        self.conn.close_conn()
Ejemplo n.º 8
0
class SaveData:
    def __init__(self):
        # 连接数据库
        self.conn = ConnectMysql()
        # 如果表不存在则创建表
        self.conn.create_table()

    # 完整数据保存               
    def data_save(self,path,file,phone_model,tt_time): 
        print(path) 
        time_period = tt_time;
        with open(path + file, 'r') as file_read:
            file_a = file.split('.')
            file_b = file_a[0].split('-')
            addr = "C204"
            phoneIP = phone_model
            coordinate = file_b[1] # 注意x,y的先后
            strx = coordinate[len(coordinate) - 1]
            stry = coordinate[0:(len(coordinate) - 1)]
            direction = file_b[2]
            model = file_b[0]
            line_datas = []
            while True:
                lines = file_read.readline() # 读取整行数据
                if not lines:
                    break
                line_datas.append(lines.split())
            line_time_t = []
            for line_data in line_datas:
                line_time_t.append(line_data[0] + " " + line_data[1])
            for time_p in time_period:
                model = time_p[0]
                if time_p[1] in line_time_t and time_p[2] in line_time_t:#数据采集出了比较大的问题,只有部分数据完整,只保存完整的数据
                    print(model+" " +str(1)) 
                    line_datas_t = line_datas[line_time_t.index(time_p[1]):line_time_t.index(time_p[2])]
                    if int(model) == 0: # 模型0为底图采集
                        for line_data in line_datas_t:
                            line_time = line_data.pop(0)
                            line_time = line_time + " " + line_data.pop(0)
                            mac = []
                            ap = []
                            if line_data:
                                for x in range(0,len(line_data),2):
                                    mac.append(line_data[x])
                                    ap.append(line_data[x+1])
                            flag = self.conn.insert_data(model,addr,phoneIP,1,strx,stry,direction,line_time,mac,ap)  
                            if flag == -1:
                                return line_time  
                    else: #其他数据分为四组
                        one = int(len(line_datas_t)/4)
                        for x in range(1,5):
                            o_line_datas = line_datas_t[one*(x-1):one*x]     
                            for line_data in o_line_datas:
                                line_time = line_data.pop(0)
                                line_time = line_time + " " + line_data.pop(0)
                                mac = []
                                ap = []
                                if line_data:
                                    for y in range(0,len(line_data),2):
                                        mac.append(line_data[y])
                                        ap.append(line_data[y+1])
                                flag = self.conn.insert_data(str(x)+""+str(model),addr,phoneIP,1,strx,stry,direction,line_time,mac,ap)  
                                if flag == -1:
                                    return line_time 
        return 1

    # 读取数据
    def data_read(self):
        data = self.conn.read_data()
        return data

    #关闭连接
    def close_connect(self):
        pass
        self.conn.close_conn()