Exemple #1
0
def rotation_changes() -> str:
    query = request.args.get('fq')
    if query is None:
        query = ''
    view = RotationChanges(
        *oracle.pd_rotation_changes(get_season_id()), cs.playability(), query=query)
    return view.page()
Exemple #2
0
def rotation_speculation() -> str:
    query = request.args.get('fq')
    if query is None:
        query = ''
    view = RotationChanges(oracle.if_todays_prices(out=False), oracle.if_todays_prices(
        out=True), cs.playability(), speculation=True, query=query)
    return view.page()
 def __init__(self, interestingness: Optional[str] = None, rotation_query: Optional[str] = None, only_these: Optional[List[str]] = None) -> None:
     super().__init__()
     self.playability = card.playability()
     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)
     self.cards: List[Card] = []
     if in_rotation:
         self.read_rotation_files()
     self.show_interesting = True
     if interestingness:
         self.cards = [c for c in self.cards if c.get('interestingness') == interestingness]
     if only_these:
         self.cards = [c for c in self.cards if c.name in only_these]
     self.num_cards = len(self.cards)
     self.rotation_query = rotation_query or ''
Exemple #4
0
 def __init__(self) -> None:
     super().__init__()
     self.playability = card.playability()
     until_full_rotation = rotation.next_rotation() - dtutil.now()
     until_supplemental_rotation = rotation.next_supplemental(
     ) - dtutil.now()
     in_rotation = False
     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)
     self.cards: List[Card] = []
     if in_rotation:
         self.read_rotation_files()
     self.show_interesting = True
Exemple #5
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)]
Exemple #6
0
 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)
Exemple #7
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
Exemple #8
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
Exemple #9
0
def rotation_speculation() -> str:
    view = RotationChanges(oracle.if_todays_prices(out=False),
                           oracle.if_todays_prices(out=True),
                           cs.playability(),
                           speculation=True)
    return view.page()
Exemple #10
0
def rotation_changes() -> str:
    view = RotationChanges(*oracle.pd_rotation_changes(get_season_id()),
                           cs.playability())
    return view.page()
def rotation_changes():
    view = RotationChanges(*oracle.last_pd_rotation_changes(), cs.playability())
    return view.page()