Skip to content

Commit f038165

Browse files
authored
Change landing page to be profiling-results (#16)
* Force index to redirect to profiling page * Fix API typo * Sort profiling results by newest first, and allow clickable commit shas * Insert profiling lookup directly into index page * Write lookup table and plots to hidden rst files that are then included * Apply suggestions from code review
1 parent 2535dcb commit f038165

File tree

8 files changed

+84
-92
lines changed

8 files changed

+84
-92
lines changed

source/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# List of patterns, relative to source directory, that match files and
4444
# directories to ignore when looking for source files.
4545
# This pattern also affects html_static_path and html_extra_path.
46-
exclude_patterns = []
46+
exclude_patterns = ["_.*rst"]
4747

4848

4949
# -- Options for HTML output -------------------------------------------------
@@ -52,6 +52,7 @@
5252
# a list of builtin themes.
5353
#
5454
html_theme = "alabaster"
55+
master_doc = "documentation"
5556

5657
# Add any paths that contain custom static files (such as style sheets) here,
5758
# relative to this directory. They are copied after the builtin static files,

source/developers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The build can be triggered by passing the ``website_builder/builder.py`` script
2727

2828
.. code-block:: bash
2929
30-
python website_builder/builder.py
30+
python website_builder/builder.py <results-branch>
3131
3232
You may pass the ``-h`` or ``--help`` flags for the command line help, which provides a few convenience wrappers for the :class:`builder.Builder` class that manages the website build.
3333
Configuration options include specifying a particular directory to place the built website into, forcing the removal of any previously (failed or completed) builds, and toggling the structure of static HTML files from profiling outputs into a flat directory or nested directory structure.

source/documentation.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.. TLO Model: Profiling documentation master file, created by
2+
sphinx-quickstart on Thu Aug 17 13:46:22 2023.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to the TLO Model: Profiling Documentation
7+
=================================================
8+
9+
.. toctree::
10+
:maxdepth: 1
11+
:caption: Contents:
12+
13+
index
14+
run-statistics
15+
developers
16+
api-reference
17+
18+
This is a repository for storing profiling outputs from the TLOmodel, an epidemiology modelling framework for the Thanzi la Onse project.
19+
20+
Running Simulations with the Model
21+
----------------------------------
22+
23+
For more information about setting up, using, and running simulations using the model, `please see the main repository <https://github.com/UCL/TLOmodel>`_ and information provided there.
24+
25+
View the Profiling Results
26+
--------------------------
27+
28+
Profiling results are hosted on `GitHub pages <http://github-pages.ucl.ac.uk/TLOmodel-profiling>`_ and are built using ``sphinx`` and some custom Python scripts to process the results data.
29+
30+
* :doc:`Lookup table for profiling runs <index>`
31+
* :doc:`Summary page for captured run statistics <run-statistics>`
32+
33+
Developer Documentation
34+
-----------------------
35+
36+
For developer information about this repository; such as how the repository is organised, how the website is built, and documentation for the functions and scripts, :doc:`please see the online documentation <developers>`.
37+
38+
API Reference
39+
-------------
40+
41+
For details and usage examples of the code in this repository, please see the :doc:`API reference <api-reference>` page.
42+
43+
Indices and tables
44+
==================
45+
46+
* :ref:`genindex`
47+
* :ref:`search`

source/index.rst

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,6 @@
1-
.. TLO Model: Profiling documentation master file, created by
2-
sphinx-quickstart on Thu Aug 17 13:46:22 2023.
3-
You can adapt this file completely to your liking, but it should at least
4-
contain the root `toctree` directive.
1+
Profiling Runs: Lookup Page
2+
===========================
53

6-
Welcome to the TLO Model: Profiling Documentation
7-
=================================================
4+
Profiling results are listed from newest to oldest, based on the timestamp recorded when the profiling run was *triggered*.
85

9-
.. toctree::
10-
:maxdepth: 1
11-
:caption: Contents:
12-
13-
profiling
14-
run-statistics
15-
developers
16-
api-reference
17-
18-
This is a repository for storing profiling outputs from the TLOmodel, an epidemiology modelling framework for the Thanzi la Onse project.
19-
20-
Running Simulations with the Model
21-
----------------------------------
22-
23-
For more information about setting up, using, and running simulations using the model, `please see the main repository <https://github.com/UCL/TLOmodel>`_ and information provided there.
24-
25-
View the Profiling Results
26-
--------------------------
27-
28-
Profiling results are hosted on `GitHub pages <http://github-pages.ucl.ac.uk/TLOmodel-profiling>`_ and are built using ``sphinx`` and some custom Python scripts to process the results data.
29-
30-
* :doc:`Lookup table for profiling runs <profiling>`
31-
* :doc:`Summary page for captured run statistics <run-statistics>`
32-
33-
Developer Documentation
34-
-----------------------
35-
36-
For developer information about this repository; such as how the repository is organised, how the website is built, and documentation for the functions and scripts, :doc:`please see the online documentation <developers>`.
37-
38-
API Reference
39-
-------------
40-
41-
For details and usage examples of the code in this repository, please see the :doc:`API reference <api-reference>` page.
42-
43-
Indices and tables
44-
==================
45-
46-
* :ref:`genindex`
47-
* :ref:`search`
6+
.. include:: _profiling_table.rst

source/profiling.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.

source/run-statistics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Run Statistics
22
==============
33

4-
<<<MATCH_PATTERN_FOR_RUN_STATS_PLOTS>>>
4+
.. include:: _stats_plots.rst

website_builder/builder.py

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from profiling_statistics import STATS
1616
from utils import (
1717
md_title_format,
18-
replace_in_file,
1918
rst_title_format,
2019
safe_remove_dir,
2120
write_image_link,
@@ -26,12 +25,6 @@
2625
"Build the website deployment for the profiling results, "
2726
"placing the resulting files in the build directory."
2827
)
29-
# This pattern, where it appears in the template files,
30-
# will be replaced with the profiling runs lookup table.
31-
PROFILING_TABLE_MATCH_STRING = "<<<MATCH_PATTERN_FOR_MARKDOWN_TABLE_INSERT>>>"
32-
# This pattern, where it appears in the template files,
33-
# will be replaced with the plots for statistics that are tracked across runs
34-
RUN_PLOTS_MATCH_STRING = "<<<MATCH_PATTERN_FOR_RUN_STATS_PLOTS>>>"
3528

3629
# These columns need to be computed from the statistics that are read in
3730
# from the statistics files on the source branch
@@ -52,7 +45,7 @@
5245
class Builder:
5346
"""
5447
Handles the construction of the gh-pages website, as per the process detailed
55-
in http://github-pages.ucl.ac.uk/TLOmodel-profiling/index.html.
48+
in http://github-pages.ucl.ac.uk/TLOmodel-profiling.
5649
5750
Build options are configured on initialisation of a class instance;
5851
members with default values can be passed as keyword arguments to the
@@ -122,22 +115,17 @@ def static_folder(self) -> Path:
122115
@property
123116
def profiling_table_file(self) -> Path:
124117
"""
125-
The file containing the
126-
<<<MATCH_PATTERN_FOR_MARKDOWN_TABLE_INSERT>>>,
127-
128-
which is where the profiling results lookup table will be inserted.
118+
The file into which the profiling results lookup table
119+
will be inserted.
129120
"""
130-
return self.staging_dir / "profiling.rst"
121+
return self.staging_dir / "_profiling_table.rst"
131122

132123
@property
133124
def statistics_plots_file(self) -> Path:
134125
"""
135-
The file containing the
136-
<<<MATCH_PATTERN_FOR_RUN_STATS_PLOTS>>>,
137-
138-
which is where the run statistics plots will be inserted.
126+
The file into which the run statistics plots will be inserted.
139127
"""
140-
return self.staging_dir / "run-statistics.rst"
128+
return self.staging_dir / "_stats_plots.rst"
141129

142130
@property
143131
def plot_folder(self) -> Path:
@@ -298,7 +286,7 @@ def format_as_title(self, text: str) -> str:
298286
"""
299287
title_writer: Callable[[str], str]
300288
if self.website_plaintext_format == "rst":
301-
title_writer = lambda t: rst_title_format(t, "-")
289+
title_writer = rst_title_format
302290
elif format == "md":
303291
title_writer = md_title_format
304292
return title_writer(text)
@@ -355,14 +343,19 @@ def parse_stats_files_to_df(self) -> None:
355343
# Can probably do this with .apply() - revisit
356344
for index, row in self.df.iterrows():
357345
stats_file = row["stats_file"]
358-
self.df.loc[
359-
index, STATS.values("dataframe_col_name")
360-
] = STATS.read_from_file(file=stats_file, branch=self.source_branch)
346+
self.df.loc[index, STATS.values("dataframe_col_name")] = (
347+
STATS.read_from_file(file=stats_file, branch=self.source_branch)
348+
)
361349

362350
# Set the commit field from the sha field
363-
self.df["Commit"] = self.df["sha"].apply(
364-
lambda sha: REPO.git.rev_parse("--short", sha)
365-
)
351+
def sha_to_clickable(sha: str) -> str:
352+
""" """
353+
short_sha = REPO.git.rev_parse("--short", sha)
354+
site = "https://github.com/UCL/TLOmodel/commit/"
355+
as_link = write_page_link(site + sha, link_text=short_sha)
356+
return as_link
357+
358+
self.df["Commit"] = self.df["sha"].apply(sha_to_clickable)
366359

367360
return
368361

@@ -372,17 +365,17 @@ def write_profiling_lookup_table(self) -> str:
372365
by extracting the relevant columns from the DataFrame.
373366
"""
374367
if self.website_plaintext_format == "rst":
375-
lookup_table = self.df[self.cols_for_lookup_table].to_markdown(
376-
index=False, tablefmt="grid"
368+
lookup_table = (
369+
self.df[self.cols_for_lookup_table]
370+
.iloc[::-1]
371+
.to_markdown(index=False, tablefmt="grid")
377372
)
378373
else:
379374
lookup_table = self.df[self.cols_for_lookup_table].to_markdown(index=False)
380375

381-
# Write the lookup page into the templated file.
382-
replace_in_file(
383-
self.profiling_table_file, PROFILING_TABLE_MATCH_STRING, lookup_table
384-
)
385-
376+
# Write table to the corresponding file
377+
with open(self.profiling_table_file, "w") as f:
378+
f.write(lookup_table)
386379
return
387380

388381
def write_run_stats_page(self) -> None:
@@ -400,11 +393,9 @@ def write_run_stats_page(self) -> None:
400393
)
401394
stat_page_text += "\n"
402395

403-
# Inject the text into the statistics plot webpage file
404-
replace_in_file(
405-
self.statistics_plots_file, RUN_PLOTS_MATCH_STRING, stat_page_text
406-
)
407-
396+
# Write plots to the corresponding file
397+
with open(self.statistics_plots_file, "w") as f:
398+
f.write(stat_page_text)
408399
return
409400

410401

website_builder/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def write_page_link(
131131
elif relative_to is not None:
132132
hyperlink = os.path.relpath(link, relative_to)
133133
else:
134-
hyperlink = str(hyperlink)
134+
hyperlink = str(link)
135135
if format == "rst":
136136
return f"`{link_text} <{hyperlink}>`__"
137137
elif format == "md":

0 commit comments

Comments
 (0)