def process_score(name: str, hits: int, cs: Dict[str, Card], runs: int, latest_list: List[str]) -> Optional[Card]: remaining_runs = TOTAL_RUNS - runs hits_needed = max(round(TOTAL_RUNS / 2 - hits), 0) c = cs[name] if c.layout not in multiverse.playable_layouts(): return None percent = round(round(hits / runs, 2) * 100) if remaining_runs == 0: percent_needed = '0' else: percent_needed = str( round(round(hits_needed / remaining_runs, 2) * 100)) if c is None: raise DoesNotExistException( "Legality list contains unknown card '{name}'".format(name=name)) if remaining_runs + hits < TOTAL_RUNS / 2: status = 'Not Legal' elif hits >= TOTAL_RUNS / 2: status = 'Legal' else: status = 'Undecided' hit_in_last_run = name in latest_list c.update({ 'hits': hits, 'hits_needed': hits_needed, 'percent': percent, 'percent_needed': percent_needed, 'status': status, 'hit_in_last_run': hit_in_last_run }) return c
def if_todays_prices(out: bool = True) -> List[Card]: current_format = multiverse.get_format_id('Penny Dreadful') if out: not_clause = '' compare = '<' else: not_clause = 'NOT' compare = '>=' where = """ c.id {not_clause} IN (SELECT card_id FROM card_legality WHERE format_id = {format}) AND c.name in (SELECT name FROM `{prices_database}`.cache WHERE week {compare} 0.5) AND c.layout IN ({layouts}) """.format(not_clause=not_clause, format=current_format, prices_database=configuration.get('prices_database'), compare=compare, layouts=', '.join([ sqlescape(layout) for layout in multiverse.playable_layouts() ])) rs = db().select(multiverse.cached_base_query(where=where)) cards = [Card(r) for r in rs] return sorted(cards, key=lambda card: card['name'])
def process_score(self, name: str, hits: int) -> None: remaining_runs = (168 - self.runs) hits_needed = max(84 - hits, 0) c = self.cs[name] if c.layout not in multiverse.playable_layouts(): return percent = round(round(hits / self.runs, 2) * 100) if remaining_runs == 0: percent_needed = '0' else: percent_needed = str(round(round(hits_needed / remaining_runs, 2) * 100)) if c is None: raise DoesNotExistException("Legality list contains unknown card '{name}'".format(name=name)) if remaining_runs + hits < 84: status = 'Not Legal' elif hits >= 84: status = 'Legal' else: status = 'Undecided' hit_in_last_run = name in self.latest_list c.update({ 'hits': redact(hits) if status == 'Undecided' else hits, 'hits_needed': redact(hits_needed) if status == 'Undecided' else hits_needed, 'percent': redact(percent) if status == 'Undecided' else percent, 'percent_hits_needed': redact(percent_needed) if status == 'Undecided' else percent_needed, 'status': status, 'interestingness': rotation.interesting(self.playability, c), 'hit_in_last_run': hit_in_last_run }) self.cards.append(c)
def process_score(self, name, hits): playability = card.playability() remaining_runs = (168 - self.runs) name = html.unescape(name.encode('latin-1').decode('utf-8')) hits_needed = max(84 - hits, 0) c = self.cs.get(name) if c.layout not in multiverse.playable_layouts(): return percent = round(round(hits / self.runs, 2) * 100) if remaining_runs == 0: percent_needed = 0 else: percent_needed = round(round(hits_needed / remaining_runs, 2) * 100) if c is None: raise DoesNotExistException("Legality list contains unknown card '{name}'".format(name=name)) if remaining_runs + hits < 84: status = 'Not Legal' elif hits >= 84: status = 'Legal' else: status = 'Undecided' hits = redact(hits) hits_needed = redact(hits_needed) percent = redact(percent) percent_needed = redact(percent_needed) c.update({ 'hits': hits, 'hits_needed': hits_needed, 'percent': percent, 'percent_hits_needed': percent_needed, 'status': status, 'interestingness': rotation.interesting(playability, c) }) self.cards.append(c)
def update_index(index: Index, cards: List[Card]) -> None: writer = index.writer() # We exclude tokens here because they can have the exact same name as cards. # We exclude emblems here to stop them showing up as cards = [c for c in cards if c.layout in multiverse.playable_layouts()] for card in cards: names = card.names if card.name not in names: names.append(card.name) # Split and aftermath cards for name in names: document = {} document['id'] = card.id document['name'] = name document['canonical_name'] = card.name document['name_tokenized'] = name document['name_stemmed'] = name document['name_normalized'] = name writer.update_document(**document) writer.commit()