def __init__(self, cards_in, cards_out, playability, speculation=False): self.sections = [] self.cards = cards_in + cards_out entries_in = [{ 'name': c.name, 'card': c, 'interestingness': rotation.interesting(playability, c, speculation) } for c in cards_in] entries_out = [{ 'name': c.name, 'card': c, 'interestingness': rotation.interesting(playability, c, speculation, new=False) } for c in cards_out] self.sections.append({ 'name': 'New this season', 'entries': entries_in, 'num_entries': len(entries_in) }) self.sections.append({ 'name': 'Rotated out', 'entries': entries_out, 'num_entries': len(entries_out) }) self.speculation = speculation self.show_interesting = True
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 __init__(self, interestingness: Optional[str] = None, query: Optional[str] = '') -> None: super().__init__() until_rotation = seasons.next_rotation() - dtutil.now() in_rotation = configuration.get_bool('always_show_rotation') if until_rotation < datetime.timedelta(7): in_rotation = True self.rotation_msg = 'Rotation is in progress, ends ' + dtutil.display_date(seasons.next_rotation(), 2) else: self.rotation_msg = 'Rotation is ' + dtutil.display_date(seasons.next_rotation(), 2) if in_rotation: self.in_rotation = in_rotation self.show_interestingness_filter = True self.runs, self.runs_percent, self.cards = rotation.read_rotation_files() # Now add interestingness to the cards, which only decksite knows not magic.rotation. playability = card.playability() c: Card for c in self.cards: c.interestingness = rotation.interesting(playability, c) else: self.cards = [] self.show_interesting = True if interestingness: self.cards = [c for c in self.cards if c.get('interestingness') == interestingness] self.num_cards = len(self.cards) self.query = query self.show_filters_toggle = True self.cards = [c for c in self.cards if visible(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 __init__(self, cards_in: Sequence[Card], cards_out: Sequence[Card], playability: Dict[str, float], speculation: bool = False, query: str = '') -> None: super().__init__() self.sections: List[Dict[str, Any]] = [] self.cards = list(cards_in) + list(cards_out) entries_in = [{ 'name': c.name, 'card': c, 'interestingness': rotation.interesting(playability, c, speculation) } for c in cards_in] entries_out = [{ 'name': c.name, 'card': c, 'interestingness': rotation.interesting(playability, c, speculation, new=False) } for c in cards_out] self.sections.append({ 'name': 'New this season', 'entries': entries_in, 'num_entries': len(entries_in) }) self.sections.append({ 'name': 'Rotated out', 'entries': entries_out, 'num_entries': len(entries_out) }) self.speculation = speculation self.show_interesting = True self.show_seasons = not speculation self.query = query self.show_interestingness_filter = True self.show_filters_toggle = True rotation_type = 'speculation' if speculation else 'changes' self.new_cards_deck_url = url_for(f'rotation_{rotation_type}_files', changes_type='new') self.rotated_out_cards_deck_url = url_for( f'rotation_{rotation_type}_files', changes_type='out') self.show_downloads = True
def __init__(self, cards_in: Sequence[Card], cards_out: Sequence[Card], playability: Dict[str, float], speculation: bool = False) -> None: super().__init__() self.sections: List[Dict[str, Any]] = [] self.cards = list(cards_in) + list(cards_out) entries_in = [{ 'name': c.name, 'card': c, 'interestingness': rotation.interesting(playability, c, speculation) } for c in cards_in] entries_out = [{ 'name': c.name, 'card': c, 'interestingness': rotation.interesting(playability, c, speculation, new=False) } for c in cards_out] self.sections.append({ 'name': 'New this season', 'entries': entries_in, 'num_entries': len(entries_in) }) self.sections.append({ 'name': 'Rotated out', 'entries': entries_out, 'num_entries': len(entries_out) }) self.speculation = speculation self.show_interesting = True self.show_seasons = not speculation
def rotation_cards_api() -> Response: """ Grab a slice of results from a 0-indexed resultset of cards that are potentially rotating in. Input: { 'page': <int>, 'pageSize': <int>, 'q': <str>, 'sortBy': <str>, 'sortOrder': <'ASC'|'DESC'> } Output: { 'page': <int>, 'objects': [<entry>], 'total': <int> } """ _, _, cs = rotation.read_rotation_files() q = request.args.get('q', '').lower() search_results = None try: search_results = [c.name for c in card_search.search(q)] if q else None except card_search.InvalidSearchException: pass if search_results is not None: cs = [c for c in cs if c.name in search_results] if not session.get('admin', False): cs = [c for c in cs if c.status != 'Undecided'] total = len(cs) # Now add interestingness to the cards, which only decksite knows not magic.rotation. playability = card.playability() for c in cs: c.interestingness = rotation.interesting(playability, c) rotation.rotation_sort(cs, request.args.get('sortBy'), request.args.get('sortOrder')) page_size = int(request.args.get('pageSize', DEFAULT_LIVE_TABLE_PAGE_SIZE)) page = int(request.args.get('page', 0)) start = page * page_size end = start + page_size cs = cs[start:end] prepare_cards(cs) r = {'page': page, 'total': total, 'objects': cs} resp = return_json(r, camelize=True) resp.set_cookie('page_size', str(page_size)) return resp
def __init__(self, interestingness: Optional[str] = None, query: Optional[str] = '') -> None: super().__init__() until_full_rotation = rotation.next_rotation() - dtutil.now() until_supplemental_rotation = rotation.next_supplemental() - dtutil.now() in_rotation = configuration.get_bool('always_show_rotation') if until_full_rotation < datetime.timedelta(7): in_rotation = True self.rotation_msg = 'Full rotation is in progress, ends ' + dtutil.display_date(rotation.next_rotation(), 2) elif until_supplemental_rotation < datetime.timedelta(7): in_rotation = True self.rotation_msg = 'Supplemental rotation is in progress, ends ' + dtutil.display_date(rotation.next_supplemental(), 2) elif until_full_rotation < until_supplemental_rotation: self.rotation_msg = 'Full rotation is ' + dtutil.display_date(rotation.next_rotation(), 2) else: self.rotation_msg = 'Supplemental rotation is ' + dtutil.display_date(rotation.next_supplemental(), 2) if in_rotation: self.in_rotation = in_rotation self.show_interestingness_filter = True self.runs, self.runs_percent, self.cards = rotation.read_rotation_files() # Now add interestingness to the cards, which only decksite knows not magic.rotation. playability = card.playability() c: Card for c in self.cards: c.interestingness = rotation.interesting(playability, c) else: self.cards = [] self.show_interesting = True if interestingness: self.cards = [c for c in self.cards if c.get('interestingness') == interestingness] self.num_cards = len(self.cards) self.query = query for c in self.cards: if c.status != 'Undecided': continue c.hits = redact(c.hits) c.hits_needed = redact(c.hits_needed) c.percent = redact(c.percent) c.percent_needed = redact(c.percent_needed) self.show_filters_toggle = True