Ejemplo n.º 1
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.º 2
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.º 3
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()