Esempio n. 1
0
async def rotation_hype_message() -> Optional[str]:
    runs, runs_percent, cs = rotation.read_rotation_files()
    runs_remaining = rotation.TOTAL_RUNS - runs
    newly_legal = [
        c for c in cs
        if c.hit_in_last_run and c.hits == rotation.TOTAL_RUNS / 2
    ]
    newly_eliminated = [
        c for c in cs if not c.hit_in_last_run and c.status == 'Not Legal'
        and c.hits_needed == runs_remaining + 1
    ]
    newly_hit = [c for c in cs if c.hit_in_last_run and c.hits == 1]
    num_undecided = len([c for c in cs if c.status == 'Undecided'])
    num_legal_cards = len([c for c in cs if c.status == 'Legal'])
    s = f'Rotation run number {runs} completed. Rotation is {runs_percent}% complete. {num_legal_cards} cards confirmed.'
    if not newly_hit + newly_legal + newly_eliminated and runs != 1 and runs % 5 != 0 and runs < rotation.TOTAL_RUNS / 2:
        return None  # Sometimes there's nothing to report
    if len(newly_hit) > 0 and runs_remaining > runs:
        newly_hit_s = list_of_most_interesting(newly_hit)
        s += f'\nFirst hit for: {newly_hit_s}.'
    if len(newly_legal) > 0:
        newly_legal_s = list_of_most_interesting(newly_legal)
        s += f'\nConfirmed legal: {newly_legal_s}.'
    if len(newly_eliminated) > 0:
        newly_eliminated_s = list_of_most_interesting(newly_eliminated)
        s += f'\nEliminated: {newly_eliminated_s}.'
    s += f"\nUndecided: {num_undecided}.\n<{fetcher.decksite_url('/rotation/')}>"
    return s
Esempio n. 2
0
 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)]
Esempio n. 3
0
def get_future_legality(c: Card, legal: bool) -> str:
    out_emoji = '<:rotating_out:702545628882010183>'
    for status, symbol in {'undecided': ':question:', 'legal': '<:rotating_in:702545611597021204>', 'notlegal': out_emoji}.items():
        if redis.sismember(f'decksite:rotation:summary:{status}', c.name):
            return symbol
    if rotation.read_rotation_files()[0] <= (rotation.TOTAL_RUNS / 2):
        return ':question:'
    if legal:
        return out_emoji
    return ''
Esempio n. 4
0
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
Esempio n. 5
0
 def __init__(self) -> 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.runs, self.runs_percent, self.cards = rotation.read_rotation_files(
         )
     else:
         self.cards = []
     self.num_cards = len(self.cards)
Esempio n. 6
0
 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