Skip to content

Commit

Permalink
Fixes for classes deriving from Counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-Rey committed Jul 20, 2023
1 parent 763013d commit f1699bd
Show file tree
Hide file tree
Showing 19 changed files with 309 additions and 20 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ when it comes to PB data.

## Installation

Ultimately, the goal is to host this library on pip. For now, use the
source code provided here.
The installation should be as easy as:
```shell
pip3 install pabutools
```

## Documentation

Expand Down
18 changes: 17 additions & 1 deletion docs/_modules/pabutools/election/profile/approvalprofile.html
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ <h1>Source code for pabutools.election.profile.approvalprofile</h1><div class="h
<span class="sd"> The type that the ballots are validated against. If `ballot_validation` is `True` and a ballot of a type</span>
<span class="sd"> that is not a subclass of `ballot_type` is added, an exception will be raised.</span>
<span class="sd"> Defaults to `FrozenApprovalBallot`.</span>
<span class="sd"> profile: :py:class:`~pabutools.election.profile.approvalprofile.ApprovalProfile`, optional</span>
<span class="sd"> A profile used to initialise the multiprofile. Some metadata are taken from the profile if they are not</span>
<span class="sd"> specified in the constructor.</span>
<span class="sd"> legal_min_length : int, optional</span>
<span class="sd"> The minimum length of an approval ballot per the rules of the election.</span>
<span class="sd"> Defaults to `None`.</span>
Expand Down Expand Up @@ -730,7 +733,20 @@ <h1>Source code for pabutools.election.profile.approvalprofile</h1><div class="h
<span class="nb">setattr</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">inner</span><span class="p">)</span>

<span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
<span class="n">wrap_method_closure</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></div>
<span class="n">wrap_method_closure</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">__reduce__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">,</span> <span class="p">(</span>
<span class="nb">dict</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">instance</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ballot_validation</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ballot_type</span><span class="p">,</span>
<span class="kc">None</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_min_length</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_max_length</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_min_cost</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_max_cost</span><span class="p">,</span>
<span class="p">)</span></div>


