Exemple #1
0
            break
        similarity = comparetext.comp(child.wordlist, child2.wordlist)
        max_similarity = max(max_similarity, similarity)
        if similarity > settings.cmp_threshold:
            child2.merge_item(child)
            logging.warning(
                "removing news entry: %s as duplicate of: %s",
                child.title,
                child2.title,
            )
    if max_similarity > settings.cmp_threshold:
        feed.remove_item(child)
        continue

    # Check against blackwords
    lvl = wordfilter.check(child.title, settings.title_scale)
    if child.categories:
        lvl += wordfilter.check(str(child.categories), 1)
    if child.content:
        lvl += wordfilter.check(str(child.content), 1)
    elif child.description:
        lvl += wordfilter.check(str(child.description), 1)
    child.set_stats(lvl, settings.threshold, max_similarity)
    if lvl > settings.threshold:
        logging.warning("removing item %s with score %i", child.title, lvl)
        feed.remove_item(child)
    child.append_stats = settings.appendlvl
    logging.info("%.2g %.2f " % (lvl, max_similarity) + child.title)

    for plugin in loaded_plugins:
        plugin.apply_on_item(child)
Exemple #2
0
class Carousel(object):

    def __init__(self, aggregatedData):
        self.__aData = aggregatedData
        self.__currentType = CUSTOMIZATION_TYPE.CAMOUFLAGE
        self.__currentSlotIdx = 0
        self.__currentDuration = 0
        self.__carouselItems = []
        self.filter = Filter(self.__aData.availableGroupNames)
        self.filter.changed += self.__updateCarouselData
        self.slots = Slots(self.__aData)
        self.slots.selected += self.__onSlotSelected
        self.slots.updated += self.__onSlotUpdated
        self.updated = Event()

    def fini(self):
        self.slots.selected -= self.__onSlotSelected
        self.slots.updated -= self.__onSlotUpdated
        self.filter.changed -= self.__updateCarouselData
        self.__carouselItems = None
        self.__aData = None
        self.slots.fini()
        self.filter.fini()
        return

    @property
    def items(self):
        return self.__carouselItems

    @property
    def currentType(self):
        return self.__currentType

    @property
    def currentSlotIdx(self):
        return self.__currentSlotIdx

    def applyItem(self, carouselItemIdx):
        self.slots.updateSlot(self.__carouselItems[carouselItemIdx], duration=self.__currentDuration)

    def previewItem(self, carouselItemIdx):
        previewItemID = self.__carouselItems[carouselItemIdx]['id']
        if self.__currentType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
            g_hangarSpace.space.updateVehicleCamouflage(camouflageID=previewItemID)
        else:
            self.__updateItemOnTank3DModel(previewItemID)

    def changeDuration(self, duration):
        self.__currentDuration = duration
        self.__updateCarouselData()

    def __updateItemOnTank3DModel(self, previewItemID):
        cType = self.__currentType
        slotIdx = self.__currentSlotIdx
        slotItem = self.slots.getData()['data'][cType]['data'][slotIdx]
        changedPreviewModel = copy.deepcopy(self.__aData.viewModel[1:3])
        rawInstalledItem = [previewItemID, time.time(), 0]
        if cType == CUSTOMIZATION_TYPE.INSCRIPTION:
            rawInstalledItem.append(0)
        changedPreviewModel[cType - 1][slotItem['spot'] + self.slots.calculateVehicleIndex(slotIdx, cType)] = rawInstalledItem
        g_hangarSpace.space.updateVehicleSticker(changedPreviewModel)

    def __onSlotSelected(self, newType, newSlotIdx):
        self.__currentType = newType
        self.__currentSlotIdx = newSlotIdx
        self.filter.setTypeAndIdx(newType, newSlotIdx)
        if newType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
            self.filter.set(FILTER_TYPE.GROUP, CAMOUFLAGE_GROUP_MAPPING[newSlotIdx])
        self.filter.apply()

    def __getBtnTooltip(self, installedInSlot):
        if installedInSlot:
            params = (TOOLTIPS.CUSTOMIZATION_CAROUSEL_SLOT_REMOVE_HEADER, TOOLTIPS.CUSTOMIZATION_CAROUSEL_SLOT_REMOVE_BODY)
        else:
            params = (TOOLTIPS.CUSTOMIZATION_CAROUSEL_SLOT_SELECT_HEADER, TOOLTIPS.CUSTOMIZATION_CAROUSEL_SLOT_SELECT_BODY)
        return makeTooltip(*params)

    def __onSlotUpdated(self, newSlotData):
        self.__updateCarouselData()

    def __updateCarouselData(self):
        oldItemsCount = len(self.__carouselItems)
        del self.__carouselItems[:]
        appliedItems = []
        purchasedItems = []
        otherItems = []
        currentSlotItem = None
        installedItemID = self.slots.getInstalledItem(self.__currentSlotIdx, self.__currentType).getID()
        if self.__currentType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
            displayedItems = {}
            for itemID, item in self.__aData.displayed[self.__currentType].iteritems():
                if item.getGroup() == CAMOUFLAGE_GROUP_MAPPING[self.__currentSlotIdx]:
                    displayedItems[itemID] = item

        else:
            displayedItems = self.__aData.displayed[self.__currentType]
        for itemID, item in displayedItems.iteritems():
            if not self.filter.check(item):
                continue
            appliedToCurrentSlot = itemID == self.slots.getSelectedSlotItemID()
            installedInSlot = itemID == installedItemID
            carouselItem = {'id': itemID,
             'object': item,
             'appliedToCurrentSlot': appliedToCurrentSlot,
             'price': item.getPrice(self.__currentDuration),
             'priceIsGold': item.priceIsGold(self.__currentDuration),
             'isInDossier': item.isInDossier,
             'buttonTooltip': self.__getBtnTooltip(installedInSlot),
             'duration': self.__currentDuration,
             'installedInSlot': installedInSlot}
            if appliedToCurrentSlot:
                currentSlotItem = carouselItem
            if installedInSlot:
                appliedItems.append(carouselItem)
            elif item.isInDossier:
                purchasedItems.append(carouselItem)
            else:
                otherItems.append(carouselItem)

        self.__carouselItems = appliedItems + purchasedItems + otherItems
        if currentSlotItem is not None:
            goToIndex = currentSlotCarouselItemIdx = self.__carouselItems.index(currentSlotItem)
        else:
            currentSlotCarouselItemIdx = -1
            goToIndex = -1 if oldItemsCount == len(self.__carouselItems) else 0
        self.updated({'items': self.__carouselItems,
         'rendererWidth': _RENDERER_WIDTH[self.__currentType],
         'selectedIndex': currentSlotCarouselItemIdx,
         'goToIndex': goToIndex,
         'unfilteredLength': len(displayedItems)})
        return
