# Výsledky a štatistiky

Výsledky volieb sa rátajú na serveri pomocou dát získaných z ElasticSearch-u a funkcie calcualte_winning_parties_and_seats.

Na zobrazenie výsledkov ponúkame viaceré endpointy, ktoré výsledky vrátia s inou agregáciou alebo vrátia len ich časť aby odpoveď nebola príliš veľká.

# Dostupné endpointy:

  • /elastic/get-parties-results
    • získanie výsledkov politických strán bez kandidátov
  • /elastic/get-party-candidate-results
    • získanie výsledkov všetkých strán a kandidátov
  • /elastic/get-candidates-results
    • získanie výsledkov všetkých kandidátov
  • /elastic/get-results-by-locality
    • získanie výsledkov všetkých strán a kandidátov pre určitú lokalitu

# Počítanie percent a parlamentných kresiel

Výpočet získaných kresiel sa vykonáva vo funkcii calcualte_winning_parties_and_seats.

def calcualte_winning_parties_and_seats(transformed_data):
    """
    Find parties having more than 5% (threshold) and count all votes for these parties.
    In case parties have less then threshold value, take all parties
    Calculate relative vote percentage from this set of parties and calculate result seats for each party
    """

Algoritmus výpočtu:

  1. Prepočítať počet získaných hlasov pre všetky strany a získať tie, ktoré majú nad 5%.
  2. Počet republikové číslo (počet hlasov, potrebných pre získanie jedného mandátu, ráta s pomocou čísla 151).
  3. Pomocou republikového čísla určiť na koľko kresiel má strana nárok a uchovať si počet po celočíselnom delení.
  4. Ak neboli rozdané všetky kreslá, tak sa doplnia postupne stranám v poradí podľa zostatku po celočíselonom delení republikovým číslom.

# Popis API

# setup_elastic_votes_index_elastic_setup_elastic_vote_index_post

Code samples

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.post('/elastic/setup-elastic-vote-index', headers = headers)

print(r.json())

POST /elastic/setup-elastic-vote-index

Setup Elastic Votes Index

Setup elastic search. Drop index if previously used. Create new index and variables mapping.

Example responses

200 Response

{
  "status": "string",
  "message": "string"
}

Responses

Status Meaning Description Schema
200 OK Successful Response Message
400 Bad Request Bad Request Message
500 Internal Server Error Internal Server Error Message

# synchronize_votes_ES_elastic_synchronize_votes_es_post

Code samples

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.post('/elastic/synchronize-votes-es', headers = headers)

print(r.json())

POST /elastic/synchronize-votes-es

Synchronize Votes Es

Batch synchronization of votes from Mongo DB to Elastic search 3 Node cluster. Shuld be called in specific intervals during election period.

Parameters

Name In Type Required Description
number query any false none

Example responses

200 Response

{
  "status": "string",
  "message": "string"
}

Responses

Status Meaning Description Schema
200 OK Successful Response Message
400 Bad Request Bad Request Message
422 Unprocessable Entity Validation Error HTTPValidationError
500 Internal Server Error Internal Server Error Message

# get_parties_results_elastic_get_parties_results_post

Code samples

import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

r = requests.post('/elastic/get-parties-results', headers = headers)

print(r.json())

POST /elastic/get-parties-results

Get Parties Results

Body parameter

{
  "party": "SME RODINA"
}

Parameters

Name In Type Required Description
body body StatisticsPerPartyRequest true none

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
400 Bad Request Bad Request Message
422 Unprocessable Entity Validation Error HTTPValidationError
500 Internal Server Error Internal Server Error Message

Response Schema

# get_parties_with_candidates_results_elastic_get_party_candidate_results_post

Code samples

import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

r = requests.post('/elastic/get-party-candidate-results', headers = headers)

print(r.json())

POST /elastic/get-party-candidate-results

Get Parties With Candidates Results

Body parameter

{
  "party": "SME RODINA"
}

Parameters

Name In Type Required Description
body body StatisticsPerPartyRequest true none

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
400 Bad Request Bad Request Message
422 Unprocessable Entity Validation Error HTTPValidationError
500 Internal Server Error Internal Server Error Message

Response Schema

# get_candidates_results_elastic_get_candidates_results_post

Code samples

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.post('/elastic/get-candidates-results', headers = headers)

print(r.json())

POST /elastic/get-candidates-results

Get Candidates Results

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
400 Bad Request Bad Request Message
500 Internal Server Error Internal Server Error Message

Response Schema

# get_resilts_by_locality_mongo_elastic_get_results_by_locality_mongo_get

Code samples

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('/elastic/get-results-by-locality-mongo', headers = headers)

print(r.json())

GET /elastic/get-results-by-locality-mongo

Get Resilts By Locality Mongo

Used to provide benchmark for ES vs Mongo aggregation queries

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK Successful Response Inline

Response Schema

# get_results_by_locality_elastic_get_results_by_locality_post

Code samples

import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

r = requests.post('/elastic/get-results-by-locality', headers = headers)

print(r.json())

POST /elastic/get-results-by-locality

Get Results By Locality

Body parameter

{
  "filter_by": "region_name",
  "filter_value": "Prešovský kraj",
}

Parameters

Name In Type Required Description
body body StatisticsPerLocalityRequest true none

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
400 Bad Request Bad Request Message
422 Unprocessable Entity Validation Error HTTPValidationError
500 Internal Server Error Internal Server Error Message

Response Schema

# get_elections_status_elastic_elections_status_get

Code samples

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('/elastic/elections-status', headers = headers)

print(r.json())

GET /elastic/elections-status

Get Elections Status

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK Successful Response Inline
400 Bad Request Bad Request Message
500 Internal Server Error Internal Server Error Message

Response Schema