Implement category leaderboards
This commit is contained in:
parent
f3c0921728
commit
d7ee56609a
7 changed files with 134 additions and 16 deletions
|
@ -27,6 +27,16 @@ h1, h2 {
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
.centerHoriz {
|
||||
margin: auto;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.categoryLink {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.categoryBoard {
|
||||
font-weight: normal;
|
||||
text-align: left;
|
||||
}
|
|
@ -1 +1 @@
|
|||
tk_run_id,tk_run_runner,tk_run_verifier,tk_run_category_dashname,tk_run_date,tk_run_description,tk_run_link
|
||||
tk_run_id,tk_run_runner,tk_run_verifier,tk_run_duration,tk_run_category_dashname,tk_run_date,tk_run_description,tk_run_link
|
||||
|
|
|
|
@ -13,10 +13,12 @@ if len(categoriesOld.keys()) == 0:
|
|||
print("Add a category first (using scripts/add-category.py)")
|
||||
os._exit(1)
|
||||
|
||||
## End of: Check to see if there's at least one category ##
|
||||
|
||||
divider = "----------"
|
||||
|
||||
print(
|
||||
f"\nWe'll ask for the runner, verifier, category, run date, category, description of, and recording link of the new run.\n\n{divider}\n"
|
||||
f"\nWe'll ask for the runner, verifier, run duration (time), category, run date, category, description of, and recording link of the new run.\n\n{divider}\n"
|
||||
)
|
||||
|
||||
tk_run_id = 1
|
||||
|
@ -27,7 +29,23 @@ for id in existingRuns:
|
|||
tk_run_runner = input("Runner: ")
|
||||
tk_run_verifier = input("Verifier: ")
|
||||
|
||||
## End of: Check to see if there's at least one category ##
|
||||
## Handle input of tk_run_duration ##
|
||||
|
||||
doneDurationInput = False
|
||||
while not doneDurationInput:
|
||||
tk_run_duration = input("Duration (format - HH:MM:SS): ")
|
||||
values = tk_run_duration.split(":")
|
||||
if len(values) == 3:
|
||||
try:
|
||||
for value in values:
|
||||
test = float(value)
|
||||
doneDurationInput = True
|
||||
except:
|
||||
print("Invalid input!")
|
||||
else:
|
||||
print("Invalid input!")
|
||||
|
||||
## End of: Handle input of tk_run_duration ##
|
||||
|
||||
## Handle input of tk_run_category_dashname ##
|
||||
|
||||
|
@ -74,6 +92,7 @@ runDict = {
|
|||
"tk_run_id": tk_run_id,
|
||||
"tk_run_runner": tk_run_runner,
|
||||
"tk_run_verifier": tk_run_verifier,
|
||||
"tk_run_duration": tk_run_duration,
|
||||
"tk_run_category_dashname": tk_run_category_dashname,
|
||||
"tk_run_date": tk_run_date,
|
||||
"tk_run_description": tk_run_description,
|
||||
|
|
|
@ -4,6 +4,7 @@ from .. import file as util_file
|
|||
from .. import csv as util_csv
|
||||
import shutil
|
||||
import os
|
||||
import datetime
|
||||
|
||||
|
||||
def generate(templatedir, destinationdir, templateFilename):
|
||||
|
@ -14,13 +15,16 @@ def generate(templatedir, destinationdir, templateFilename):
|
|||
templateFilename -- the filename of the category template (always category.html)\n
|
||||
"""
|
||||
|
||||
runIdName = "tk_run_id"
|
||||
categoryIdName = "tk_category_dashname"
|
||||
runs = util_csv.dictReaderMultiRow("../csv/runs.csv", runIdName)
|
||||
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", categoryIdName)
|
||||
config = util_csv.dictReaderFirstRow("../csv/config.csv")
|
||||
|
||||
for category in categories:
|
||||
|
||||
path = f"{destinationdir}/{categories[category][categoryIdName]}"
|
||||
thisCategory = categories[category]
|
||||
path = f"{destinationdir}/{thisCategory[categoryIdName]}"
|
||||
currentDir = os.getcwd()
|
||||
|
||||
os.makedirs(path, exist_ok=True)
|
||||
|
@ -30,10 +34,69 @@ def generate(templatedir, destinationdir, templateFilename):
|
|||
f"{currentDir}/{path}/index.html",
|
||||
)
|
||||
|
||||
for key in categories[category]:
|
||||
util_file.replaceTextInFile(
|
||||
f"{path}/index.html", key, categories[category][key]
|
||||
)
|
||||
for key in thisCategory:
|
||||
util_file.replaceTextInFile(f"{path}/index.html", key, thisCategory[key])
|
||||
|
||||
for key in config.keys():
|
||||
util_file.replaceTextInFile(f"{path}/index.html", key, config[key])
|
||||
|
||||
## lk_leaderboard handler ##
|
||||
|
||||
runsInCategory = {}
|
||||
for run in runs:
|
||||
thisRun = runs[run]
|
||||
if (
|
||||
thisRun["tk_run_category_dashname"]
|
||||
== thisCategory["tk_category_dashname"]
|
||||
):
|
||||
runsInCategory[thisRun["tk_run_id"]] = thisRun
|
||||
|
||||
runDurationsInCategory = {}
|
||||
for run in runsInCategory:
|
||||
thisRun = runsInCategory[run]
|
||||
runDurationSplit = [
|
||||
float(value) for value in thisRun["tk_run_duration"].split(":")
|
||||
]
|
||||
|
||||
runDurationsInCategory[thisRun["tk_run_id"]] = datetime.timedelta(
|
||||
hours=runDurationSplit[0],
|
||||
minutes=runDurationSplit[1],
|
||||
seconds=runDurationSplit[2],
|
||||
)
|
||||
|
||||
sortedRunsInCategory = {
|
||||
runId: runDuration
|
||||
for runId, runDuration in sorted(
|
||||
runDurationsInCategory.items(), key=lambda item: item[1]
|
||||
)
|
||||
}
|
||||
|
||||
trimmedRunsInCategory = {}
|
||||
runnersRepresentedInCategory = []
|
||||
for run in sortedRunsInCategory:
|
||||
thisRun = runs[run]
|
||||
runner = thisRun["tk_run_runner"]
|
||||
if runner not in runnersRepresentedInCategory:
|
||||
trimmedRunsInCategory[thisRun["tk_run_id"]] = thisRun
|
||||
runnersRepresentedInCategory.append(runner)
|
||||
|
||||
place = 1
|
||||
lk_leaderboard = '<table class="categoryBoard centerHoriz">'
|
||||
for run in trimmedRunsInCategory:
|
||||
|
||||
thisRun = trimmedRunsInCategory[run]
|
||||
thisRunner = thisRun["tk_run_runner"]
|
||||
thisRunId = thisRun["tk_run_id"]
|
||||
thisLink = f"../../runs/{thisRunId}"
|
||||
thisDuration = str(runDurationsInCategory[thisRunId])
|
||||
thisDate = thisRun["tk_run_date"]
|
||||
|
||||
lk_leaderboard += f'<tr><th>{place}.</th><th>{thisRunner}</th><th><a href="{thisLink}">{thisDuration}</a></th><th>{thisDate}</th></tr>'
|
||||
place += 1
|
||||
lk_leaderboard += "</table>"
|
||||
|
||||
util_file.replaceTextInFile(
|
||||
f"{path}/index.html", "lk_leaderboard", lk_leaderboard
|
||||
)
|
||||
|
||||
## End of: lk_leaderboard handler ##
|
||||
|
|
|
@ -25,7 +25,8 @@ def generate(templatedir, destinationdir, templateFilename):
|
|||
tk_category_dashname = "tk_category_dashname"
|
||||
tk_category_name = "tk_category_name"
|
||||
|
||||
# lk_categories handler
|
||||
## lk_categories handler ##
|
||||
|
||||
for category in categories:
|
||||
|
||||
util_file.replaceTextInFile(
|
||||
|
@ -33,4 +34,7 @@ def generate(templatedir, destinationdir, templateFilename):
|
|||
"lk_categories",
|
||||
f'<a class="categoryLink" href="categories/{categories[category][tk_category_dashname]}">{categories[category][tk_category_name]}</a>lk_categories',
|
||||
)
|
||||
|
||||
util_file.replaceTextInFile(f"{destinationdir}/index.html", "lk_categories", "")
|
||||
|
||||
## End of: lk_categories handler ##
|
||||
|
|
|
@ -4,6 +4,7 @@ from .. import file as util_file
|
|||
from .. import csv as util_csv
|
||||
import shutil
|
||||
import os
|
||||
import datetime
|
||||
|
||||
|
||||
def generate(templatedir, destinationdir, templateFilename):
|
||||
|
@ -22,7 +23,8 @@ def generate(templatedir, destinationdir, templateFilename):
|
|||
|
||||
for run in runs:
|
||||
|
||||
path = f"{destinationdir}/{runs[run][runIdName]}"
|
||||
thisRun = runs[run]
|
||||
path = f"{destinationdir}/{thisRun[runIdName]}"
|
||||
currentDir = os.getcwd()
|
||||
|
||||
os.makedirs(path, exist_ok=True)
|
||||
|
@ -33,22 +35,25 @@ def generate(templatedir, destinationdir, templateFilename):
|
|||
)
|
||||
|
||||
tk_run_link = ""
|
||||
for key in runs[run]:
|
||||
util_file.replaceTextInFile(f"{path}/index.html", key, runs[run][key])
|
||||
for key in thisRun:
|
||||
util_file.replaceTextInFile(f"{path}/index.html", key, thisRun[key])
|
||||
if key == "tk_run_link":
|
||||
tk_run_link = runs[run][key]
|
||||
tk_run_link = thisRun[key]
|
||||
elif key == "tk_run_duration":
|
||||
tk_run_duration = thisRun[key]
|
||||
|
||||
for key in categories[runs[run]["tk_run_category_dashname"]]:
|
||||
for key in categories[thisRun["tk_run_category_dashname"]]:
|
||||
util_file.replaceTextInFile(
|
||||
f"{path}/index.html",
|
||||
key,
|
||||
categories[runs[run]["tk_run_category_dashname"]][key],
|
||||
categories[thisRun["tk_run_category_dashname"]][key],
|
||||
)
|
||||
|
||||
for key in config.keys():
|
||||
util_file.replaceTextInFile(f"{path}/index.html", key, config[key])
|
||||
|
||||
# lk_run_link handler
|
||||
## lk_run_link handler ##
|
||||
|
||||
if tk_run_link == "":
|
||||
util_file.replaceTextInFile(
|
||||
f"{path}/index.html", "lk_run_link", "No recording available"
|
||||
|
@ -59,3 +64,19 @@ def generate(templatedir, destinationdir, templateFilename):
|
|||
"lk_run_link",
|
||||
f'<a class="runLink" href="{tk_run_link}">Run recording</a>',
|
||||
)
|
||||
|
||||
## End of: lk_run_link handler ##
|
||||
|
||||
## lk_run_duration handler ##
|
||||
|
||||
runDurationSplit = [float(value) for value in tk_run_duration.split(":")]
|
||||
lk_run_duration = datetime.timedelta(
|
||||
hours=runDurationSplit[0],
|
||||
minutes=runDurationSplit[1],
|
||||
seconds=runDurationSplit[2],
|
||||
)
|
||||
util_file.replaceTextInFile(
|
||||
f"{path}/index.html", "lk_run_duration", str(lk_run_duration)
|
||||
)
|
||||
|
||||
## End of: lk_run_duration handler ##
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<body>
|
||||
<h1><a href="../../">tk_game_name</a> - tk_run_runner's run</h1>
|
||||
<h2><a href="../../categories/tk_category_dashname">tk_category_name<a></h2>
|
||||
<p>lk_run_duration</p>
|
||||
<p>Verified by <strong>tk_run_verifier</strong></p>
|
||||
<p>Took place on <strong>tk_run_date</strong></p>
|
||||
lk_run_link
|
||||
|
|
Loading…
Reference in a new issue