Exemple #3
0
    for index, dic in wordlists.items():
        t = comparetext.comp(wordlist, dic)
        maxcmplvl = max(maxcmplvl, t)
        if t > settings.cmp_threshold:
            feed.add_crosslink(index, link, title)
            logging.warn(_("removing news entry: %(duplicate)s\n\tas duplicate of: %(news)s") %
                         {'duplicate': title, 'news': feed.get_title(index)})
            continue
    if maxcmplvl > settings.cmp_threshold:
        feed.remove_item(child)
        continue
    else:
        wordlists[gid] = wordlist

    # Check against blackwords
    lvl = wordfilter.check(title, settings.title_scale)
    if content != "":
        lvl += wordfilter.check(content, 1)
    elif summary != "":
        lvl += wordfilter.check(summary, 1)
    if lvl > settings.threshold:
        logging.warn(_("removing item %(title)s with score %(score)i") %
                     {'title': title, 'score': lvl})
        feed.remove_item(child)
        del wordlists[gid]
    elif settings.appendlvl:
        appendstr = "<br><small><small>lvl: %.2g &nbsp;" % lvl + \
                    "maxcmplvl: %.2f</small></small>" % maxcmplvl
        feed.append_description(child, appendstr)
        if content != "":
            feed.append_content(child, appendstr)
