예제 #1
0
def process_games(aggr_by: int, games: Iterable[int]) -> Iterator[Tuple[str, str]]:
    for index, game_id in enumerate(games):
        game = RequestThing(game_id).with_flags("stats").query_first()

        collected_families = [
            family_id
            for family_id, family_name in game.links()["boardgamefamily"]
            if family_id in COLLECTED_FAMILIES
        ]
        if collected_families:
            collected_family = collected_families[0]
            g_games_in_family[collected_family].add(game.id())
            print(
                f"Skipping '{game.primary_name()}' ({game.id()}). It is part of family: {collected_family}"
            )
            continue

        if game.type() != "boardgame":
            print(f"Skipping '{game.type()}': {game.primary_name()} ({game.id()})")
            continue

        metadata = [
            f"{game.year_published() or MISSING_YEAR_LABEL}-{normalize_str(game.primary_name())}",
            game.primary_category() or MISSING_CATEGORY_LABEL,
            game.thumbnail() or "",
            "0",
        ]

        print(
            f"Processing plays for game {index:03d}: {game.primary_name()} ({game.id()})"
        )

        plays_logic = bcr.UniquePlaysLogic(aggr_by)
        users_logic = bcr.UniqueUsersLogic(aggr_by)
        total_logic = bcr.TotalUsersLogic(aggr_by)
        for play in RequestPlays(thingid=game_id).queryAll():
            plays_logic.visit(play)
            users_logic.visit(play)
            total_logic.visit(play)

        for exp_index, expansion in enumerate(game.links()["boardgameexpansion"]):
            print(
                f"Fetching plays for expansion {exp_index:02d}: {expansion[1]} ({expansion[0]}) of {game.primary_name()}"
            )
            for play in RequestPlays(thingid=expansion[0]).queryAll():
                plays_logic.visit(play)
                users_logic.visit(play)

        yield (
            f"{SEPARATOR.join(metadata)}{SEPARATOR}{bcr.Presenter(plays_logic, window(aggr_by), game.year_published(), SEPARATOR)}\n",
            f"{SEPARATOR.join(metadata)}{SEPARATOR}{bcr.Presenter(users_logic, window(aggr_by), game.year_published(), SEPARATOR)}\n",
        )

    print(f"Finished processing {index-1} games")
    def __iter__(self) -> Iterator[int]:
        for user_input in self.__user_inputs:
            if user_input == FLAG_ALL_CACHED:
                for id in RequestPlays.cached_queries():
                    yield int(id)

                print(f"Finished Reading entries from cache")

            elif user_input.startswith(LIST_PREFIX):
                listid = int(user_input.split(LIST_PREFIX)[1])
                geeklist = RequestList(listid).fetch()
                print(
                    f'Iterating over geeklist "{geeklist.title()}" by {geeklist.user_name()} [last updated: {geeklist.edit_date()}]'
                )

                for item in geeklist.filter(("thing", "boardgame")):
                    yield item.object_id()

                print(f"Finished GeekList {geeklist.id()}")

            elif user_input.startswith(FAMILY_PREFIX):
                family_id = int(user_input.split(FAMILY_PREFIX)[1])
                family = RequestFamily(family_id).query_first()
                print(f'Iterating over family "{family.primary_name()}"')

                for item_id, item_name in family:
                    yield item_id

                print(f"Finished family {family.id()}")

            elif user_input.isdigit():
                yield int(user_input)

            else:
                yield self.__get_game_id_from_name(user_input)
예제 #3
0
def main(argv: List[str] = []) -> int:
    locations_logic = lc.Logic()
    quantity_logic = qn.Logic()

    try:
        for index, game_id in enumerate(CLIGamesParser(argv[1:])):
            game = RequestThing(game_id).with_flags("stats").query_first()
            print(
                f"Processing plays for game {index:03d}: {game.primary_name()} ({game_id})"
            )
            player_count_logic = pca.Logic(game.player_count())
            for play in RequestPlays(thingid=game_id).queryAll():
                player_count_logic.visit(play)
                locations_logic.visit(play)
                quantity_logic.visit(play)

        print(f"Finished processing")
        return 0

    finally:
        print(pca.CLIPresenter(player_count_logic))
        print("\n" * 3)
        print(lc.CLIPresenter(locations_logic, is_digital=False))
        print("\n")
        print(lc.CLIPresenter(locations_logic, is_digital=True))
        print("\n")
        print(qn.Presenter(quantity_logic, percentile=0.99))
예제 #4
0
def process_games(games: Iterable[int]) -> Iterator[str]:
    for index, game_id in enumerate(games):
        game = RequestThing(game_id).with_flags("stats").query_first()

        collected_families = [
            family_id
            for family_id, family_name in game.links()["boardgamefamily"]
            if family_id in COLLECTED_FAMILIES
        ]
        if collected_families:
            collected_family = collected_families[0]
            g_games_in_family[collected_family].add(game.id())
            print(
                f"Skipping '{game.primary_name()}' ({game.id()}). It is part of family: {collected_family}"
            )
            continue

        if game.type() != "boardgame":
            print(
                f"Skipping '{game.type()}': {game.primary_name()} ({game.id()})"
            )
            continue

        print(
            f"Processing plays for game {index:03d}: {game.primary_name()} ({game.id()})"
        )

        player_count_logic = pca.Logic(game.player_count())
        session_count_logic = sc.Logic()
        for plays, play in enumerate(RequestPlays(thingid=game_id).queryAll()):
            player_count_logic.visit(play)
            session_count_logic.visit(play)

        if plays >= MIN_PLAYS_FOR_DISPLAY:
            try:
                fields = [
                    game.primary_name(),
                    game.id(),
                    game.primary_category() or "",
                    game.year_published(),
                    game.overall_rank(),
                    f"{game.player_count()[0]}-{game.player_count()[1]}",
                    game.ratings().users_rated(),
                    game.ratings().market()[0],
                    sc.Presenter(session_count_logic),
                    pca.CSVPresenter(player_count_logic, SEPARATOR),
                ]
                yield f"{SEPARATOR.join([str(field) for field in fields])}\n"
            except Exception as e:
                print(f"Skipping {game.primary_name()} because: {e}")
        else:
            print(
                f"Game {game.primary_name()} ({game.id()}) only had {plays} plays so it won't be added to the output!"
            )

    print(f"Finished processing {index-1} games")
