Tutorial 3: Playing with more than one district¶
Until now, we limited th examples to one-district systems. But in the real world, systems contains multiple divisions. In this tutorial a new type of node will be introduced: the group of districts or nodes.
UK - General election (complete schema)¶
Let’s go back to the UK - General election (Caerfyrddin) tutorial. Then, we defined the system for just one constituency. Now, we will include all constituencies:
Create a group of nodes, and put our constituency (Caerfyrddin) into its divisions (candidates are not shown):
1name: 2024 UK General election 2type: group 3divisions: 4- name: Caerfyrddin 5 method: first_past_the_post
Add the remaining 649 constituencies:
1name: 2024 UK General election 2type: group 3divisions: 4- name: Amber Valley 5 method: first_past_the_post 6... 7- name: Caerfyrddin 8 method: first_past_the_post 9... 10- name: West Tyrone 11 method: first_past_the_post
Since all the constituencies share the same method, it will be easier if we define it once for all the divisions:
1name: 2024 UK General election 2type: group 3method: first_past_the_post 4divisions: 5- name: Amber Valley 6... 7- name: Caerfyrddin 8... 9- name: West Tyrone
Now, all the constituencies will inherit the method defined by its parent. There are other properties that are inherited by children (see
NodeContext).If we want to get an aggregated result (for example, get a result grouped by parties), a criterion can be added to the root node:
1name: 2024 UK General election 2type: group 3method: first_past_the_post 4# enable aggregated result 5aggregate: yes 6# group seats by parties 7groupby: "alliance" 8divisions: 9- name: Amber Valley 10... 11- name: Caerfyrddin 12... 13- name: West Tyrone 14...
Aggregated results can be controled by using the properties
aggregateandgroupby.
Spain - Andalusian regional election¶
Andalusian Parliament electoral system uses 8 districts, one per province. Each distrct apportions a number of seats using the highest averages method with d'Hondt divisors. Candidates with less votes than the 3% of total valid votes in the district are excluded from the apportionment for that district.
The system for the Spanish Parliament would be exactly the same, but with 52 leaf districts.
1name: Parlamento Andaluz 2015
2type: group
3method: highest_averages
4method_params:
5 divisor_f: dhondt
6exclude: "valid_votes < 3%"
7divisions:
8- name: Almería
9 seats: 12
10- name: Cádiz
11 seats: 15
12- name: Córdoba
13 seats: 12
14- name: Granada
15 seats: 13
16- name: Huelva
17 seats: 11
18- name: Jaén
19 seats: 11
20- name: Málaga
21 seats: 17
22- name: Sevilla
23 seats: 18
Since include and exclude restrictions are inherited by chldren, the threshold is defined once by the root node, but applied at each province. A restriction that does not reference to node will use the district where it is been used as reference.