Example #1
0
class NetZobFormatInferTest:
    def __init__(self):
        self.nz = NetZobFormatInfer()
        self.md = ModBusDataTuning()
        self.ftpdata = FTPDataTuning()

    def clsModbus(self):
        datas = self.md.getModDatas()
        dic = set()
        for data in datas:
            item = data[7:8]
            dic.add(item)
        print(len(dic))
        sys.exit()
        self.nz.clsMessages(datas)

    def clsFTP(self):
        datas = self.ftpdata.getTotalData()
        self.nz.clsMessages(datas)

    def clsMix(self):
        Tdatas = []
        Tdatas.extend(self.md.getModDatas())
        Tdatas.extend(self.ftpdata.getTotalData())
        self.nz.clsMessages(Tdatas, 60)
Example #2
0
def TSumFTP():
    ftpdatas = FTPDataTuning()
    totalDatas = ftpdatas.getTotalData()
Example #3
0
class FormatViewTest:
    def __init__(self):
        self.msg = MegSplitLogic()
        self.TGraph = tree_graph('a', 'B')
        self.moddatas = ModBusDataTuning()
        self.ftp = FTPDataTuning()

    def geneDatas(self):
        messages = read_datas('/home/wxw/data/modbusdata', 'single')
        messages = get_puredatas(messages)[0:1000]
        return messages

    def getMixDatas(self):
        MergeDatas = []
        modDatas = self.moddatas.getModDatas()
        ftpDatas = self.ftp.getTotalData()
        MergeDatas.extend(modDatas)
        MergeDatas.extend(ftpDatas)
        return MergeDatas

    def testModData(self):
        datas = self.geneDatas()
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        #borders = self.msg.getFreBorders(vePara, datas)
        borders = self.msg.getOrderBorders(vePara, datas)
        i = 0
        primDatas = []
        print(datas[0])
        while (i < len(datas)):
            primDatas.append(primeData(datas[i], borders[i], i))
            i = i + 1
        tree_builder = treeFormat(primDatas, 20, 0.2)
        # t_result = tree_builder.generateNT()
        t_result = tree_builder.generateSplitNT(5)
        Nodes = []
        Edges = []
        t_result.showTree(0)
        t_result.getGraph(0, Nodes, Edges, [0])
        self.TGraph.graph_buildTwo(
            Nodes, Edges,
            '/home/wxw/paper/researchresult/BinaryFormat/treeshow/Modbus Order 10 20.png'
        )

    def testFTPData(self):
        #datas = self.geneDatas()
        srcDatas, desDatas = FTPDataTuning().tuningHttpByregix()
        datas = []
        datas.extend(srcDatas)
        datas.extend(desDatas)
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        borders = self.msg.getFreBorders(vePara, datas)
        i = 0
        primDatas = []
        print(datas[0])
        while (i < len(datas)):
            primDatas.append(primeData(datas[i], borders[i], i))
            i = i + 1
        tree_builder = treeFormat(primDatas, 20, 0.2)
        t_result = tree_builder.generateNT()
        t_result.depth_traverse()
        for f in t_result.result:
            print("format start")
            for node_i in f:
                print(node_i.loc, node_i.word_type, node_i.value)
                #print(node_i.getNodeData())

    def testFTPDataOne(self):
        # datas = self.geneDatas()
        srcDatas, desDatas = FTPDataTuning().tuningHttpByregix()
        datas = []
        datas.extend(srcDatas)
        datas.extend(desDatas)
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        borders = self.msg.getFreBorders(vePara, datas)
        #borders = self.msg.getOrderBorders(vePara, datas)
        i = 0
        primDatas = []
        print(datas[0])
        while (i < len(datas)):
            primDatas.append(primeData(datas[i], borders[i], i))
            i = i + 1
        tree_builder = treeFormat(primDatas, 10, 0.2)
        #t_result = tree_builder.generateNT()
        t_result = tree_builder.generateSplitNT(5)
        Nodes = []
        Edges = []
        t_result.showTree(0)
        t_result.getGraph(0, Nodes, Edges, [0])
        self.TGraph.graph_buildTwo(
            Nodes, Edges,
            '/home/wxw/paper/researchresult/BinaryFormat/treeshow/Fre 5 20.png'
        )
        #t_result.showTree(0)
        #tree_builder.layyerTree()

    def testMixData(self):
        datas = self.getMixDatas()
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        #borders = self.msg.getFreBorders(vePara, datas)
        borders = self.msg.getOrderBorders(vePara, datas)
        i = 0
        primDatas = []
        print(datas[0])
        while (i < len(datas)):
            primDatas.append(primeData(datas[i], borders[i], i))
            i = i + 1
        tree_builder = treeFormat(primDatas, 10, 0.2)
        # t_result = tree_builder.generateNT()
        t_result = tree_builder.generateSplitNT(5)
        Nodes = []
        Edges = []
        t_result.showTree(0)
        t_result.getGraph(0, Nodes, Edges, [0])
        self.TGraph.graph_buildTwo(
            Nodes, Edges,
            '/home/wxw/paper/researchresult/BinaryFormat/treeshow/Order 5 20 10 MixData.png'
        )

    def testMixTree(self):
        datas = self.getMixDatas()
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        # borders = self.msg.getFreBorders(vePara, datas)
        borders = self.msg.getOrderBorders(vePara, datas)
        i = 0
        primDatas = []
        print(datas[0])
        while (i < len(datas)):
            primDatas.append(primeData(datas[i], borders[i], i))
            i = i + 1
        tree_builder = treeFormat(primDatas, 10, 0.2)
        # t_result = tree_builder.generateNT()
        t_result = tree_builder.generateSplitNT(5)
        print(t_result.transToDictTree())
