Skip to content

Commit

Permalink
Updated filenaming, documentation and filenames passed to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lchipchase authored and Kartheyan committed Apr 13, 2024
1 parent 65c6d88 commit d4102a2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions docs-source/source/usage/outcomevisualisation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ We provide a way to visualise the results using the class :py:class:`~pabutools.
# The visualiser takes the profile, instance, and outcome as arguments
visualiser = MESVisualiser(profile, instance, outcome)
# summary_filename and round_analysis_filename are optional and default to summary.html and round_analysis.html respectively
visualiser.render("./{path_to_output_file}/", "{summary_page_filename}", "{round_analysis_filename}")
# name is optional and defaults to the empty string
visualiser.render("./{path_to_output_file}/", name="{name}")
The visualisations will be saved with the filenames summary.html and round_analysis.html respectively in the specified path. These work as standalone HTML files, and must be stored in the same directory to ensure the links between different pages work correctly.
The visualisations will be saved with the filenames {name}_summary.html and {name}_round_analysis.html respectively in the specified path. These work as standalone HTML files, and must be stored in the same directory to ensure the links between different pages work correctly.
6 changes: 3 additions & 3 deletions docs/_sources/usage/outcomevisualisation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ We provide a way to visualise the results using the class :py:class:`~pabutools.
# The visualiser takes the profile, instance, and outcome as arguments
visualiser = MESVisualiser(profile, instance, outcome)
# summary_filename and round_analysis_filename are optional and default to summary.html and round_analysis.html respectively
visualiser.render("./{path_to_output_file}/", "{summary_page_filename}", "{round_analysis_filename}")
# name is optional and defaults to the empty string
visualiser.render("./{path_to_output_file}/", name="{name}")
The visualisations will be saved with the filenames summary.html and round_analysis.html respectively in the specified path. These work as standalone HTML files, and must be stored in the same directory to ensure the links between different pages work correctly.
The visualisations will be saved with the filenames {name}_summary.html and {name}_round_analysis.html respectively in the specified path. These work as standalone HTML files, and must be stored in the same directory to ensure the links between different pages work correctly.
6 changes: 3 additions & 3 deletions docs/usage/outcomevisualisation.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ <h2>Method of Equal Shares<a class="headerlink" href="#method-of-equal-shares" t
<span class="c1"># The visualiser takes the profile, instance, and outcome as arguments</span>
<span class="n">visualiser</span> <span class="o">=</span> <span class="n">MESVisualiser</span><span class="p">(</span><span class="n">profile</span><span class="p">,</span> <span class="n">instance</span><span class="p">,</span> <span class="n">outcome</span><span class="p">)</span>

<span class="c1"># summary_filename and round_analysis_filename are optional and default to summary.html and round_analysis.html respectively</span>
<span class="n">visualiser</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="s2">&quot;./</span><span class="si">{path_to_output_file}</span><span class="s2">/&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{summary_page_filename}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{round_analysis_filename}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="c1"># name is optional and defaults to the empty string</span>
<span class="n">visualiser</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="s2">&quot;./</span><span class="si">{path_to_output_file}</span><span class="s2">/&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{name}</span><span class="s2">&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>The visualisations will be saved with the filenames summary.html and round_analysis.html respectively in the specified path. These work as standalone HTML files, and must be stored in the same directory to ensure the links between different pages work correctly.</p>
<p>The visualisations will be saved with the filenames {name}_summary.html and {name}_round_analysis.html respectively in the specified path. These work as standalone HTML files, and must be stored in the same directory to ensure the links between different pages work correctly.</p>
</section>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="./round_analysis.html">Round By Round</a>
<a class="nav-link" href="./{{name}}_round_analysis.html">Round By Round</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">Pabutools</a>
Expand Down Expand Up @@ -514,7 +514,7 @@ <h2>Summary Table</h2>
<tr class='hidden-row' id='hidden-{{ round.id }}'>
<td colspan=7>
<div style='text-align: left'>
<b>Round Analysis:</b><a href='round_analysis.html?projectId={{ round.id }}'> Click Me!</a> <br>
<b>Round Analysis:</b><a href='{{name}}_round_analysis.html?projectId={{ round.id }}'> Click Me!</a> <br>
<b>Description:</b> {{ projects[round.id]["description"] }} <br>
<b>Categories:</b> <br>
{% for category in projects[round.id]["categories"] %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<body>
<header>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="./summary.html">Summary</a>
<a class="navbar-brand" href="./{{name}}_summary.html">Summary</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
Expand Down
14 changes: 7 additions & 7 deletions pabutools/visualisation/visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,16 @@ def _calculate(self):
round["voter_flow"] = voter_flow_matrix(self.instance, self.profile)
self._calculate_pie_charts(projectVotes)

def render(self, output_folder_path, summary_filename="summary.html", round_by_round_filename="round_analysis.html",):
def render(self, output_folder_path, name=""):
"""
Render the visualisation.
Parameters
----------
output_folder_path : str
The path to the folder where the visualisation will be saved.
summary_filename : str, optional
The name of the summary file. The default is "summary.html".
round_by_round_filename : str, optional
The name of the round by round file. The default is "round_analysis.html".
name : str, optional
The prefix of the output files. The default is "".
Returns
-------
Expand All @@ -403,6 +401,7 @@ def render(self, output_folder_path, summary_filename="summary.html", round_by_r
spent=total_cost(p for p in self.instance if p.name in self.outcome),
budget=self.instance.meta["budget"],
total_votes=self.instance.meta["num_votes"],
name=name
)

# Page Summary
Expand All @@ -416,12 +415,13 @@ def render(self, output_folder_path, summary_filename="summary.html", round_by_r
spent=total_cost(p for p in self.instance if p.name in self.outcome),
budget=self.instance.meta["budget"],
total_votes=self.instance.meta["num_votes"],
name=name
)
if not os.path.exists(output_folder_path):
os.makedirs(output_folder_path)
with open(f"{output_folder_path}/{round_by_round_filename}", "w", encoding="utf-8") as o:
with open(f"{output_folder_path}/{name}_round_analysis.html", "w", encoding="utf-8") as o:
o.write(round_analysis_page_output)
with open(f"{output_folder_path}/{summary_filename}", "w", encoding="utf-8") as o:
with open(f"{output_folder_path}/{name}_summary.html", "w", encoding="utf-8") as o:
o.write(summary_page_output)


Expand Down

0 comments on commit d4102a2

Please sign in to comment.