<span class="n">ApprovalMultiProfile</span><span class="o">.</span><span class="n">_wrap_methods</span><span class="p">(</span>
Expand Down
18 changes: 17 additions & 1 deletion docs/_modules/pabutools/election/profile/cardinalprofile.html
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@ <h1>Source code for pabutools.election.profile.cardinalprofile</h1><div class="h
<span class="sd"> The type that the ballots are validated against. If `ballot_validation` is `True` and a ballot of a type</span>
<span class="sd"> that is not a subclass of `ballot_type` is added, an exception will be raised.</span>
<span class="sd"> Defaults to `CardinalBallot`.</span>
<span class="sd"> profile: :py:class:`~pabutools.election.profile.cardinalprofile.CardinalProfile`, optional</span>
<span class="sd"> A profile used to initialise the multiprofile. Some metadata are taken from the profile if they are not</span>
<span class="sd"> specified in the constructor.</span>
<span class="sd"> legal_min_length : int, optional</span>
<span class="sd"> The minimum number of projects a voter needs to assign a score to per the rules of the election.</span>
<span class="sd"> Defaults to `None`.</span>
Expand Down Expand Up @@ -655,7 +658,20 @@ <h1>Source code for pabutools.election.profile.cardinalprofile</h1><div class="h
<span class="nb">setattr</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">inner</span><span class="p">)</span>

<span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
<span class="n">wrap_method_closure</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></div>
<span class="n">wrap_method_closure</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">__reduce__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">,</span> <span class="p">(</span>
<span class="nb">dict</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">instance</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ballot_validation</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ballot_type</span><span class="p">,</span>
<span class="kc">None</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_min_length</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_max_length</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_min_score</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_max_score</span><span class="p">,</span>
<span class="p">)</span></div>


<span class="n">CardinalMultiProfile</span><span class="o">.</span><span class="n">_wrap_methods</span><span class="p">(</span>
Expand Down
21 changes: 19 additions & 2 deletions docs/_modules/pabutools/election/profile/cumulativeprofile.html
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ <h1>Source code for pabutools.election.profile.cumulativeprofile</h1><div class=
<span class="sd"> The type that the ballots are validated against. If `ballot_validation` is `True` and a ballot of a type</span>
<span class="sd"> that is not a subclass of `ballot_type` is added, an exception will be raised.</span>
<span class="sd"> Defaults to `FrozenCumulativeBallot`.</span>
<span class="sd"> profile: :py:class:`~pabutools.election.profile.cumulativeprofile.CumulativeProfile`, optional</span>
<span class="sd"> A profile used to initialise the multiprofile. Some metadata are taken from the profile if they are not</span>
<span class="sd"> specified in the constructor.</span>
<span class="sd"> legal_min_length : int, optional</span>
<span class="sd"> The minimum number of projects a voter needs to assign a score to per the rules of the election.</span>
<span class="sd"> Defaults to `None`.</span>
Expand Down Expand Up @@ -698,8 +701,22 @@ <h1>Source code for pabutools.election.profile.cumulativeprofile</h1><div class=
<span class="nb">setattr</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">inner</span><span class="p">)</span>

<span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
<span class="n">wrap_method_closure</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></div>

<span class="n">wrap_method_closure</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">__reduce__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">,</span> <span class="p">(</span>
<span class="nb">dict</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">instance</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ballot_validation</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ballot_type</span><span class="p">,</span>
<span class="kc">None</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_min_length</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_max_length</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_min_score</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_max_score</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_min_total_score</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_max_total_score</span><span class="p">,</span>
<span class="p">)</span></div>

<span class="n">CumulativeMultiProfile</span><span class="o">.</span><span class="n">_wrap_methods</span><span class="p">(</span>
<span class="p">[</span>
Expand Down
17 changes: 15 additions & 2 deletions docs/_modules/pabutools/election/profile/ordinalprofile.html
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ <h1>Source code for pabutools.election.profile.ordinalprofile</h1><div class="hi
<span class="sd"> The type that the ballots are validated against. If `ballot_validation` is `True` and a ballot of a type</span>
<span class="sd"> that is not a subclass of `ballot_type` is added, an exception will be raised.</span>
<span class="sd"> Defaults to `ForzenOrdinalBallot`.</span>
<span class="sd"> profile: :py:class:`~pabutools.election.profile.ordinalprofile.OrdinalProfile`, optional</span>
<span class="sd"> A profile used to initialise the multiprofile. Some metadata are taken from the profile if they are not</span>
<span class="sd"> specified in the constructor.</span>
<span class="sd"> legal_min_length : int, optional</span>
<span class="sd"> The minimum length of an ordinal ballot per the rules of the election.</span>
<span class="sd"> Defaults to `None`.</span>
Expand Down Expand Up @@ -551,8 +554,18 @@ <h1>Source code for pabutools.election.profile.ordinalprofile</h1><div class="hi
<span class="nb">setattr</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">inner</span><span class="p">)</span>

<span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
<span class="n">wrap_method_closure</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></div>

<span class="n">wrap_method_closure</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">__reduce__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">,</span> <span class="p">(</span>
<span class="nb">dict</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">instance</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ballot_validation</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ballot_type</span><span class="p">,</span>
<span class="kc">None</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_min_length</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">legal_max_length</span><span class="p">,</span>
<span class="p">)</span></div>

<span class="n">OrdinalMultiProfile</span><span class="o">.</span><span class="n">_wrap_methods</span><span class="p">(</span>
<span class="p">[</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ <h1>Source code for pabutools.election.satisfaction.satisfactionmeasure</h1><div
<span class="sd"> -------</span>
<span class="sd"> int</span>
<span class="sd"> The multiplicity of the satisfaction measure.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="o">...</span></div>
<span class="sd"> &quot;&quot;&quot;</span></div>

<div class="viewcode-block" id="GroupSatisfactionMeasure.total_satisfaction"><a class="viewcode-back" href="../../../../reference/election/satisfaction.html#pabutools.election.satisfaction.satisfactionmeasure.GroupSatisfactionMeasure.total_satisfaction">[docs]</a> <span class="k">def</span> <span class="nf">total_satisfaction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">projects</span><span class="p">:</span> <span class="n">Iterable</span><span class="p">[</span><span class="n">Project</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">Number</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
Expand Down
Loading

0 comments on commit f1699bd

Please sign in to comment.