Exemple #1
0
	def handle(self, *args, **options):
		result = {
			"map": {},
			"decks": {}
		}

		card_id_map, reverse_map = self.generate_card_id_maps()
		result["map"] = card_id_map

		offset = int(options["offset"])
		lookback = int(options["lookback"])
		today = date.today()
		date_from = (today - timedelta(days=(offset + lookback))).isoformat()
		date_to = (today - timedelta(days=offset)).isoformat()

		for row in execute_query(DECKS_QUERY % (date_from, date_to)):
			d = Deck.objects.get(id=row["deck_id"])

			if len(d.card_id_list()) == 30:
				player_class = guess_class(d)

				if player_class and (player_class.value not in result["decks"]):
					result["decks"][player_class.value] = []

				includes = d.includes.values_list("card__id", "count")
				deck_vector = self.generate_deck_feature_vector(reverse_map, includes)
				if deck_vector and player_class:
					deck_payload = {
						"observations": row["observations"],
						"cards": deck_vector
					}
					result["decks"][player_class.value].append(deck_payload)

		with open(options["out"], "wt") as out:
			out.write(json.dumps(result, indent=4))
Exemple #2
0
def render_deck_list_meta_for_digest_param(context):
	request = context.request
	deck_digest = request.GET.get("deck_digest", "")
	result = {
		"render_meta_tag": False
	}

	if deck_digest:
		deck = Deck.objects.filter(digest=deck_digest).first()
		if deck:
			class_guess = guess_class(deck)
			if class_guess:
				hero_card = Card.objects.filter(
					card_class=class_guess,
					type=CardType.HERO
				).first()
				if hero_card:
					result["render_meta_tag"] = True
					result["card_ids"] = ",".join(deck.card_id_list())
					result["hero_id"] = str(hero_card.id)

					if deck.archetype:
						name = deck.archetype.name
					else:
						name = "Deck"
					result["deck_name"] = "HSReplay.net %s" % name

	return result
	def handle(self, *args, **options):
		result = {
			"map": {},
			"decks": {}
		}

		card_id_map, reverse_map = self.generate_card_id_maps()
		result["map"] = card_id_map

		offset = int(options["offset"])
		lookback = int(options["lookback"])
		today = date.today()
		date_from = (today - timedelta(days=(offset + lookback))).isoformat()
		date_to = (today - timedelta(days=offset)).isoformat()

		for row in execute_query(DECKS_QUERY % (date_from, date_to)):
			d = Deck.objects.get(id=row["deck_id"])

			if len(d.card_id_list()) == 30:
				player_class = guess_class(d)

				if player_class and (player_class.value not in result["decks"]):
					result["decks"][player_class.value] = []

				includes = d.includes.values_list("card__id", "count")
				deck_vector = self.generate_deck_feature_vector(reverse_map, includes)
				if deck_vector and player_class:
					deck_payload = {
						"observations": row["observations"],
						"cards": deck_vector
					}
					result["decks"][player_class.value].append(deck_payload)

		with open(options["out"], "wt") as out:
			out.write(json.dumps(result, indent=4))
Exemple #4
0
	def get(self, request, id):
		try:
			deck = Deck.objects.get_by_shortid(id)
		except Deck.DoesNotExist:
			raise Http404("Deck does not exist.")

		cards = deck.card_dbf_id_list()
		if len(cards) != 30:
			raise Http404("Deck list is too small.")

		guessed_class = guess_class(deck)
		deck_name = "%s Deck" % (guessed_class.name.capitalize()) if guessed_class else ""
		request.head.title = deck_name

		if guessed_class:
			deck_url = request.build_absolute_uri(deck.get_absolute_url())
			request.head.add_meta(
				{"property": "x-hearthstone:deck", "content": deck_name},
				{"property": "x-hearthstone:deck:hero", "content": guessed_class.default_hero},
				{"property": "x-hearthstone:deck:cards", "content": ",".join(deck.card_id_list())},
				{"property": "x-hearthstone:deck:url", "content": deck_url},
			)

		context = {
			"deck": deck,
			"card_list": ",".join(str(id) for id in cards),
			"deck_class": guessed_class.name if guessed_class else "UNKNOWN",
			"deck_name": deck_name,
		}

		description = "Decklist for this %s. Learn how to play it with our mulligan " \
			"guide and find similar decks." % (deck_name)
		self.request.head.add_meta({"name": "description", "content": description})

		return render(request, self.template_name, context)