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

introduce typescript #447

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions project/thscoreboard/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ tests/report/
shared_content/static/style.css
staticfiles
launch.json
package-lock.json
1 change: 1 addition & 0 deletions project/thscoreboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"devDependencies": {
"@types/jsdom": "^21.1.0",
"@types/node": "^20.4.10",
"jest": "^29.5.0",
"jsdom": "^21.1.1"
},
Expand Down
32 changes: 16 additions & 16 deletions project/thscoreboard/replays/replays_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,38 @@ def convert_replay_to_dict(self, replay: models.Replay) -> dict:
score_prefix = _get_medal_emoji(replay.rank) if hasattr(replay, "rank") else ""

json_dict = {}
json_dict["Id"] = replay.id
json_dict["id"] = replay.id
Copy link
Owner

Choose a reason for hiding this comment

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

IMO you should really make these changes in a separate PR; they make this one look much bigger than it needs to be

if replay.user:
json_dict["User"] = {
json_dict["user"] = {
"text": f"{replay.user.username}",
"url": f"/replays/user/{replay.user.username}",
}
else:
json_dict["User"] = replay.imported_username or replay.name
json_dict["Game"] = {
json_dict["user"] = replay.imported_username or replay.name
json_dict["game"] = {
"text": game.GetShortName(),
"url": f"/replays/{game.game_id}",
}
json_dict["Difficulty"] = game_ids.GetDifficultyName(
json_dict["difficulty"] = game_ids.GetDifficultyName(
game.game_id, replay.difficulty
)
json_dict["Shot"] = self._get_shot_name(shot)
json_dict["shot"] = self._get_shot_name(shot)
if game.game_id in [
game_ids.GameIDs.TH01,
game_ids.GameIDs.TH08,
game_ids.GameIDs.TH128,
]:
route = replay.route
json_dict["Route"] = route.GetName() if route is not None else ""
json_dict["route"] = route.GetName() if route is not None else ""
if game.game_id == game_ids.GameIDs.TH128 and replay.difficulty == 4:
json_dict["Route"] = "Extra"
json_dict["Score"] = {
json_dict["route"] = "Extra"
json_dict["score"] = {
"text": f"{score_prefix}{int(replay.score):,}",
"url": f"/replays/{game.game_id}/{replay.id}",
}
json_dict["Upload Date"] = replay.created.strftime("%Y-%m-%d")
json_dict["Comment"] = replay.GetShortenedComment()
json_dict["Replay"] = {
json_dict["uploadDate"] = replay.created.strftime("%Y-%m-%d")
json_dict["comment"] = replay.GetShortenedComment()
json_dict["replay"] = {
"text": "⬇",
"url": f"/replays/{game.game_id}/{replay.id}/download",
}
Expand All @@ -68,14 +68,14 @@ def convert_replay_to_dict(self, replay: models.Replay) -> dict:

def _get_th16_additional_fields(self, shot: models.Shot) -> dict:
return {
"Character": shot.GetCharacterName(),
"Season": shot.GetSubshotName(),
"character": shot.GetCharacterName(),
"season": shot.GetSubshotName(),
}

def _get_th17_additional_fields(self, shot: models.Shot) -> dict:
return {
"Character": shot.GetCharacterName(),
"Goast": shot.GetSubshotName(),
"character": shot.GetCharacterName(),
"goast": shot.GetSubshotName(),
}

def convert_replay_to_json_bytes(self, replay: models.Replay) -> bytes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<script>
const showGameColumn = "{{show_game}}";
const showRouteColumn = "{{show_route}}";
const aaaa = "aaaaa";
Copy link
Owner

Choose a reason for hiding this comment

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

?

</script>

<script src="/static/js/replays/replayTable.js"></script>
58 changes: 29 additions & 29 deletions project/thscoreboard/replays/test_replays_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,28 @@ def testConvertReplaysToJsonString(self):

for json_replay_data in json_data:
assert json_replay_data
assert isinstance(json_replay_data["Score"], dict)
assert set(json_replay_data["Score"].keys()) == {"text", "url"}

assert isinstance(json_replay_data["Replay"], dict)
assert set(json_replay_data["Replay"].keys()) == {"text", "url"}

assert json_data[0]["User"]["text"] == self.user.username
assert json_data[0]["User"]["url"] == f"/replays/user/{self.user.username}"
assert json_data[0]["Game"]["text"] == "th06"
assert json_data[0]["Game"]["url"] == "/replays/th06"
assert json_data[0]["Difficulty"] == "Easy"
assert json_data[0]["Shot"] == "Reimu A"
assert json_data[0]["Score"]["text"] == "🥇1,000,000"
assert json_data[0]["Upload Date"] == "2000-01-01"
assert json_data[0]["Comment"] == "鼻毛"
assert json_data[0]["Replay"]["text"] == "⬇"
assert "Character" not in json_data[0]["Replay"]["text"]
assert "Season" not in json_data[0]["Replay"]["text"]

assert json_data[1]["User"] == "あ"
assert json_data[1]["Character"] == "Marisa"
assert json_data[1]["Season"] is None
assert isinstance(json_replay_data["score"], dict)
assert set(json_replay_data["score"].keys()) == {"text", "url"}

assert isinstance(json_replay_data["replay"], dict)
assert set(json_replay_data["replay"].keys()) == {"text", "url"}

assert json_data[0]["user"]["text"] == self.user.username
assert json_data[0]["user"]["url"] == f"/replays/user/{self.user.username}"
assert json_data[0]["game"]["text"] == "th06"
assert json_data[0]["game"]["url"] == "/replays/th06"
assert json_data[0]["difficulty"] == "Easy"
assert json_data[0]["shot"] == "Reimu A"
assert json_data[0]["score"]["text"] == "🥇1,000,000"
assert json_data[0]["uploadDate"] == "2000-01-01"
assert json_data[0]["comment"] == "鼻毛"
assert json_data[0]["replay"]["text"] == "⬇"
assert "character" not in json_data[0]["replay"]["text"]
assert "season" not in json_data[0]["replay"]["text"]

assert json_data[1]["user"] == "あ"
assert json_data[1]["character"] == "Marisa"
assert json_data[1]["season"] is None

def testMedalEmojisSingleShot(self):
for i in range(5):
Expand All @@ -111,11 +111,11 @@ def testMedalEmojisSingleShot(self):
converter = ReplayToJsonConverter()
json_data = [converter.convert_replay_to_dict(replay) for replay in replays]

self.assertEquals(json_data[0]["Score"]["text"], "🥇1,000,000,000")
self.assertEquals(json_data[1]["Score"]["text"], "🥈900,000,000")
self.assertEquals(json_data[2]["Score"]["text"], "🥉800,000,000")
self.assertEquals(json_data[3]["Score"]["text"], "700,000,000")
self.assertEquals(json_data[4]["Score"]["text"], "600,000,000")
self.assertEquals(json_data[0]["score"]["text"], "🥇1,000,000,000")
self.assertEquals(json_data[1]["score"]["text"], "🥈900,000,000")
self.assertEquals(json_data[2]["score"]["text"], "🥉800,000,000")
self.assertEquals(json_data[3]["score"]["text"], "700,000,000")
self.assertEquals(json_data[4]["score"]["text"], "600,000,000")

def testMedalEmojisMultipleShots(self):
replay_filenames = [
Expand All @@ -136,5 +136,5 @@ def testMedalEmojisMultipleShots(self):
converter = ReplayToJsonConverter()
json_data = [converter.convert_replay_to_dict(replay) for replay in replays]

self.assertEquals(json_data[0]["Score"]["text"], "🥇1,000,000,000")
self.assertEquals(json_data[1]["Score"]["text"], "🥇900,000,000")
self.assertEquals(json_data[0]["score"]["text"], "🥇1,000,000,000")
self.assertEquals(json_data[1]["score"]["text"], "🥇900,000,000")
24 changes: 12 additions & 12 deletions project/thscoreboard/replays/views/replay_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,31 @@ def _get_filter_options(game: Game) -> dict[str, list[str]]:
def _get_filter_options_default(game: Game) -> dict[str, list[str]]:
all_shots = [shot.GetName() for shot in Shot.objects.filter(game=game.game_id)]
all_difficulties = [game.GetDifficultyName(d) for d in range(game.num_difficulties)]
return {"Difficulty": all_difficulties, "Shot": all_shots}
return {"difficulty": all_difficulties, "shot": all_shots}


def _get_filter_options_th01_th128(game: Game) -> dict[str, list[str]]:
all_difficulties = [game.GetDifficultyName(d) for d in range(game.num_difficulties)]
all_routes = [route.GetName() for route in Route.objects.filter(game=game.game_id)]
return {"Difficulty": all_difficulties, "Route": all_routes}
return {"difficulty": all_difficulties, "route": all_routes}


def _get_filter_options_th08(game: Game) -> dict[str, list[str]]:
all_shots = [shot.GetName() for shot in Shot.objects.filter(game=game.game_id)]
all_difficulties = [game.GetDifficultyName(d) for d in range(game.num_difficulties)]
all_routes = [route.GetName() for route in Route.objects.filter(game=game.game_id)]
return {
"Difficulty": all_difficulties,
"Shot": all_shots,
"Route": all_routes,
"difficulty": all_difficulties,
"shot": all_shots,
"route": all_routes,
}


def _get_filter_options_th13(game: Game) -> dict[str, list[str]]:
filter_options = _get_filter_options_default(game)
# The Overdrive difficulty only exists for spell practice, but we do not show any
# spell practice replays.
filter_options["Difficulty"].remove("Overdrive")
filter_options["difficulty"].remove("Overdrive")
return filter_options


Expand All @@ -99,9 +99,9 @@ def _get_filter_options_th16(game: Game) -> dict[str, list[str]]:
all_seasons.remove(None)
all_difficulties = [game.GetDifficultyName(d) for d in range(game.num_difficulties)]
return {
"Difficulty": all_difficulties,
"Character": all_characters,
"Season": all_seasons,
"difficulty": all_difficulties,
"character": all_characters,
"season": all_seasons,
}


Expand All @@ -114,9 +114,9 @@ def _get_filter_options_th17(game: Game) -> dict[str, list[str]]:
)
all_difficulties = [game.GetDifficultyName(d) for d in range(game.num_difficulties)]
return {
"Difficulty": all_difficulties,
"Character": all_characters,
"Goast": all_goasts,
"difficulty": all_difficulties,
"character": all_characters,
"goast": all_goasts,
}


Expand Down
Loading
Loading