Exemple #4
0
class Carousel(object):

    def __init__(self, aggregatedData):
        self.__aData = aggregatedData
        self.__currentType = CUSTOMIZATION_TYPE.CAMOUFLAGE
        self.__currentSlotIdx = 0
        self.__currentDuration = 0
        self.__carouselItems = []
        self.filter = Filter(self.__aData.availableGroupNames)
        self.filter.changed += self.__updateCarouselData
        self.slots = Slots(self.__aData)
        self.slots.selected += self.__onSlotSelected
        self.slots.updated += self.__onSlotUpdated
        self.updated = Event()

    def fini(self):
        self.slots.selected -= self.__onSlotSelected
        self.slots.updated -= self.__onSlotUpdated
        self.filter.changed -= self.__updateCarouselData
        self.__carouselItems = None
        self.__aData = None
        self.slots.fini()
        self.filter.fini()
        return

    @property
    def items(self):
        return self.__carouselItems

    @property
    def currentType(self):
        return self.__currentType

    @property
    def currentSlotIdx(self):
        return self.__currentSlotIdx

    def applyItem(self, carouselItemIdx):
        carouselItem = self.__carouselItems[carouselItemIdx]
        self.slots.applyItem(carouselItem, duration=self.__currentDuration)

    def changeDuration(self, duration):
        self.__currentDuration = duration
        self.__updateCarouselData()

    def __onSlotSelected(self, newType, newSlotIdx):
        self.__currentType = newType
        self.__currentSlotIdx = newSlotIdx
        self.filter.setTypeAndIdx(newType, newSlotIdx)
        if newType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
            self.filter.set(FILTER_TYPE.GROUP, CAMOUFLAGE_GROUP_MAPPING[newSlotIdx])
        self.filter.apply()

    def __onSlotUpdated(self, newSlotData):
        if self.__currentType == newSlotData['type'] and self.__currentSlotIdx == newSlotData['idx']:
            self.filter.setTypeAndIdx(newSlotData['type'], newSlotData['idx'])
            self.__updateCarouselData()

    def __updateCarouselData(self):
        oldItemsCount = len(self.__carouselItems)
        del self.__carouselItems[:]
        appliedItems = defaultdict(list)
        purchasedItems = defaultdict(list)
        otherItems = defaultdict(list)
        allItems = [appliedItems, purchasedItems, otherItems]
        currentSlotItem = None
        installedItemID = self.slots.getInstalledItem(self.__currentSlotIdx, self.__currentType).getID()
        if self.__currentType == CUSTOMIZATION_TYPE.CAMOUFLAGE:
            displayedItems = {}
            for itemID, item in self.__aData.displayed[self.__currentType].iteritems():
                if item.getGroup() == CAMOUFLAGE_GROUP_MAPPING[self.__currentSlotIdx]:
                    displayedItems[itemID] = item

        else:
            displayedItems = self.__aData.displayed[self.__currentType]
        filterExceptions = {FILTER_TYPE.SHOW_IN_DOSSIER: self.__aData.installed[self.__currentType]}
        for itemID, item in displayedItems.iteritems():
            if self.filter.check(item, filterExceptions):
                appliedToCurrentSlot = itemID == self.slots.getSelectedSlotItemID()
                installedInSlot = itemID == installedItemID
                isInQuests = item.isInQuests and not item.isInDossier and self.filter.purchaseType == PURCHASE_TYPE.QUEST
                carouselItem = {'id': itemID,
                 'object': item,
                 'appliedToCurrentSlot': appliedToCurrentSlot,
                 'price': item.getPrice(self.__currentDuration),
                 'priceIsGold': item.priceIsGold(self.__currentDuration),
                 'isInDossier': item.isInDossier,
                 'isInQuests': isInQuests,
                 'duration': self.__currentDuration,
                 'installedInSlot': installedInSlot}
                if appliedToCurrentSlot:
                    currentSlotItem = carouselItem
                if installedInSlot:
                    group = appliedItems[item.getGroup()]
                elif item.isInDossier:
                    group = purchasedItems[item.getGroup()]
                else:
                    group = otherItems[item.getGroup()]
                if item.isFeatured:
                    group.insert(0, carouselItem)
                else:
                    group.append(carouselItem)

        for groupedItems in allItems:
            self.__carouselItems += chain(*groupedItems.values())

        if currentSlotItem is not None:
            goToIndex = currentSlotCarouselItemIdx = self.__carouselItems.index(currentSlotItem)
        else:
            currentSlotCarouselItemIdx = -1
            goToIndex = -1 if oldItemsCount == len(self.__carouselItems) else 0
        self.updated({'items': self.__carouselItems,
         'rendererWidth': _RENDERER_WIDTH[self.__currentType],
         'selectedIndex': currentSlotCarouselItemIdx,
         'goToIndex': goToIndex,
         'unfilteredLength': len(displayedItems)})
        return