Skip to content

Commit

Permalink
Merge branch 'debarcode' of https://github.com/manuelseeger/sc2-ai-coach
Browse files Browse the repository at this point in the history
 into debarcode
  • Loading branch information
manuelseeger committed Oct 11, 2024
2 parents 8f13a05 + 0525dc5 commit f8aa897
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion obs_tools/playerinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,12 @@ def resolve_replays_from_current_opponent(
) -> Tuple[str, List[Replay]]:

playerinfo = None
race = None

log.debug(f"Resolving replays for opponent {opponent}")

if not is_barcode(opponent):
# 0 look in DB for player info
q = PlayerInfo.name == opponent
playerinfos = replaydb.db.find_many(PlayerInfo, q)

Expand All @@ -267,7 +269,10 @@ def resolve_replays_from_current_opponent(
# 1 look through DB and see if we played this name + portrait before
playerinfo = resolve_player_with_portrait(opponent, np.array(portrait))

if not playerinfo:
if not race:
log.debug(f"Could not get race, is SC2Client running?")

if not playerinfo and race:

# 2 query sc2pulse for player info
pulse_players = sc2pulse.get_unmasked_players(
Expand Down
5 changes: 5 additions & 0 deletions obs_tools/sc2pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# all credit to author [email protected]
# https://github.com/sc2-pulse/reveal-sc2-opponent

import logging
from datetime import UTC, datetime
from enum import Enum
from typing import List, Optional
Expand All @@ -14,6 +15,8 @@
from obs_tools.types import Race as GameInfoRace
from replays.util import convert_enum

log = logging.getLogger(f"{config.name}.{__name__}")


class SC2PulseRace(str, Enum):
protoss = "PROTOSS"
Expand Down Expand Up @@ -150,6 +153,8 @@ def get_teams(
"race": race.value,
},
)
if response.status_code == 404:
log.debug(f"404 for {batch}, race {race.value}")
response.raise_for_status()
pulse_teams = [SC2PulseTeam(**t) for t in response.json()]
teams.extend(pulse_teams)
Expand Down
13 changes: 12 additions & 1 deletion replays/newreplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import threading
from os.path import basename, join
from pathlib import Path
from time import sleep

from blinker import signal
Expand All @@ -20,6 +21,16 @@
reader = ReplayReader()


def wait_for_delete(file_path: Path, timeout: int = 10) -> bool:
for _ in range(timeout):
try:
os.remove(file_path)
return True
except:
sleep(1)
return False


class NewReplayScanner(threading.Thread):
def __init__(self, name):
super().__init__()
Expand Down Expand Up @@ -63,7 +74,7 @@ def replay_scanner(self):
if reader.is_instant_leave(replay_raw) or reader.has_afk_player(
replay_raw
):
os.remove(file_path)
wait_for_delete(file_path)
log.info(f"Deleted {basename(file_path)}")
list_of_files = new_list_of_files + list_of_files
sleep(config.deamon_polling_rate)

0 comments on commit f8aa897

Please sign in to comment.