Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Stats Support #28

Open
coreyjs opened this issue Feb 9, 2024 · 2 comments · May be fixed by #42
Open

Async Stats Support #28

coreyjs opened this issue Feb 9, 2024 · 2 comments · May be fixed by #42
Labels
enhancement New feature or request inprogress

Comments

@coreyjs
Copy link
Owner

coreyjs commented Feb 9, 2024

I am thinking about updating this to support async operations. If anyone has any feedback, for or against, I would love to hear it.

@coreyjs coreyjs added enhancement New feature or request inprogress labels Feb 9, 2024
@coreyjs coreyjs linked a pull request Feb 15, 2024 that will close this issue
@jaihon1
Copy link

jaihon1 commented Feb 20, 2024

Not really sure where you need async operations, but if it helps I worked a little with the new NHL API and used concurrency feature of python to get all landing data for batch games.

import concurrent.futures

def processGameLanding(game):
    game_id = game['id']

    try:
        getNHLGameLanding(game_id)
    except Exception as landing_error:
        print(f"Error retrieving Game Landing for game {game_id}: {landing_error}")

    print(f'Completed game: {game_id}')

def getAllLanding():
    num_threads = 100

    schedule_file_names = get_file_names('../data/nhl-v2/schedule')

    for schedule_file_name in schedule_file_names:
        print(f'Schedule File: {schedule_file_name}')

        games = readJSON(f'../data/nhl-v2/schedule/{schedule_file_name}')['games']

        # Create a ThreadPoolExecutor <---- This Part!
        with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor:
            # Submit tasks to the executor and get a list of futures
            futures = [executor.submit(processGameLanding, game) for game in games]

            # Use as_completed to iterate over completed futures
            for future in concurrent.futures.as_completed(futures):
                try:
                    future.result()  # Retrieve the result or raise an exception if an error occurred
                except Exception as e:
                    print(f"An error occurred: {e}")

@coreyjs
Copy link
Owner Author

coreyjs commented Feb 20, 2024

It was more out of a curiosity stand point on my end, but this is interesting. Thanks!

@coreyjs coreyjs changed the title Async Support Async Stats Support Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request inprogress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants