Example #1
0
    def rendertable(self,
                    dataset,
                    cards,
                    allow_shortlink=1,
                    table_name="Custom Table",
                    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)
    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})
Example #3
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)
Example #4
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 = "Lm?"
        lim_cat.values = limited_flags
        lim_cat.yes_text = "Yes"
        lim_cat.no_text = "No"
        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)
Example #5
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)
Example #6
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})
Example #7
0
    async 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."
            )
            self.finish()
            return

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

        if not is_current:
            self.set_status(404)
            self.write(
                "Gacha rates are only available for current gachas. Sorry about that."
            )
            self.finish()
            return

        want_awakened = self.get_argument("plus", "NO") == "YES"
        live_info = await starlight.data.live_gacha_rates(selected_gacha.id)

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

        want_id_list = [gr.card_id for gr in availability_list]
        if want_awakened:
            limited_flags = {
                self.awakened_id(gr.card_id): gr.is_limited
                for gr in availability_list
            }
        else:
            limited_flags = {
                gr.card_id: gr.is_limited
                for gr in availability_list
            }

        if live_info:
            want_id_list.extend(cid for cid in live_info["indiv"]
                                if cid not in limited_flags)

        card_list = starlight.data.cards(want_id_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"
        categories.insert(0, lim_cat)

        if live_info:
            if want_awakened:
                indiv_rates = {
                    self.awakened_id(k): v
                    for k, v in live_info["indiv"].items()
                }
            else:
                indiv_rates = live_info["indiv"]

            odds_cat = table.CustomNumber(indiv_rates,
                                          header_text="Chance",
                                          format="{0:.3f}%")
            categories.insert(1, odds_cat)

            live_rates = live_info["rates"]
        else:
            live_rates = None

        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,
                         rates=live_rates)
Example #8
0
    async 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.")
            self.finish()
            return

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

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

        selected_gacha = selected_gacha
        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}

        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"
        categories.insert(0, lim_cat)

        if is_current:
            live_info = await starlight.data.live_gacha_rates(selected_gacha)
        else:
            live_info = None

        if live_info:
            rel_odds = live_info["indiv"].copy()
            rel_odds.update({self.flip_chain(starlight.data.card(gr.card_id)).id:
                rel_odds.get(gr.card_id, 0.0) for gr in availability_list})
            odds_cat = table.CustomNumber(rel_odds, header_text="Chance", format="{0:.3f}%")
            categories.insert(1, odds_cat)

            live_rates = live_info["rates"]
        else:
            live_rates = None

        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,
            rates=live_rates)