Ejemplo n.º 1
0
class GvoterLogic(splitter):
    def __init__(self):
        super().__init__()
        self.converter = Converter()
        self.msgSpliter = MsgSpliter()
        self.redis_dealer = redis_deal()

    def getGVotes(self, configParas, messages):
        freVotes = self.getFreVotes(configParas, messages)
        entryVotes = self.getEntryVotes(configParas, messages)
        freGVotes = self.converter.MergeListDics(freVotes)
        entryGVotes = self.converter.MergeListDics(entryVotes)
        return freGVotes, entryGVotes

    def getBoundaries(self, configParas, gveConfigParas, messages):
        freGVotes, entryGVotes = self.getGVotes(configParas, messages)
        desiner = Desiner()
        paraFre = {}
        paraFre['diff_measure'] = gveConfigParas['diffMeasure']
        paraFre['vWay'] = gveConfigParas['vWayFre']
        paraFre['T'] = gveConfigParas['T']
        paraFre['r'] = gveConfigParas['r']
        freBoundaries = desiner.VoteSingleByDicParas(paraFre, freGVotes)
        paraFre['vWay'] = gveConfigParas['vWayEntry']
        entryBoundaries = desiner.VoteSingleByDicParas(paraFre, entryGVotes)
        return Converter().MergeLists(freBoundaries, entryBoundaries)

    def getCommonRange(self, messages):
        heads = [len(message) for message in messages]
        t_head = min(heads)
        t_fhead = min(23, t_head + 2)
        return t_fhead

    def filterBoundaries(self, boundaries, cRange):
        rBoundaries = []
        for boundary in boundaries:
            if boundary < cRange:
                rBoundaries.append(boundary)
            else:
                break
        return rBoundaries

    def getGBoundaries(self, boundaries, messages):
        cRange = self.getCommonRange(messages)
        cBoundaries = self.filterBoundaries(boundaries, cRange)
        vSpliter = vertical_splitter(messages)
        merGer = base_merger()
        return cBoundaries

    def getSplitMessages(self,
                         configParas,
                         gveConfigParas,
                         messages,
                         FType='G'):
        splitKey = '{}_{}'.format(configParas.getUserPathDynamic(), 'GSplit')
        gBoundaries = None
        if FType == 'Y' and self.redis_dealer.is_exist_key(splitKey):
            gBoundaries = json.loads(
                self.redis_dealer.read_from_redis(splitKey))
        else:
            boundaries = self.getBoundaries(configParas, gveConfigParas,
                                            messages)
            gBoundaries = self.getGBoundaries(boundaries, messages)
            jsongBoundaries = json.dumps(gBoundaries)
            self.redis_dealer.insert_to_redis(splitKey, jsongBoundaries)
        return gBoundaries

    def splitMessages(self,
                      configParas,
                      gveConfigParas,
                      messages,
                      maxRange=15):
        gBoundaries = self.getSplitMessages(configParas, gveConfigParas,
                                            messages)
        return self.msgSpliter.splitMessages(
            [gBoundaries for i in range(len(messages))], messages, maxRange)

    def splitFileMessages(self, filePath, messages, maxRange=15):
        gVeParas = GveConf.geneGveParas()
        uConfig = UserConfig('/home/wxw/data/ToolDatas/15895903730.10.222',
                             '15895903730')
        messageSplitSums = self.splitMessages(uConfig, gVeParas, messages,
                                              maxRange)
        return messageSplitSums
Ejemplo n.º 2
0
class MegSplitLogic:
    def __init__(self):
        super().__init__()
        self.converter = Converter()
        self.msgSpliter = MsgSpliter()
        self.redis_dealer = redis_deal()
        self.splt = splitter()
        self.desiner = Desiner()
        self.msAb = MeasureAb()
        self.cvt = Converter()
        self.dataTuning = DataTuning()

    def getOrderBorders(self, gveConfigParas, messages):
        borderDicts = self.splt.getOrderVotesByMsgs(messages)
        paraFre = {}
        paraFre['diff_measure'] = gveConfigParas['diffMeasure']
        paraFre['vWay'] = gveConfigParas['vWayFre']
        paraFre['T'] = gveConfigParas['T']
        paraFre['r'] = gveConfigParas['r']
        return self.desiner.VoteMultyByDicParas(paraFre, borderDicts)

    def getEntryBorders(self, gveConfigParas, messages):
        entryDicts = self.splt.getEntryVotesByMsgs(messages)
        paraFre = {}
        paraFre['diff_measure'] = gveConfigParas['diffMeasure']
        paraFre['vWay'] = gveConfigParas['vWayFre']
        paraFre['T'] = gveConfigParas['T']
        paraFre['r'] = gveConfigParas['r']
        return self.desiner.VoteMultyByDicParas(paraFre, entryDicts)

    def getMbourders(self, gveConfigParas, messages):
        VeDicts = self.splt.getVeVotesByMsg(messages)
        paraFre = {}
        paraFre['diff_measure'] = gveConfigParas['diffMeasure']
        paraFre['vWay'] = gveConfigParas['vWayFre']
        paraFre['T'] = gveConfigParas['T']
        paraFre['r'] = gveConfigParas['r']
        print(VeDicts[0])
        return self.desiner.VoteMultyByDicParas(paraFre, VeDicts)

    def getFreBorders(self, gveConfigParas, messages):
        freDicts = self.splt.getFreVotesByMsg(messages)
        paraFre = {}
        paraFre['diff_measure'] = gveConfigParas['diffMeasure']
        paraFre['vWay'] = gveConfigParas['vWayFre']
        paraFre['T'] = gveConfigParas['T']
        paraFre['r'] = gveConfigParas['r']
        return self.desiner.VoteMultyByDicParas(paraFre, freDicts)

    def msgSplit(self, borders, msgs, maxRange=15):
        return self.msgSpliter.splitMessages(borders, msgs, maxRange)

    def getOrderBordersNyPath(self, filePath='', msgs=None, maxRange=15):
        # future update
        veParas = {'diffMeasure': 'abs', 'vWayFre': 'loose', 'T': 0, 'r': 0.3}
        # future update
        #if filePath != '':
        #    msgs = self.dataTuning.readDatas(filePath)
        borders = self.getOrderBorders(veParas, msgs)
        spltMsgs = self.msgSplit(borders, msgs, maxRange)
        return borders, spltMsgs