예제 #1
0
    def generate_tags(self, replay: Replay,
                      replay_data_extractor: ReplayDataExtractor) -> List[str]:
        def get_cannons(
            participant: Optional[sc2reader.objects.Participant],
        ) -> List[Unit]:
            if not participant or not participant.units:
                return []

            return [
                unit for unit in participant.units
                if unit.started_at <= ReplayDataExtractor.EARLY_RUSH_END
                and unit.is_building and ReplayDataExtractor.
                get_original_unit_name(unit) == "PhotonCannon"
            ]

        tags = []

        if any(cannon for cannon in get_cannons(replay_data_extractor.player)
               if replay_data_extractor.is_proxy(cannon)):
            tags.append(Replay.create_player_tag(CANNON_RUSH_TAG_NAME))

        if any(cannon for cannon in get_cannons(replay_data_extractor.opponent)
               if replay_data_extractor.is_proxy(cannon)):
            tags.append(Replay.create_opponent_tag(CANNON_RUSH_TAG_NAME))

        return tags
예제 #2
0
    def generate_tags(self, replay: Replay,
                      replay_data_extractor: ReplayDataExtractor) -> List[str]:
        def generate_tags_inner(
            participant: Optional[sc2reader.objects.Participant],
        ) -> List[str]:
            if not participant or not participant.units:
                return []

            protoss_tech_structures = [
                unit for unit in participant.units
                if unit.started_at <= ReplayDataExtractor.EARLY_GAME_END
                and ReplayDataExtractor.get_original_unit_name(
                    unit) in _PROTOSS_TECH_STRUCTURES
            ]
            protoss_tech_structures.sort(key=lambda unit: unit.started_at)

            if not protoss_tech_structures:
                return []

            tech_structure_name = ReplayDataExtractor.get_original_unit_name(
                protoss_tech_structures[0])
            tag_name = _PROTOSS_TECH_STRUCTURES[tech_structure_name]
            return [tag_name]

        return [
            Replay.create_player_tag(tag_name)
            for tag_name in generate_tags_inner(replay_data_extractor.player)
        ] + [
            Replay.create_opponent_tag(tag_name)
            for tag_name in generate_tags_inner(replay_data_extractor.opponent)
        ]
예제 #3
0
    def preprocess_replay(self, replay: Replay, _: ReplayDataExtractor) -> Replay:
        if not replay.teams:
            return replay

        if replay.player_team is not None or replay.opponent_team is not None:
            return replay

        potential_player_teams = [
            index
            for index, team in enumerate(replay.teams)
            if team.team_id in self.replay_store.get_replay_player_team_ids()
        ]
        if len(potential_player_teams) != 1:
            return replay

        replay.player_team = potential_player_teams[0]

        potential_opponent_teams = [
            index for index in range(len(replay.teams)) if index != replay.player_team
        ]
        if len(potential_opponent_teams) != 1:
            return replay

        replay.opponent_team = potential_opponent_teams[0]

        return replay
예제 #4
0
    def preprocess_replay(
            self, replay: Replay,
            replay_data_extractor: ReplayDataExtractor) -> Replay:
        if replay.opponent_team is not None or replay.player_team is not None:
            # Player and opponent team shouldn't be the same
            if replay.opponent_team == replay.player_team:
                replay.player_team = None
                replay.opponent_team = None

        return replay
예제 #5
0
    def generate_tags(self, replay: Replay,
                      replay_data_extractor: ReplayDataExtractor) -> List[str]:
        tags: List[str] = []

        if replay_data_extractor.player and not replay_data_extractor.player.is_human:
            tags.append(Replay.create_player_tag(AI_TAG))

        if (replay_data_extractor.opponent
                and not replay_data_extractor.opponent.is_human):
            tags.append(Replay.create_opponent_tag(AI_TAG))

        return tags
예제 #6
0
    def generate_tags(
        self, replay: Replay, replay_data_extractor: ReplayDataExtractor
    ) -> List[str]:
        if (
            not replay_data_extractor.player
            or not replay_data_extractor.player.result
            or not replay_data_extractor.opponent
            or not replay_data_extractor.opponent.result
        ):
            return []

        return [
            Replay.create_player_tag(replay_data_extractor.player.result.lower()),
            Replay.create_opponent_tag(replay_data_extractor.opponent.result.lower()),
        ]
예제 #7
0
 def generate_tags(self, replay: Replay,
                   replay_data_extractor: ReplayDataExtractor) -> List[str]:
     map_name: str = replay_data_extractor.source_replay_data.map_name
     map_name = map_name.lower()
     map_name = re.sub(r"[^\w\s]", "", map_name)
     map_name = re.sub(r"\s+", "_", map_name)
     return [Replay.create_game_tag(_MAP_TAG_PREFIX + map_name)]