예제 #5
0
def process_family(
    aggr_by: int, id: int, family_games: Iterable[int], bar_chart_race: bcr.MonthlyLogic
) -> str:
    family = RequestFamily(id).query_first()

    earliest_year = None
    popular_category = None
    popular_thumbnail = None
    popular_users_rated = 0
    for index, game_id in enumerate(family_games):
        game = RequestThing(game_id).with_flags("stats").query_first()

        print(
            f"Adding {index:03d} {game.primary_name()} ({game.id()}) to family {family.primary_name()}"
        )

        if (
            game.type() == "boardgame"
            and game.primary_category()
            and (
                not popular_category
                or game.ratings().users_rated() > popular_users_rated
            )
        ):
            popular_category = game.primary_category()

        if game.ratings().users_rated() > popular_users_rated:
            popular_users_rated = game.ratings().users_rated()
            popular_thumbnail = game.thumbnail()

        if game.year_published() and (
            not earliest_year or game.year_published() < earliest_year
        ):
            earliest_year = game.year_published()

        for play in RequestPlays(thingid=game_id).queryAll():
            bar_chart_race.visit(play)

    metadata = [
        # I don't use the word family here because it would clash with the
        # family category
        f"[SERIES] {earliest_year or MISSING_YEAR_LABEL}-{normalize_str(family.primary_name())}",
        popular_category or MISSING_CATEGORY_LABEL,
        family.thumbnail() or popular_thumbnail or "",
        "0",
    ]

    print(
        f"Finished processing family {family.primary_name()}, it has {index+1} games in it"
    )

    return f"{SEPARATOR.join(metadata)}{SEPARATOR}{bcr.Presenter(bar_chart_race, window(aggr_by), earliest_year or 1999, SEPARATOR)}\n"
예제 #6
0
def process_games(games: Iterable[int]) -> Iterator[str]:
    for index, game_id in enumerate(games):
        game = RequestThing(game_id).with_flags("stats").query_first()

        print(
            f"Processing plays for game {index:03d}: {game.primary_name()} ({game.id()})"
        )

        logic = ml.Logic()
        for plays, play in enumerate(RequestPlays(thingid=game_id).queryAll()):
            logic.visit(play)

        try:
            fields = [
                game.primary_name(),
                game.id(),
                ml.Presenter(logic, SEPARATOR)
            ]
            yield f"{SEPARATOR.join([str(field) for field in fields])}\n"
        except Exception as e:
            print(f"Skipping {game.primary_name()} because: {e}")

    print(f"Finished processing {index-1} games")
예제 #7
0
def process_family(id: int, family_games: Iterable[int]) -> str:
    family = RequestFamily(id).query_first()

    player_count_logic = pca.Logic()
    session_count_logic = sc.Logic()

    earliest_year = None
    popular_category = None
    best_rank = None
    published_play_count = None
    popular_users_rated = 0
    total_users_rated = 0
    total_owned = 0
    for index, game_id in enumerate(family_games):
        game = RequestThing(game_id).with_flags("stats").query_first()

        print(
            f"Adding {index:03d} {game.primary_name()} ({game.id()}) to family {family.primary_name()}"
        )

        if game.type() == "boardgame":
            best_rank = (min(best_rank, game.overall_rank()) if best_rank
                         and game.overall_rank() else game.overall_rank())

        if game.ratings().users_rated() > popular_users_rated:
            popular_users_rated = game.ratings().users_rated()
            if game.type() == "boardgame":
                if game.primary_category():
                    popular_category = game.primary_category()
                published_play_count = game.player_count()

        if not earliest_year or game.year_published() < earliest_year:
            earliest_year = game.year_published()

        total_owned += game.ratings().market()[0]
        total_users_rated += game.ratings().users_rated()

        for play in RequestPlays(thingid=game_id).queryAll():
            player_count_logic.visit(play)
            session_count_logic.visit(play)

    print(
        f"Finished processing family {family.primary_name()}, it has {index-1} games in it"
    )

    published = (f"{published_play_count[0]}-{published_play_count[1]}"
                 if published_play_count else "Unknown")

    fields = [
        # I don't use the word family here because it would clash with the
        # family category
        f"{family.primary_name()} [SERIES]",
        family.id(),
        popular_category or "",
        earliest_year,
        best_rank,
        published,
        total_users_rated,
        total_owned,
        sc.Presenter(session_count_logic),
        pca.CSVPresenter(player_count_logic, SEPARATOR),
    ]
    return f"{SEPARATOR.join([str(field) for field in fields])}\n"