def getSigDates(user, start=None, end=None, extras=False): '''Get significant dates to test for the given user. Optionally filters dates to only those between 'start' and 'end'. If 'extras' is true, then it will include generic events in myuwDates. ''' # Expected cards for the given user userCards = cardList[user] # Convert start/end to myuwDate if start: start = myuwDate(start) if end: end = myuwDate(end) sigDates = [] # Internal function to ensure date is in range def checkDate(date): if start and date < start: return False if end and date > end: return False return True # Internal function to do duplicate checking then # add to list def addSigDate(date): if sigDate not in sigDates: sigDates.append(date) def checkAndAdd(date): if checkDate(date): addSigDate(date) # Go through each card collection (set of each # different version a card might be in depending on # date, as an alternative to natively supporting # that in the card). for cardColl in userCards.values(): # Go through each version of the card for card in cardColl: # Check each sigdate for each card and see if # it falls within the desired range if hasattr(card, 'significantDates'): for sigDate in card.significantDates: checkAndAdd(sigDate) if extras: for sigDate in getAllDates(): if not(getattr(sigDate, 'nosig', False)): checkAndAdd(sigDate) outList = sigDates outList.sort() return outList
def getExpectedResults(user, date): '''Get expected results for user on date. Returns a list of cards. ''' if isinstance(date, basestring): date = myuwDate(date) userCards = cardList[user] userCardsVisible = {} # Go over the collection of possible card states, figure out which to display for name, cardColl in userCards.items(): for card in cardColl: if card.shouldAppear(date): if name in userCardsVisible: s = 'Two expected cards with id %s on %s' %(name, date) raise Exception(s) else: userCardsVisible[name] = card return userCardsVisible