Skip to content

Factorio: Fix 500 error on Factorio multi-tracker. #3184

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

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions WebHostLib/tracker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import collections
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, NamedTuple
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, NamedTuple, Counter
from uuid import UUID

from flask import render_template
Expand Down Expand Up @@ -422,11 +422,11 @@ def render_generic_multiworld_tracker(tracker_data: TrackerData, enabled_tracker

if "Factorio" in network_data_package["games"]:
def render_Factorio_multiworld_tracker(tracker_data: TrackerData, enabled_trackers: List[str]):
inventories: Dict[TeamPlayer, Dict[int, int]] = {
(team, player): {
inventories: Dict[TeamPlayer, collections.Counter[str]] = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This collections.Counter[str] type annotation won't work in Python 3.8.

Suggested change
inventories: Dict[TeamPlayer, collections.Counter[str]] = {
inventories: Dict[TeamPlayer, Counter[str]] = {

Another workaround to fix it without typing.Counter is just to put the whole type annotation in quotes.

(team, player): collections.Counter({
tracker_data.item_id_to_name["Factorio"][item_id]: count
for item_id, count in tracker_data.get_player_inventory_counts(team, player).items()
} for team, players in tracker_data.get_all_slots().items() for player in players
}) for team, players in tracker_data.get_all_slots().items() for player in players
if tracker_data.get_player_game(team, player) == "Factorio"
}

Expand Down Expand Up @@ -501,7 +501,7 @@ class RegionCounts(NamedTuple):
total: int
checked: int

def prepare_inventories(team: int, player: int, inventory: collections.Counter[str], tracker_data: TrackerData):
def prepare_inventories(team: int, player: int, inventory: Counter[str], tracker_data: TrackerData):
for item, (prog_item, level) in non_progressive_items.items():
if item in inventory:
inventory[prog_item] = min(max(inventory[prog_item], level), progressive_item_max[prog_item])
Expand All @@ -525,7 +525,7 @@ def prepare_inventories(team: int, player: int, inventory: collections.Counter[s
inventory["Triforce"] = 1

def render_ALinkToThePast_multiworld_tracker(tracker_data: TrackerData, enabled_trackers: List[str]):
inventories: Dict[Tuple[int, int], collections.Counter[str]] = {
inventories: Dict[Tuple[int, int], Counter[str]] = {
(team, player): collections.Counter({
tracker_data.item_id_to_name["A Link to the Past"][code]: count
for code, count in tracker_data.get_player_inventory_counts(team, player).items()
Expand Down
Loading