def complete_with_rel_odds(self, live_info): 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 self.availability_list}) odds_cat = table.CustomNumber(rel_odds, header_text="Chance", format="{0:.3f}%") self.categories.insert(1, odds_cat) live_rates = live_info["rates"] else: live_rates = None self.rendertable( (self.filters, self.categories), cards=self.card_list, allow_shortlink=0, table_name="Gacha: {0}".format(self.selected_gacha.name), template="ext_gacha_table.html", gacha=self.selected_gacha, rates=live_rates)
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})
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)
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)