Skip to content

Commit

Permalink
Election Day: Update open data documentation and add missing field.
Browse files Browse the repository at this point in the history
TYPE: Bugfix
LINK: OGC-485
  • Loading branch information
msom authored Jun 4, 2024
1 parent b13e478 commit 6514bf2
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/onegov/election_day/models/election_compound/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ def has_results(self) -> bool:

return False

@property
def elected_candidates(self) -> list[tuple[str, str]]:
""" Returns the first and last names of the elected candidates. """

result = []
for election in self.elections:
result.extend(election.elected_candidates)

return result

@property
def relationships_for_historical_party_results(
self
Expand Down
20 changes: 17 additions & 3 deletions src/onegov/election_day/static/docs/api/open_data_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ Die auf der Startseite und den Archivseiten dargestellten Ergebnisse sind im JSO

Name|Beschreibung
---|---
`type`|`election` für Wahlen, `vote` für Abstimmungen.
`type`|`election` für Wahlen, `election_compound` für verbundene Wahlen, `vote` für Abstimmungen.
`title`|Ein Objekt mit den übersetzten Titeln.
`date`|Das Datum (ISO 8601).
`domain`|Einflussbereich (Bund, Kanton, ...).
`url`|Ein Link zur Detailansicht.
`completed`|Wahr, falls die Abstimmung oder Wahl abgeschlossen ist.
`progress`|Ein Objekt, welches die Anzahl ausgezählter Gemeinden (`counted`) und die Gesamtzahl an Gemeinden (`total`) enthält.

`progress`|Ein Objekt, welches die Anzahl ausgezählter Gemeinden/Wahlen (`counted`) und die Gesamtzahl an Gemeinden/Wahlen (`total`) enthält.
`last_modified`|Zeitpunkt der letzten Änderung (ISO 8601).
`turnout`|Stimm-/Wahlbeteiligung in Prozent.

Abstimmungsresultate enthalten die folgenden zusätzlichen Informationen:

Expand All @@ -57,6 +58,19 @@ Name|Beschreibung
`nays_percentage`|Nein-Stimmen in Prozent.
`local` (*optional*)|Eidgenössische und kantonale Abstimmungen innerhalb kommunaler Instanzen können zusätzlich die Resultate dieser Gemeinde enthalten als zusätzliches Objekt mit den Feldern `answer`, `yeas_percentage` and `nays_percentage`.

Wahlresultate enthalten die folgenden zusätzlichen Informationen:

Name|Beschreibung
---|---
`elected`|Liste mit den gewählten Kandidierenden.

Verbundene Wahlen enthalten die folgenden zusätzlichen Informationen:

Name|Beschreibung
---|---
`elected`|Liste mit den gewählten Kandidierenden.
`elections`|Liste mit Links zu den Wahlen.

2 Wahlresultate
---------------

Expand Down
19 changes: 17 additions & 2 deletions src/onegov/election_day/static/docs/api/open_data_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ The summarized results displayed at the home page (only the results of latest vo

Name|Description
---|---
`type`|`election` for elections, `vote` for votes.
`type`|`election` for elections, `election_compound` for election compounds, `vote` for votes.
`title`|An object containing the translated titles.
`date`|The date (ISO 8601).
`domain`|The domain of influence (federation, canton, ...).
`url`|A link to the detailed view.
`completed`|True, if the vote or election is completed.
`progress`|An object containing the number already counted municipalities (`counted`) and the total number of municipalities (`total`).
`progress`|An object containing the number already counted municipalities/elections (`counted`) and the total number of municipalities/elections (`total`).
`last_modified`|Last time, the data has changed (ISO 8601).
`turnout`|Voter turnout in per cent.

Vote results contain the following additional information:

Expand All @@ -56,6 +58,19 @@ Name|Description
`nays_percentage`|Nays percentage.
`local` (*optional*)|Federal and cantonal votes within a communal instance may contain additionally the results of the municipality in the form of an object with `answer`, `yeas_percentage` and `nays_percentage`.

Election results contain the following additional information:

Name|Description
---|---
`elected`|A list with the elected candidates.

Election compound results contain the following additional information:

Name|Description
---|---
`elected`|A list with the elected candidates.
`elections`|A list with links to the elections.

2 Election results
------------------

Expand Down
19 changes: 17 additions & 2 deletions src/onegov/election_day/static/docs/api/open_data_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ Les résultats synthétisés affichés sur la page d'accueil (seuls les résulta

Nom|Description
---|---
`type`|`election` pour les élections, `vote` pour les votations.
`type`|`election` pour les élections, `election_compound` pour les composantes des élections, `vote` pour les votations.
`title`|Un objet contenant les titres traduits.
`date`|La date (ISO 8601).
`domain`|Le domaine d'influence (fédération, canton, ...).
`url`|Un lien vers la vue détaillée.
`completed`|True, si le vote ou l'élection est terminé.
`progress`|Un objet contenant le nombre de municipalités déjà comptées (`counted`) et le nombre total de municipalités (`total`).
`progress`|Un objet contenant le nombre de municipalités/élections déjà comptées (`counted`) et le nombre total de municipalités/élections (`total`).
`last_modified`|La dernière fois que les données ont changé (ISO 8601).
`turnout`|Pourcentage de participation.

Les résultats de la votation contiennent les informations supplémentaires suivantes :

Expand All @@ -56,6 +58,19 @@ Nom|Description
`nays_percentage`|Pourcentage de non.
`local` (*optional*)|Federal and cantonal votes within a communal instance may contain additionally the results of the municipality in the form of an object with `answer`, `yeas_percentage` and `nays_percentage`.

Les résultats des élections contiennent les informations supplémentaires suivantes :

Nom|Description
---|---
`elected`|Une liste des candidats élus.

Les résultats des élections contiennent les informations supplémentaires suivantes :

Nom|Description
---|---
`elected`|Une liste des candidats élus.
`elections`|Une liste avec des liens vers les élections.


2 Résultats des élections
-------------------------
Expand Down
18 changes: 16 additions & 2 deletions src/onegov/election_day/static/docs/api/open_data_it.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ Il riepilogo dei risultati visualizzato sulla pagina iniziale (solo i risultati

Nome|Descrizione
---|---
`type`|`election` per elezioni, `vote` per votazioni.
`type`|`election` per elezioni, `election_compound` per componente delle elezioni, `vote` per votazioni.
`title`|Un oggetto contenente i titoli tradotti.
`date`|La data (ISO 8601).
`domain`|Il dominio di influenza (federazione, cantone, ...).
`url`|Un collegamento alla visualizzazione dettagliata.
`completed`|True, if the vote or election is completed.
`progress`|Un oggetto contenente il numero dei comuni già contati (`counted`) e il numero totale di comuni (`total`).
`progress`|Un oggetto contenente il numero dei comuni/elezioni già contati (`counted`) e il numero totale di comuni/elezioni (`total`).
`last_modified`|L'ultima volta in cui si è verificata una modifica dei dati (ISO 8601).
`turnout`|Affluenza alle urne in percentuale.

I risultati della votazione contengono le seguenti informazioni aggiuntive:

Expand All @@ -56,6 +58,18 @@ Nome|Descrizione
`nays_percentage`|Percentuale voti contrari.
`local` (*optional*)|Federal and cantonal votes within a communal instance may contain additionally the results of the municipality in the form of an object with `answer`, `yeas_percentage` and `nays_percentage`.

I risultati delle elezioni contengono le seguenti informazioni aggiuntive:

Nome|Descrizione
---|---
`elected`|Una lista con i candidati eletti.

I risultati del componente delle elezioni contengono le seguenti informazioni aggiuntive:

Nome|Descrizione
---|---
`elected`|Una lista con i candidati eletti.
`elections`|Una lista con link alle elezioni.

2 Risultati dell'elezione
-------------------------
Expand Down
18 changes: 16 additions & 2 deletions src/onegov/election_day/static/docs/api/open_data_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ Ils resultats che vegnan preschentads sin la pagina iniziala e sin las paginas d

Num|Descripziun
---|---
`type`|`election` per elecziuns, `vote` per votaziuns.
`type`|`election` per elecziuns, `election_compound` per colliaziuns cun l'elecziun, f`vote` per votaziuns.
`title`|In object cun ils titels translatads.
`date`|La data (ISO 8601).
`domain`|Champ d'influenza (confederaziun, chantun, ...).
`url`|In link a la vista detagliada.
`completed`|True, if the vote or election is completed.
`progress`|In object che cuntegna il dumber da las vischnancas dumbradas ora (`counted`) ed il dumber total da vischnancas (`total`).
`progress`|In object che cuntegna il dumber da las vischnancas/elecziuns dumbradas ora (`counted`) ed il dumber total da vischnancas/elecziuns (`total`).
`last_modified`|Ultima midadas (ISO 8601).
`turnout`|Participaziun a la elecziun/votaziun en pertschient.

Ils resultats da la votaziun cuntegnan las suandantas infurmaziuns supplementaras:

Expand All @@ -58,6 +60,18 @@ Num|Descripziun
`nays_percentage`|Vuschs negativas en pertschients.
`local` (*optional*)|Federal and cantonal votes within a communal instance may contain additionally the results of the municipality in the form of an object with `answer`, `yeas_percentage` and `nays_percentage`.

Ils resultats da las elecziuns cuntegnan las suandantas indicaziuns supplementaras:

Name|Description
---|---
`elected`|Ina glista cun las candidatas ed ils candidats elegids.

Ils resultats da las colliaziuns cun l'elecziun cuntegnan las suandantas indicaziuns supplementaras:

Name|Description
---|---
`elected`|Ina glista cun las candidatas ed ils candidats elegids.
`elections`|Ina glista cun links per las elecziuns.

2 Resultats da las elecziuns
----------------------------
Expand Down
1 change: 1 addition & 0 deletions src/onegov/election_day/utils/summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def get_election_compound_summary(
'completed': election_compound.completed,
'date': election_compound.date.isoformat(),
'domain': election_compound.domain,
'elected': election_compound.elected_candidates,
'last_modified': last_modified.isoformat() if last_modified else None,
'progress': {
'counted': election_compound.progress[0] or 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_election_compound_part_model(session):
assert part.manually_completed is False
assert part.pukelsheim is False
assert part.completed is False
assert part.elected_candidates == []
assert part.last_result_change is None
assert part.last_change
assert part.last_modified
Expand Down Expand Up @@ -96,6 +97,7 @@ def test_election_compound_part_model(session):
session.flush()

assert part.completed is False
assert part.elected_candidates == []
assert part.last_result_change == last_result_change
assert part.last_change
assert part.last_modified
Expand Down Expand Up @@ -169,6 +171,7 @@ def test_election_compound_part_model(session):
)

assert part.completed is False
assert part.elected_candidates == []
assert part.progress == (0, 1)
assert part.party_results == []
assert part.has_results is False
Expand Down Expand Up @@ -200,6 +203,7 @@ def test_election_compound_part_model(session):
# Set results as counted
part.elections[0].results[0].counted = True
assert part.completed is False
assert part.elected_candidates == []
assert part.counted is False
assert part.progress == (0, 1)
assert part.counted_entities == []
Expand All @@ -226,11 +230,13 @@ def test_election_compound_part_model(session):
assert part.totals.turnout == 0

part.elections[0].results[1].counted = True
part.elections[0].candidates[0].elected = True
assert part.completed is True
assert part.elected_candidates == [('Peter', 'Paul')]
assert part.counted is True
assert part.progress == (1, 1)
assert part.counted_entities == ['First Region']
assert part.allocated_mandates == 0
assert part.allocated_mandates == 1
assert part.has_results is True
assert part.results[0].accounted_ballots == 258
assert part.results[0].accounted_votes == 216
Expand Down
1 change: 1 addition & 0 deletions tests/onegov/election_day/models/test_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def test_webhook_notification(session):
'completed': False,
'date': '2011-01-01',
'domain': 'federation',
'elected': [],
'elections': [],
'last_modified': '2008-01-01T00:00:00+00:00',
'progress': {'counted': 0, 'total': 0},
Expand Down
1 change: 1 addition & 0 deletions tests/onegov/election_day/utils/test_summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def test_get_election_compound_summary(session):
'completed': False,
'date': '2011-01-01',
'domain': 'canton',
'elected': [],
'elections': ['Election/e1', 'Election/e2'],
'last_modified': '2014-01-01T12:00:00+00:00',
'progress': {'counted': 0, 'total': 2},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ def test_view_election_compound_summary(election_day_app_gr):
'completed': False,
'date': '2022-01-01',
'domain': 'canton',
'elected': [['Carol', 'Winner'], ['Hans', 'Sieger']],
'elections': [
'http://localhost/election/regional-election-a',
'http://localhost/election/regional-election-b'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def test_view_election_compound_part_summary(election_day_app_bl):
'completed': False,
'date': '2022-01-01',
'domain': 'superregion',
'elected': [['Hans', 'Sieger']],
'elections': [
'http://localhost/election/regional-election-b'
],
Expand Down

0 comments on commit 6514bf2

Please sign in to comment.