def test_get_signature_weights(self): self.cluster_set = ClusterSetSnapshot( game_format=FormatType.FT_STANDARD, live_in_production=True) self.cluster_set.save() self.class_cluster = ClassClusterSnapshot(cluster_set=self.cluster_set, player_class=CardClass.DRUID) self.class_cluster.save() self.cluster = ClusterSnapshot(class_cluster=self.class_cluster, cluster_id=1, external_id=247, required_cards=[48625], ccp_signature=MECHATHUN_DRUID) self.cluster.save() signature_weights = ClusterManager().get_signature_weights( FormatType.FT_STANDARD, CardClass.DRUID) assert signature_weights == { 247: { "required_cards": [48625], "rules": [], "signature_weights": {int(k): v for k, v in MECHATHUN_DRUID.items()} } }
def test_synchronize_required_cards(self): archetype = Archetype( name="Mecha'thun Druid", player_class=CardClass.DRUID, ) archetype.save() archetype.required_cards.add(Card.objects.get(dbf_id=836)) archetype.required_cards.add(Card.objects.get(dbf_id=1124)) cluster_set = ClusterSetSnapshot(game_format=FormatType.FT_STANDARD, live_in_production=True) cluster_set.save() class_cluster = ClassClusterSnapshot(cluster_set=cluster_set, player_class=CardClass.DRUID) class_cluster.save() cluster = ClusterSnapshot(class_cluster=class_cluster, cluster_id=1, external_id=archetype.id, required_cards=[48625], ccp_signature=MECHATHUN_DRUID) cluster.save() cluster_set.synchronize_required_cards() assert archetype.required_cards.count() == 1 assert archetype.required_cards.first() == Card.objects.get( dbf_id=48625)
def setup_method(self, db): self.cluster_set = ClusterSetSnapshot(latest=True) self.cluster_set.save() self.class_cluster = ClassClusterSnapshot( cluster_set=self.cluster_set, player_class=CardClass.PRIEST ) self.class_cluster.save() self.cluster = ClusterSnapshot( class_cluster=self.class_cluster, cluster_id=1, data_points=[{ "x": 0, "y": 0, "cards": _get_deck_from_deckstring( "AAECAa0GCO0Fw8EC0cEClsQCnccC3PUC8fsCiIIDC4oB+wHlBPIMysMCns4C8M8C6NACqe" "IC6uYCof4CAA==""" ), "observations": 1 }], signature=MECHATHUN_QUEST_PRIEST ) self.cluster.save()
def setup_method(self, db): Feature(name="archetype-training", status=FeatureStatus.PUBLIC).save() self.cluster_set = ClusterSetSnapshot() self.cluster_set.save() self.class_cluster = ClassClusterSnapshot(cluster_set=self.cluster_set) self.class_cluster.save() self.cluster = ClusterSnapshot( class_cluster=self.class_cluster, cluster_id=1, data_points=[{ "x": 0, "y": 0, "cards": _get_deck_from_deckstring( "AAECAZICApnTAvH7Ag5AX+kB/gHTA8QGpAf2B+QIktICmNICntICv/ICj/YCAA==" ), "observations": 1 }], signature=MECHATHUN_DRUID) self.cluster.save()
class TestClusterSnapshotRequiredCardsUpdateView: view = ClusterSnapshotRequiredCardsUpdateView() @pytest.fixture(autouse=True) def setup_method(self, db): self.cluster_set = ClusterSetSnapshot(latest=True) self.cluster_set.save() self.class_cluster = ClassClusterSnapshot( cluster_set=self.cluster_set, player_class=CardClass.PRIEST ) self.class_cluster.save() self.cluster = ClusterSnapshot( class_cluster=self.class_cluster, cluster_id=1, data_points=[{ "x": 0, "y": 0, "cards": _get_deck_from_deckstring( "AAECAa0GCO0Fw8EC0cEClsQCnccC3PUC8fsCiIIDC4oB+wHlBPIMysMCns4C8M8C6NACqe" "IC6uYCof4CAA==""" ), "observations": 1 }], signature=MECHATHUN_QUEST_PRIEST ) self.cluster.save() @pytest.mark.django_db def test_delete(self, client): self.cluster.required_cards = [41494, 48625] self.cluster.save() response = client.delete( f"/clusters/latest/FT_STANDARD/PRIEST/{self.cluster.cluster_id}/41494/" ) assert response.status_code == 200 self.cluster.refresh_from_db() assert self.cluster.required_cards == [48625] @pytest.mark.django_db def test_put(self, client): self.cluster.required_cards = [48625] self.cluster.save() response = client.put( f"/clusters/latest/FT_STANDARD/PRIEST/{self.cluster.cluster_id}/41494/" ) assert response.status_code == 200 self.cluster.refresh_from_db() assert self.cluster.required_cards == [48625, 41494]
def setup_method(self, db): self.cluster_set = ClusterSetSnapshot(latest=True) self.cluster_set.save() self.class_cluster = ClassClusterSnapshot( cluster_set=self.cluster_set, player_class=CardClass.DRUID ) self.class_cluster.save() self.cluster = ClusterSnapshot( class_cluster=self.class_cluster, cluster_id=1, data_points=[{ "x": 0, "y": 0, "cards": _get_deck_from_deckstring( "AAECAZICApnTAvH7Ag5AX+kB/gHTA8QGpAf2B+QIktICmNICntICv/ICj/YCAA==" ), "observations": 1 }], signature=MECHATHUN_DRUID ) self.cluster.save()
class TestClusterSnapshotUpdateView: view = ClusterSnapshotUpdateView() @pytest.fixture(autouse=True) def setup_method(self, db): self.cluster_set = ClusterSetSnapshot(latest=True) self.cluster_set.save() self.class_cluster = ClassClusterSnapshot( cluster_set=self.cluster_set, player_class=CardClass.DRUID ) self.class_cluster.save() self.cluster = ClusterSnapshot( class_cluster=self.class_cluster, cluster_id=1, data_points=[{ "x": 0, "y": 0, "cards": _get_deck_from_deckstring( "AAECAZICApnTAvH7Ag5AX+kB/gHTA8QGpAf2B+QIktICmNICntICv/ICj/YCAA==" ), "observations": 1 }], signature=MECHATHUN_DRUID ) self.cluster.save() @pytest.mark.django_db def test_patch_no_archetype_id(self, client): response = client.patch( f"/clusters/latest/FT_STANDARD/DRUID/{self.cluster.cluster_id}/", data="{}" ) assert response.status_code == 200 self.cluster.refresh_from_db() assert self.cluster.external_id is None assert self.cluster.name == "NEW" assert self.cluster.required_cards == [] @pytest.mark.django_db def test_patch_with_archetype_id(self, client): archetype = Archetype( name="Mecha'thun Druid", player_class=CardClass.DRUID, ) archetype.save() archetype.required_cards.add(Card.objects.get(dbf_id=48625)) response = client.patch( f"/clusters/latest/FT_STANDARD/DRUID/{self.cluster.cluster_id}/", data=json.dumps({ "archetype_id": archetype.id }) ) assert response.status_code == 200 self.cluster.refresh_from_db() assert self.cluster.external_id == archetype.id assert self.cluster.name == "Mecha'thun Druid" assert self.cluster.required_cards == [48625] @pytest.mark.django_db def test_patch_with_archetype_id_merge(self, client): archetype = Archetype( name="Mecha'thun Druid", player_class=CardClass.DRUID, ) archetype.save() archetype.required_cards.add(Card.objects.get(dbf_id=48625)) existing_cluster = ClusterSnapshot( class_cluster=self.class_cluster, cluster_id=2, data_points=[{ "x": 0, "y": 0, "cards": _get_deck_from_deckstring( "AAECAZICBFaHzgKZ0wLx+wINQF/pAf4BxAbkCKDNApTSApjSAp7SAtvTAoTmAr/yAgA=" ), "observations": 1 }], external_id=archetype.id, name=archetype.name, required_cards=[48625], signature=MECHATHUN_DRUID ) existing_cluster.save() response = client.patch( f"/clusters/latest/FT_STANDARD/DRUID/{self.cluster.cluster_id}/", data=json.dumps({ "archetype_id": archetype.id }) ) assert response.status_code == 200 assert ClusterSnapshot.objects.filter(pk=self.cluster.id).count() == 0 assert ClusterSnapshot.objects.filter(pk=existing_cluster.id).count() == 0 new_cluster = ClusterSnapshot.objects.filter(external_id=archetype.id).first() assert new_cluster.name == archetype.name assert new_cluster.required_cards == [48625]
def test_archetypes_serializer(archetypes_serializer_data, archetypes_serializer_metadata): cluster_set = ClusterSetSnapshot.objects.create(latest=True, promoted_on=timezone.now()) class_cluster = ClassClusterSnapshot(cluster_set=cluster_set, player_class=CardClass.DRUID) class_cluster.save() ClusterSnapshot.objects.create(ccp_signature={ "86": 0.13819617622610142, "531": 0.24418121363258521, "1109": 0.5286783042394015, "49184": 0.9821280133000831, "51791": 0.9445137157107232, "53179": 0.9954280964256027 }, class_cluster=class_cluster, cluster_id=123, external_id=1) archetype = Archetype.objects.create( id=1, name="Archetype 1", player_class=enums.CardClass.DRUID, ) mock_data = dict( game_type="RANKED_STANDARD", archetype=archetype, ) context = dict(RANKED_STANDARD=dict( deck_data=archetypes_serializer_data["decks"], popularity_data=archetypes_serializer_data["popularity"], matchup_data=archetypes_serializer_data["matchups"], matchup_metadata=archetypes_serializer_metadata["matchups"])) serializer = ArchetypeSerializer(instance=mock_data, context=context) data = serializer.data assert "id" in data assert data["id"] == 1 assert "name" in data assert len(data["name"].keys()) == 1 assert "enUS" in data["name"] assert data["name"]["enUS"] == "Archetype 1" assert "player_class" in data assert data["player_class"] == "DRUID" assert "signature_cards" in data assert data["signature_cards"] == [53179, 49184] assert "url" in data assert data["url"] == "https://hsreplay.net/archetypes/1/archetype-1" assert "game_types" in data assert len(data["game_types"].keys()) == 1 assert "RANKED_STANDARD" in data["game_types"] ranked_standard = data["game_types"]["RANKED_STANDARD"] assert "winrate" in ranked_standard assert ranked_standard["winrate"] == 50.50 assert "class_popularity" in ranked_standard assert ranked_standard["class_popularity"] == 12.34 assert "global_popularity" in ranked_standard assert ranked_standard["global_popularity"] == 4.56 assert "matchups" in ranked_standard assert len(ranked_standard["matchups"]) == 3 for i in range(0, 3): assert "id" in ranked_standard["matchups"][i] assert "winrate" in ranked_standard["matchups"][i] assert ranked_standard["matchups"][0]["id"] == 4 assert ranked_standard["matchups"][0]["winrate"] == 52.52 assert ranked_standard["matchups"][1]["id"] == 3 assert ranked_standard["matchups"][1]["winrate"] == 51.51 assert ranked_standard["matchups"][2]["id"] == 2 assert ranked_standard["matchups"][2]["winrate"] == 50.50 assert "most_popular_deck" in ranked_standard assert "url" in ranked_standard["most_popular_deck"] assert ranked_standard["most_popular_deck"][ "url"] == "https://hsreplay.net/decks/abc/" assert "winrate" in ranked_standard["most_popular_deck"] assert ranked_standard["most_popular_deck"]["winrate"] == 49.49 assert "best_performing_deck" in ranked_standard assert "url" in ranked_standard["best_performing_deck"] assert ranked_standard["best_performing_deck"][ "url"] == "https://hsreplay.net/decks/abc2/" assert "winrate" in ranked_standard["best_performing_deck"] assert ranked_standard["best_performing_deck"]["winrate"] == 51.51
class TestSingleClusterUpdateView: view = SingleClusterUpdateView() @pytest.fixture(autouse=True) def setup_method(self, db): Feature(name="archetype-training", status=FeatureStatus.PUBLIC).save() self.cluster_set = ClusterSetSnapshot() self.cluster_set.save() self.class_cluster = ClassClusterSnapshot(cluster_set=self.cluster_set) self.class_cluster.save() self.cluster = ClusterSnapshot( class_cluster=self.class_cluster, cluster_id=1, data_points=[{ "x": 0, "y": 0, "cards": _get_deck_from_deckstring( "AAECAZICApnTAvH7Ag5AX+kB/gHTA8QGpAf2B+QIktICmNICntICv/ICj/YCAA==" ), "observations": 1 }], signature=MECHATHUN_DRUID) self.cluster.save() @pytest.mark.django_db def test_patch_no_archetype_id(self, client): response = client.patch( f"/analytics/clustering/data/{self.cluster_set.id}/{self.cluster.cluster_id}/", data="{}") assert response.status_code == 200 self.cluster.refresh_from_db() assert self.cluster.external_id is None assert self.cluster.name == "NEW" assert self.cluster.required_cards == [] def test_patch_with_archetype_id(self, client): archetype = Archetype( name="Mecha'thun Druid", player_class=CardClass.DRUID, ) archetype.save() archetype.required_cards.add(Card.objects.get(dbf_id=48625)) response = client.patch( f"/analytics/clustering/data/{self.cluster_set.id}/{self.cluster.cluster_id}/", data=json.dumps({"archetype_id": archetype.id})) assert response.status_code == 200 self.cluster.refresh_from_db() assert self.cluster.external_id == archetype.id assert self.cluster.name == "Mecha'thun Druid" assert self.cluster.required_cards == [48625]