def test_filter_apply(self): input = QEInput(config=fixtures.textMain) # Filter that adds parameters to input fp = Filter("fPlus") fp.setParam("control", "prefix", "'ni'") fp.setParam("control", "pseudo_dir", "''") fp.setParam("control", "outdir", "''") fp.setCard({ "name": "occupations", "lines": ("New line", ) }) # Add new card fp.setNamelist({ "name": "cell", "params": { "hello": "world" } }) # Add new namelist fp.setNamelist({"name": "phonon"}) fp.apply(input, "plus") self.assertEqual(input.toString(), fixtures.assertPlus) # Filter that removes parameters from input fm = Filter("fMinus") fm.setCard({"name": "atomic_species"}) fm.setNamelist({"name": "phonon"}) # Remove namelist fm.setParam("cell", "hello") # Remove parameter that makes namelist empty fm.setParam("control", "prefix") # Remove parameter fm.apply(input, "minus") self.assertEqual(input.toString(), fixtures.assertMinus)
def filter(self, q): """ q is the query. """ if not isinstance(q, str): s = "filter: invalid query argument. You must use a string." self.logger.error(s) raise TypeError(s) f = Filter(self.sites, q) f.apply()
def getmeansfromboard(self, board): # Split the board into pieces mean = [[0 for _ in range(self.boardsize)] for _ in range(self.boardsize)] #mean = [[0] * self.boardsize] * self.boardsize print mean means = [] for i in range(self.boardsize): row = board[(i * 50):((i + 1) * 50)] for j in range(self.boardsize): tile = row[0:50, (j * 50):((j + 1) * 50)] means.append(cv2.mean(tile)[0]) filter = Filter(self.boardsize) filter.apply(means) return means
def getmeansfromboard(self, board): # Split the board into pieces mean = [[0 for _ in range(self.boardsize)] for _ in range(self.boardsize)] #mean = [[0] * self.boardsize] * self.boardsize print mean means = [] for i in range(self.boardsize): row = board[(i*50):((i+1)*50)] for j in range(self.boardsize): tile = row[0:50, (j*50):((j+1)*50)] means.append(cv2.mean(tile)[0]) filter = Filter(self.boardsize) filter.apply(means) return means
def test_filter_apply(self): input = QEInput(config=fixtures.textMain) # Filter that adds parameters to input fp = Filter("fPlus") fp.setParam("control", "prefix", "'ni'") fp.setParam("control", "pseudo_dir", "''") fp.setParam("control", "outdir", "''") fp.setCard({"name": "occupations", "lines": ("New line",)}) # Add new card fp.setNamelist({"name": "cell", "params": {"hello": "world"}}) # Add new namelist fp.setNamelist({"name": "phonon"}) fp.apply(input, "plus") self.assertEqual(input.toString(), fixtures.assertPlus) # Filter that removes parameters from input fm = Filter("fMinus") fm.setCard({"name": "atomic_species"}) fm.setNamelist({"name": "phonon"}) # Remove namelist fm.setParam("cell", "hello") # Remove parameter that makes namelist empty fm.setParam("control", "prefix") # Remove parameter fm.apply(input, "minus") self.assertEqual(input.toString(), fixtures.assertMinus)
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
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