예제 #8
0
    def generate_tags(self, replay: Replay,
                      replay_data_extractor: ReplayDataExtractor) -> List[str]:

        game_type = replay_data_extractor.source_replay_data.game_type.lower()
        if game_type in GAME_TYPES:
            return [Replay.create_game_tag(game_type)]

        return []
예제 #9
0
    def process_replay(self, replay: Replay) -> Replay:
        replay_data_extractor = ReplayDataExtractor(replay)

        for preprocessor in create_preprocessors(self._replay_store):
            replay = preprocessor.preprocess_replay(replay,
                                                    replay_data_extractor)

        tag_generators = create_tag_generators()
        for tag in flatten(tag_generator.tags_to_remove()
                           for tag_generator in tag_generators):
            replay.remove_tag(tag)

        new_tags = (flatten(
            tag_generator.generate_tags(replay, replay_data_extractor)
            for tag_generator in tag_generators) + replay.tags)

        replay.set_tags(new_tags)

        return replay
예제 #10
0
    def generate_tags(self, replay: Replay,
                      replay_data_extractor: ReplayDataExtractor) -> List[str]:
        tags: List[str] = []

        if (not replay_data_extractor.player
                or not replay_data_extractor.player.play_race):
            return tags

        player_race = replay_data_extractor.player.play_race.lower()
        tags.append(Replay.create_player_tag(player_race))

        if (not replay_data_extractor.opponent
                or not replay_data_extractor.opponent.play_race):
            return tags

        opponent_race = replay_data_extractor.opponent.play_race.lower()
        tags.append(Replay.create_opponent_tag(opponent_race))

        return tags
예제 #11
0
    def generate_tags(self, replay: Replay,
                      replay_data_extractor: ReplayDataExtractor) -> List[str]:
        if (not replay_data_extractor.player
                or not replay_data_extractor.player.play_race
                or not replay_data_extractor.opponent
                or not replay_data_extractor.opponent.play_race):
            return []

        matchup = (replay_data_extractor.player.play_race[:1] + "v" +
                   replay_data_extractor.opponent.play_race[:1]).lower()

        return [Replay.create_game_tag(matchup)]
예제 #12
0
from typing import List

from cerebrate.core import Replay
from cerebrate.processor.extractor import ReplayDataExtractor

from .tag_generator import TagGenerator

PLAYER_RANDOM_TAG = Replay.create_player_tag("random")
OPPONENT_RANDOM_TAG = Replay.create_opponent_tag("random")


class RandomTagGenerator(TagGenerator):
    def tags_to_remove(self) -> List[str]:
        return [PLAYER_RANDOM_TAG, OPPONENT_RANDOM_TAG]

    def generate_tags(self, replay: Replay,
                      replay_data_extractor: ReplayDataExtractor) -> List[str]:
        tags: List[str] = []

        if (not replay_data_extractor.player
                or not replay_data_extractor.player.pick_race):
            return tags

        if replay_data_extractor.player.pick_race == "Random":
            tags.append(PLAYER_RANDOM_TAG)

        if (not replay_data_extractor.opponent
                or not replay_data_extractor.opponent.pick_race):
            return tags

        if replay_data_extractor.opponent.pick_race == "Random":
예제 #13
0
 def tags_to_remove(self) -> List[str]:
     return [Replay.create_game_tag(game_type) for game_type in GAME_TYPES]
예제 #14
0
 def tags_to_remove(self) -> List[str]:
     return [Replay.create_game_tag(matchup) for matchup in MATCHUPS]
예제 #15
0
def _set_replay_info_from_payload(replay: Replay, payload: dict) -> Replay:
    replay.set_tags(payload.get("selectedTags", []))
    replay.notes = payload.get("notes", "")
    replay.player_team = payload.get("playerTeam")
    replay.opponent_team = payload.get("opponentTeam")
    return replay
예제 #16
0
 def tags_to_remove(self) -> List[str]:
     return [
         Replay.create_player_tag(CANNON_RUSH_TAG_NAME),
         Replay.create_opponent_tag(CANNON_RUSH_TAG_NAME),
     ]
예제 #17
0
 def tags_to_remove(self) -> List[str]:
     return [
         Replay.create_player_tag(AI_TAG),
         Replay.create_opponent_tag(AI_TAG),
     ]
예제 #18
0
 def preprocess_replay(
         self, replay: Replay,
         replay_data_extractor: ReplayDataExtractor) -> Replay:
     replay.timestamp = replay_data_extractor.source_replay_data.unix_timestamp
     return replay