Example #4
0
class BorderTest:
    def __init__(self):
        self.msgLogic = MegSplitLogic()
        self.modbus = ModBusDataTuning()
        self.md = modbus()
        self.anlzer = base_analyzer()
        self.ftp = FTPDataTuning()
        self.ftpPaser = FTPParser()
        self.cmPaser = ComPaser()
        self.cvt = Converter()
        self.mtool = MessageSplitMeasure()
        self.rds = redis_deal()

    def getModHPfone(self):
        self.msgs = self.modbus.getModDatas()
        #vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'normal', 'T': 0, 'r': 0.3}
        msgs = self.modbus.getModDatas()
        #Inferborders = self.msgLogic.getFreBorders(vePara, msgs)
        #Inferborders = self.msgLogic.getOrderBorders(vePara, msgs)
        #Inferborders = self.msgLogic.getEntryBorders(vePara, msgs)
        Inferborders = self.msgLogic.getMbourders(vePara, msgs)
        rightBorders = [self.md.GetMessageBorder(msg) for msg in self.msgs]
        i = 0
        print(Inferborders[0], rightBorders[0], msgs[0])
        scores = []
        while (i < len(Inferborders)):
            scores.append(self.anlzer.get_f1(Inferborders[i], rightBorders[i]))
            i = i + 1
        print(sum([score[0] for score in scores]) / len(Inferborders))
        print(sum([score[1] for score in scores]) / len(Inferborders))
        print(sum([score[2] for score in scores]) / len(Inferborders))

    def getModfoneMix(self):
        self.msgs = self.modbus.getModDatas()
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        msgs = self.modbus.getModDatas()
        Inferborders = self.msgLogic.getFreBorders(vePara, msgs)
        InferbordersOne = self.msgLogic.getOrderBorders(vePara, msgs)
        #InferbordersOne = self.msgLogic.getEntryBorders(vePara, msgs)
        Inferborders = self.cvt.MergeListGroup(Inferborders, InferbordersOne)
        rightBorders = [self.md.GetMessageBorder(msg) for msg in self.msgs]
        i = 0
        scores = []
        while (i < len(Inferborders)):
            scores.append(self.anlzer.get_f1(Inferborders[i], rightBorders[i]))
            i = i + 1
        print(sum([score[0] for score in scores]) / len(Inferborders))
        print(sum([score[1] for score in scores]) / len(Inferborders))
        print(sum([score[2] for score in scores]) / len(Inferborders))

    def getFtpMixfone(self):
        msgs = self.ftp.getTotalData()
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        msgs = self.ftpPaser.parseMsgs(msgs)
        Inferborders = self.msgLogic.getFreBorders(vePara, msgs)
        InferbordersOne = self.msgLogic.getOrderBorders(vePara, msgs)
        # InferbordersOne = self.msgLogic.getEntryBorders(vePara, msgs)
        Inferborders = self.cvt.MergeListGroup(Inferborders, InferbordersOne)
        rightBorders = msgs
        i = 0
        scores = []
        while (i < len(Inferborders)):
            scores.append(self.anlzer.get_f1(Inferborders[i], rightBorders[i]))
            i = i + 1
        print(sum([score[0] for score in scores]) / len(Inferborders))
        print(sum([score[1] for score in scores]) / len(Inferborders))
        print(sum([score[2] for score in scores]) / len(Inferborders))

    def getHPFtpfone(self):
        msgs = self.ftp.getTotalData()
        #vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'normal', 'T': 0, 'r': 0.3}
        #Inferborders = self.msgLogic.getFreBorders(vePara, msgs)
        Inferborders = self.msgLogic.getOrderBorders(vePara, msgs)
        #Inferborders = self.msgLogic.getEntryBorders(vePara, msgs)
        #Inferborders = self.msgLogic.getMbourders(vePara, msgs)
        #self.rds.insert_to_redis('nowborder', Inferborders)
        #InferbordersOne = self.rds.read_from_redis('nowborder')
        #print(self.mtool.MLs(Inferborders, InferbordersOne))
        rightBorders = self.ftpPaser.parseMsgs(msgs)
        print(Inferborders[0], rightBorders[0], msgs[0])
        i = 0
        scores = []
        while (i < len(Inferborders)):
            scores.append(self.anlzer.get_f1(Inferborders[i], rightBorders[i]))
            i = i + 1
        print(sum([score[0] for score in scores]) / len(Inferborders))
        print(sum([score[1] for score in scores]) / len(Inferborders))
        print(sum([score[2] for score in scores]) / len(Inferborders))

    def getMixFone(self):
        mixMsgs = []
        ftpData = self.ftp.getTotalData()
        modData = self.modbus.getModDatas()
        mixMsgs.extend(ftpData)
        mixMsgs.extend(modData)
        #vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'normal', 'T': 0, 'r': 0.3}
        #Inferborders = self.msgLogic.getFreBorders(vePara, mixMsgs)
        Inferborders = self.msgLogic.getOrderBorders(vePara, mixMsgs)
        #Inferborders = self.msgLogic.getEntryBorders(vePara, mixMsgs)
        #Inferborders = self.msgLogic.getMbourders(vePara, mixMsgs)
        rightBorders = self.cmPaser.parseMsgs(mixMsgs)
        print(Inferborders[0], rightBorders[0], str(mixMsgs[0]))
        print(Inferborders[-1], rightBorders[-1], str(mixMsgs[-1]))
        i = 0
        scores = []
        while (i < len(Inferborders)):
            scores.append(self.anlzer.get_f1(Inferborders[i], rightBorders[i]))
            i = i + 1
        print(sum([score[0] for score in scores]) / len(Inferborders))
        print(sum([score[1] for score in scores]) / len(Inferborders))
        print(sum([score[2] for score in scores]) / len(Inferborders))

    def getMixFoneScores(self, vePara, parserType):
        mixMsgs = []
        ftpData = self.ftp.getTotalData()
        modData = self.modbus.getModDatas()
        mixMsgs.extend(ftpData)
        mixMsgs.extend(modData)
        Inferborders = None
        if parserType == 'HP':
            Inferborders = self.msgLogic.getFreBorders(vePara, mixMsgs)
        elif parserType == 'HE':
            Inferborders = self.msgLogic.getEntryBorders(vePara, mixMsgs)
        elif parserType == 'HO':
            Inferborders = self.msgLogic.getOrderBorders(vePara, mixMsgs)
        else:
            Inferborders = self.msgLogic.getMbourders(vePara, mixMsgs)
        rightBorders = self.cmPaser.parseMsgs(mixMsgs)
        i = 0
        scores = []
        while (i < len(Inferborders)):
            scores.append(self.anlzer.get_f1(Inferborders[i], rightBorders[i]))
            i = i + 1
        print(parserType)
        print(sum([score[2] for score in scores]) / len(Inferborders))
        return [score[2] for score in scores]

    def getMixMixFone(self):
        mixMsgs = []
        ftpData = self.ftp.getTotalData()
        modData = self.modbus.getModDatas()
        mixMsgs.extend(ftpData)
        mixMsgs.extend(ftpData)
        vePara = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        msgs = self.ftpPaser.parseMsgs(mixMsgs)
        InferbordersOne = self.msgLogic.getFreBorders(vePara, msgs)
        Inferborders = self.msgLogic.getOrderBorders(vePara, msgs)
        # InferbordersOne = self.msgLogic.getEntryBorders(vePara, msgs)
        Inferborders = self.cvt.MergeListGroup(Inferborders, InferbordersOne)
        rightBorders = msgs
        i = 0
        scores = []
        while (i < len(Inferborders)):
            scores.append(self.anlzer.get_f1(Inferborders[i], rightBorders[i]))
            i = i + 1
        print(sum([score[0] for score in scores]) / len(Inferborders))
        print(sum([score[1] for score in scores]) / len(Inferborders))
        print(sum([score[2] for score in scores]) / len(Inferborders))