Skip to content

Commit

Permalink
fix issues from proj restruture and db migration
Browse files Browse the repository at this point in the history
  • Loading branch information
thearyadev committed Jan 19, 2024
1 parent 6547fc0 commit 92d6136
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
8 changes: 5 additions & 3 deletions utils/collector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import sys
sys.path.append(".")

import os
import time
import uuid
Expand All @@ -14,7 +17,6 @@
"page": 1,
} # settings for the leaderboard page

SUBFOLDER = "34"


def next_page():
Expand Down Expand Up @@ -56,5 +58,5 @@ def main():


if __name__ == "__main__":
main()
# pg.screenshot(f"./assets/leaderboard_images/MANUAL/SUPPORT-ASIA-44.png",region=(0,0,1920,1080,),)
# main()
pg.screenshot(f"./assets/manual/SUPPORT-EUROPE-46.png",region=(0,0,1920,1080,),)
50 changes: 25 additions & 25 deletions utils/generator.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import sys
sys.path.append(".")
import os
from concurrent.futures import ThreadPoolExecutor, as_completed

import legacy_database
import database
from PIL import Image
from rich.console import Console
from rich.progress import Progress, track
from rich.prompt import Prompt
from utils.raise_for_missing_env import raise_for_missing_env_vars

import leaderboards
import dotenv

console = Console()
dba = legacy_database.DatabaseAccess("./data/data.db")
dotenv.load_dotenv()

console = Console()
dba = database.DatabaseAccess(
host=os.getenv("MYSQLHOST") or raise_for_missing_env_vars(),
user=os.getenv("MYSQLUSER") or raise_for_missing_env_vars(),
password=os.getenv("MYSQLPASSWORD") or raise_for_missing_env_vars(),
database=os.getenv("MYSQLDATABASE") or raise_for_missing_env_vars(),
port=os.getenv("MYSQLPORT") or raise_for_missing_env_vars(),
)

def worker(file: str):
role, region, _ = file.split("-") # parse the filename
role = leaderboards.Role.by_name(role)
region = leaderboards.Region.by_name(region)

results = leaderboards.parse( # parse the leaderboard
image_path=os.path.join("./assets/leaderboard_images", file),
assets_path="./assets/hero_images",
Expand All @@ -27,43 +41,29 @@ def worker(file: str):
if i.heroes[0].name != "Blank":
dba.add_leaderboard_entry(seasonNumber=target_season, leaderboard_entry=i)


def worker2(file: str):
role, region, _ = file.split("-") # parse the filename
results = leaderboards.parse( # parse the leaderboard
image_path=os.path.join("./assets/leaderboard_images/MANUAL", file),
assets_path="./assets/hero_images",
role=role,
region=region,
model_name=model_name,
)
for i in results:
# Populate the database with the parsed results
if i.heroes[0].name != "Blank":
dba.add_leaderboard_entry(seasonNumber=target_season, leaderboard_entry=i)


def main():
global target_season, model_name # globals so the worker threads can access them
# sorry

target_season = "5_8"
target_season = "6_8"
model_name = "thearyadev-2023-08-25"
dba.create_season(seasonNumber=target_season)

files = os.listdir("./assets/leaderboard_images")
max_workers = 16
max_workers = 1
progress = Progress()

with progress:
progress_bar = progress.add_task(
"[red]Parsing Leaderboard Images...", total=len(files)
)
for file in files:
worker(file)

with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = [executor.submit(worker, file) for file in files]
for future in as_completed(futures):
progress.advance(progress_bar)
# with ThreadPoolExecutor(max_workers=max_workers) as executor:
# futures = [executor.submit(worker, file) for file in files]
# for future in as_completed(futures):
# progress.advance(progress_bar)


if __name__ == "__main__":
Expand Down

0 comments on commit 92d6136

Please sign in to comment.