Exemplo n.º 1
0
    def get(self, maybe_gachaid):
        if maybe_gachaid:
            maybe_gachaid = int(maybe_gachaid)
            gachas = starlight.data.gacha_ids()

            for gcid in gachas:
                if gcid.id == maybe_gachaid:
                    selected_gacha = gcid
                    break
            else:
                selected_gacha = None
        else:
            now = pytz.utc.localize(datetime.utcnow())
            gachas = starlight.data.gachas(now)

            if gachas:
                selected_gacha = gachas[0]
            else:
                selected_gacha = None

        if selected_gacha is None:
            self.set_status(404)
            self.write("Not found. If there's no gacha happening right now, you'll have to specify an ID.")
            return

        availability_list = starlight.data.available_cards(selected_gacha)
        availability_list.sort(key=lambda x: x.sort_order)

        card_list = starlight.data.cards(gr.card_id for gr in availability_list)
        limited_flags = {gr.card_id: gr.is_limited for gr in availability_list}
        rel_odds = {gr.card_id: gr.relative_odds / 10000 for gr in availability_list}
        rel_odds.update({self.flip_chain(starlight.data.card(gr.card_id)).id:
            rel_odds[gr.card_id] for gr in availability_list})

        filters, categories = table.select_categories("CASDE")

        lim_cat = table.CustomBool()
        lim_cat.header_text = "Lm?"
        lim_cat.values = limited_flags
        lim_cat.yes_text = "Yes"
        lim_cat.no_text = "No"

        odds_cat = table.CustomNumber(rel_odds, header_text="Chance", format="{0:.3f}%")

        categories.insert(0, odds_cat)
        categories.insert(0, lim_cat)

        self.rendertable( (filters, categories),
            cards=card_list,
            allow_shortlink=0,
            table_name="Gacha: {0}".format(selected_gacha.name),
            template="ext_gacha_table.html",
            gacha=selected_gacha)
        self.settings["analytics"].analyze_request(self.request, self.__class__.__name__,
            {"gid": maybe_gachaid})
Exemplo n.º 2
0
    def get(self, maybe_gachaid):
        now = pytz.utc.localize(datetime.utcnow())

        if maybe_gachaid:
            maybe_gachaid = int(maybe_gachaid)
            gachas = starlight.data.gacha_ids()

            for gcid in gachas:
                if gcid.id == maybe_gachaid:
                    selected_gacha = gcid
                    break
            else:
                selected_gacha = None
        else:
            gachas = starlight.data.gachas(now)

            if gachas:
                selected_gacha = gachas[0]
            else:
                selected_gacha = None

        if selected_gacha is None:
            self.set_status(404)
            self.write("Not found. If there's no gacha happening right now, you'll have to specify an ID.")
            return self.finish()

        is_current = (now >= selected_gacha.start_date) and (now <= selected_gacha.end_date)

        self.availability_list = starlight.data.available_cards(selected_gacha)
        self.availability_list.sort(key=lambda x: x.sort_order)

        self.selected_gacha = selected_gacha
        self.card_list = starlight.data.cards(gr.card_id for gr in self.availability_list)
        limited_flags = {gr.card_id: gr.is_limited for gr in self.availability_list}

        self.filters, self.categories = table.select_categories("CASDE")

        lim_cat = table.CustomBool()
        lim_cat.header_text = "限?"
        lim_cat.values = limited_flags
        lim_cat.yes_text = "○"
        lim_cat.no_text = "-"
        self.categories.insert(0, lim_cat)

        if is_current:
            starlight.data.live_gacha_rates(self.selected_gacha, self.complete_with_rel_odds)
        else:
            self.complete_with_rel_odds(None)
Exemplo n.º 3
0
    def rendertable(self, dataset, cards,
                    allow_shortlink=1, table_name="自定义列表",
                    template="generictable.html", **extra):
        if isinstance(dataset, str):
            filters, categories = table.select_categories(dataset)
        else:
            filters, categories = dataset

        should_switch_chain_head = self.get_argument("plus", "NO") == "YES"
        if should_switch_chain_head:
            cards = list(map(self.flip_chain, cards))

        extra.update(self.settings)

        self.render(template,
                    filters=filters,
                    categories=categories,
                    cards=cards,
                    original_dataset=dataset,
                    show_shortlink=allow_shortlink,
                    table_name=table_name,
                    is_displaying_awake_forms=should_switch_chain_head,
                    **extra)