forked from Hanabi/hanabi-league
Optimize and fix index bug
This commit is contained in:
parent
67a7662da3
commit
628f7ef041
1 changed files with 17 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
from typing import Iterable, List
|
||||
from typing import Iterable, List, Dict
|
||||
|
||||
from config import config_manager
|
||||
from constants import UNWINNABLE_SEED_FRACTION
|
||||
|
@ -35,15 +35,12 @@ class GlobalInfo:
|
|||
player_counts: Iterable[int]
|
||||
user_names: Iterable[str]
|
||||
game_counts: Iterable[int]
|
||||
rated_id_indices_in_rating_list: Dict[int, int]
|
||||
|
||||
@property
|
||||
def rating_list_length(self):
|
||||
return len(self.rated_ids) + len(self.variant_ids) * len(self.player_counts)
|
||||
|
||||
@property
|
||||
def rated_id_indices_in_rating_list(self):
|
||||
return {id: index for index, id in dict(enumerate(self.rated_ids)).items()}
|
||||
|
||||
|
||||
@dataclass
|
||||
class GameRow:
|
||||
|
@ -329,8 +326,10 @@ if __name__ == "__main__":
|
|||
|
||||
player_counts = list(range(config.min_player_count, config.max_player_count + 1))
|
||||
game_counts = np.concatenate(
|
||||
[rated_ids_dupes.count(ID) for ID in rated_ids],
|
||||
np.zeros(len(variant_ids) * len(player_counts)),
|
||||
(
|
||||
[rated_ids_dupes.count(ID) for ID in rated_ids],
|
||||
np.zeros(len(variant_ids) * len(player_counts)),
|
||||
),
|
||||
)
|
||||
|
||||
user_names = list(np.full((len(rated_ids),), ""))
|
||||
|
@ -338,16 +337,22 @@ if __name__ == "__main__":
|
|||
for user_id, user_name in zip(game["user_ids"], game["users"]):
|
||||
user_names[rated_ids.index(user_id)] = user_name
|
||||
|
||||
rated_id_indices_in_rating_list = {
|
||||
id: index for index, id in dict(enumerate(rated_ids)).items()
|
||||
}
|
||||
|
||||
global_info = GlobalInfo(
|
||||
rated_ids, variant_ids, player_counts, user_names, game_counts
|
||||
rated_ids,
|
||||
variant_ids,
|
||||
player_counts,
|
||||
user_names,
|
||||
game_counts,
|
||||
rated_id_indices_in_rating_list,
|
||||
)
|
||||
|
||||
for variant_id, num_players in zip(variant_ids_dupes, nums_players):
|
||||
game_counts[
|
||||
len(rated_ids)
|
||||
+ calculate_variant_index_in_rating_list(
|
||||
num_players, variant_id, global_info
|
||||
)
|
||||
calculate_variant_index_in_rating_list(num_players, variant_id, global_info)
|
||||
] += 1
|
||||
global_info.game_counts = game_counts
|
||||
|
||||
|
|
Loading…
Reference in a new issue