generated from astariul/pytere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 Add doc hooks and custom javascript
- Loading branch information
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"""Module declaring the hooks for Mkdocs.""" | ||
|
||
import json | ||
import os | ||
|
||
from mkdocs.config.defaults import MkDocsConfig | ||
from mkdocs.structure.nav import Page | ||
|
||
|
||
def on_page_markdown(markdown: str, page: Page, config: MkDocsConfig, **kwargs) -> str: | ||
"""Function that runs before rendering the markdown. | ||
See https://www.mkdocs.org/dev-guide/plugins/#events for more details. | ||
Args: | ||
markdown (str): The markdown content of the page. | ||
page (Page): The page being rendered. | ||
config (MkDocsConfig): The configuration. | ||
**kwargs: Keywords arguments to pass to the given function. | ||
Returns: | ||
str: The updated markdown content. | ||
""" | ||
if page.file.src_uri == "leaderboard.md": | ||
lines = markdown.split("\n") | ||
entries = [] | ||
for line in lines: | ||
if line.startswith(">>>"): | ||
# This is a line with a path to a result file | ||
# -> parse it and extract the results | ||
kb_name, result_file_path = line[3:].split("|") | ||
|
||
with open(os.path.join(config.docs_dir, result_file_path), "r") as f: | ||
res = json.load(f) | ||
|
||
entries.append( | ||
{ | ||
"kb_name": kb_name, | ||
"score": res["overall_score"], | ||
"nwp": res["next_word_prediction"]["score"]["top3_accuracy"], | ||
"acp": res["auto_completion"]["score"]["top3_accuracy"], | ||
"acr": res["auto_correction"]["score"]["fscore"], | ||
} | ||
) | ||
|
||
# Sort according to the overall score | ||
entries.sort(reverse=True, key=lambda x: x["score"]) | ||
|
||
# Find the best scores to highlight | ||
best_score = max(entries, key=lambda x: x["score"])["score"] | ||
best_nwp = max(entries, key=lambda x: x["nwp"])["nwp"] | ||
best_acp = max(entries, key=lambda x: x["acp"])["acp"] | ||
best_acr = max(entries, key=lambda x: x["acr"])["acr"] | ||
|
||
# Replace the lines accordingly | ||
for i, line in enumerate(lines): | ||
if line.startswith(">>>"): | ||
e = entries.pop(0) | ||
|
||
score = f"{round(e['score'], 2):g}" | ||
nwp = f"{round(e['nwp'], 2):g}" | ||
acp = f"{round(e['acp'], 2):g}" | ||
acr = f"{round(e['acr'], 2):g}" | ||
|
||
# Highlight the best scores | ||
if e["score"] == best_score: | ||
score = f"**{score}**" | ||
if e["nwp"] == best_nwp: | ||
nwp = f"**{nwp}**" | ||
if e["acp"] == best_acp: | ||
acp = f"**{acp}**" | ||
if e["acr"] == best_acr: | ||
acr = f"**{acr}**" | ||
|
||
# Overwrite the line | ||
lines[i] = f"| {e['kb_name']} | {score} | {nwp} | {acp} | {acr} |" | ||
|
||
return "\n".join(lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
document$.subscribe(function() { | ||
var tables = document.querySelectorAll("article table:not([class])") | ||
tables.forEach(function(table) { | ||
new Tablesort(table) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,13 +39,17 @@ nav: | |
- Welcome: "index.md" | ||
- "usage.md" | ||
- "emulated_keyboard.md" | ||
- "emu_setup.md" | ||
- "how_testing_is_done.md" | ||
- "architecture.md" | ||
- "emu_setup.md" | ||
- "leaderboard.md" | ||
- Code reference: | ||
- "public_api.md" | ||
- "internals.md" | ||
|
||
hooks: | ||
- docs/hooks.py | ||
|
||
plugins: | ||
- search | ||
- mkdocstrings: | ||
|
@@ -64,3 +68,7 @@ extra: | |
|
||
extra_css: | ||
- css/mkdocstrings.css | ||
|
||
extra_javascript: | ||
- https://unpkg.com/[email protected]/dist/tablesort.min.js | ||
- javascripts/tablesort.js |