https://github.com/simonrw/uk-election-results-analysis
https://github.com/simonrw/uk-election-results-analysis
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/simonrw/uk-election-results-analysis
- Owner: simonrw
- Created: 2018-07-01T17:56:54.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-03-29T17:53:19.000Z (over 5 years ago)
- Last Synced: 2025-02-06T08:45:16.745Z (over 1 year ago)
- Language: Python
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Election results
## REST API query design
First, send a request to
`http://lda.data.parliament.uk/electionresults.json` which is the top
level endpoint.
```
# Root request, returns election result meta-objects
elections = FETCH http://lda.data.parliament.uk/electionresults.json |> result |>
totalResults
for election in elections:
# Extract constituency info
{
constituency_url = election |> constituency |> _about
constituency_info = FETCH constituency_url
constituency_type = constituency_info |> result |> primaryTopic |> constituencyType
constituency_name = constituency_info |> result |> primaryTopic |> label |> _value
constituency_os_name = constituency_info |> result |> primaryTopic |> osName
}
# Extract election info
{
election_url = election |> _about
election_info = FETCH election_url
election_type = election_info |> result |> primaryTopic |> electionType
election_label = election_info |> result |> primaryTopic |> label |> _value
candidates = election_info |> result |> primaryTopic |> candidate
turnout = election_info |> result |> primaryTopic |> turnout
for candidate_url in candidates:
candidate = FETCH candidate_url
vote_change_percentage = candidate |> result |> primaryTopic |> voteChangePercentage
votes = candidate |> result |> primaryTopic |> numberOfVotes
full_name = candidate |> result |> primaryTopic |> fullName |> _value
party = candidate |> result |> primaryTopic |> party |> _value
}
```
## Models
```
candidate:
id integer primary key
full_name string
constituency:
id integer primary key
type string
name string
os_name string
election:
id integer primary key
type string
label string
turnout:
id integer primary key
election_id integer foreign_key(election.id)
constituency_id integer foreign_key(constituency.id)
turnout integer
votes:
id integer primary key
candidate_id integer foreign_key(candidate.id)
constituency_id integer foreign_key(constituency.id)
election_id integer foreign_key(election.id)
votes integer
vote_change_percentage real
party string
```
vim: tw=0:nowrap