Code Monkey home page Code Monkey logo

everyelection's Introduction

EveryElection

Build Status Coverage Status Code style: black

For recording every election in the UK

Domain Model

Elections

The elections table stores a list of election objects, each with a semantic ID.

Election IDs sometimes have a parent, and are sometimes a "group ID".

There are two types of group ID:

  1. [type].[date], for example local.2017-05-04 will be the group for all local elections happening on 2017-05-04.
  2. [type].[organiation].[date], for example local.norfolk.2017-05-04 is the Norfolk County Council elections.

Finally an ID is made per ballot paper using [type].[organiation].[organisation division].[date] for example local.norfolk.diss.2017-05-04.

See the reference for more information.

Graph

everyelection's People

Contributors

awdem avatar bekabyx avatar chris48s avatar davidmiller avatar dependabot-preview[bot] avatar dependabot[bot] avatar geowill avatar hugovk avatar michaeljcollinsuk avatar mrwilson avatar pmk01 avatar pyup-bot avatar russss avatar symroe avatar tfgg avatar virginiadooley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

everyelection's Issues

Support 'current' elections

We will want to have some idea of what elections are 'current', in a political sense.

Normally elections will be current for about 6 months before they happen, or, in the case of a by- or snap election from the time they are announced. They will remind 'current' for some time after the election, we can assume about a couple of months.

Each election will vary, to I suggest we have current_from and current_to fields that are pre-populated with safe defaults when the election is created. These dates can then be edited in the admin interface if needs be.

We can expose these values in the API, but also provide a filter and boolean is_current. This will help when consuming the API in cases where all historic elections aren't needed (like updating YNR).

Make it clearer that parish/town/community elections are out of scope

On the 'Election Type' page, there should be a radio button for "Parish/Town/Community". If the user selects this, it should take them to a page which:

  • Explains that these elections are out-of-scope for the project (and why)
  • Cleans up their wizard session vars

Should we also attempt to clarify that the existing "local" option applies to Administrative County/Borough/District/Metropolitan District/London Borough/Welsh Unitary/Scottish Unitary only? Is there any kind of succinct way to express that?

Special cases for City of London Elections

Slightly edited comments from conversation on slack:

@sjorford wrote:

According to http://democracy.cityoflondon.gov.uk/mgMemberIndex.aspx?bcr=1 "Each ward elects one Alderman and two or more Common Councilmen (collectively referred to as Members, equivalent to councillors), dependent on its population. There are currently 100 Common Councilmen and 25 Aldermen serving as elected representatives..."

@chris48s wrote:

If I create local.city-of-london.tower.by.2017-09-12, is that sufficiently unambiguous? I assume that even if there were both and Alderperson and Common Councilperson being elected for the same ward at the same time you'd essentially get have one poll with 2 ballots?
..but then I think the idea with the election ids spec is that each ballot should have a distinct id..

@sjorford wrote:

for the SP/NAW/GLA we have an intermediate level of IDs e.g. gla.c and gla.a
so do we need something like local.city-of-london.cc.tower.by.2017-09-12 and local.city-of-london.alder.tower.by.2017-09-12?

I think we technically we should introduce sub-types to account for City of London oddities.

The other thing this raises is versioning the spec. For the moment it probably doesn't matter as it is only really us dogfooding the schema but once we have wider users, I think it becomes useful to be able to say that local.city-of-london.tower.by.2017-09-12 was created under version 1.0 but would be local.city-of-london.alder.tower.by.2017-09-12 under version 1.1 or something. Probably worth thinking about.. Even once we're accounting for all of the edge cases present in the current structure/legislation correctly there is still the possibility of electoral reform, changes to local government structure + so on..

Elections by postcode not working/elections with NULL geography

I am getting some unexpected results from the API. For example:

but in all those cases the response is

{
  "count": 0,
  "next": null,
  "previous": null,
  "results": []
}

I've synced a local copy and had a bit of a poke about. It seems that the problem is that there are a bunch of elections where the geography_id is NULL, including the ones I've specified above. I thought initially this was a problem with the id creator wizard, but having poked about there is a management command called add_geography_to_elections and running this locally fixes the problem. Is the only thing we need to do in order to fix this to schedule that to run with cron? (I checked the crontab and it isn't scheduled), or is there a reason this isn't running?

Add start and end dates to Organisations

All good things must end, including government organisations :'(

We should make sure that we don't offer old organisations on the list of organisations in the ID creator when we know the election date, and validate that we don't have elections for organisations that have ended.

Support voting systems

We need to know:

  • The name of the voting system
  • If it used a list or not (this is used in YNR)

Create election id from radar

Once something is marked as 'this is an election', there should be a 'create an id' button which:

  • opens the id creator
  • links the created id to this record so that once the id is created, this election disappears from the 'radar'
    (MVP)

stretch goals should be:

  • auto populate the 'source' field with the relevant notice of polls or ALDC link - requires implementing 'source' field (see issue #5 ) but once that's done, should be easy
  • auto-populate other info if possible (e.g: authority, date) - that is much more difficult but would be nice :)

Refactor IDMaker

The IDMaker class needs restructuring from 2 perspectives:

General Code Structure:

IDMaker has 11 optional constructor parameters. This is a classic situation where we should be using the builder pattern. IDMaker should be refactored into an ElectionBuilder class which instantiates with the requied data and default values for everything else. It should then have setProperty()/withProperty() methods for all of the optional stuff (depending if we're going with a mutable or immutable implementation) and a build() method which returns an Election object. ElectionBuilder should be responsible for object creation only and decoupled from the concept of database persistence. Election objects should be responsible for their own DB persistence (or at least the calling code).

Re-usability:

The logic in IDMaker also determines the schema for election ID generation. Our ambition is that DC election IDs should be reproducable (i.e: we should define a method for generating ids, not become an issuer of ids) but at the moment our code for generating the IDs is tightly coupled both to a particular framework/ORM and the wider process of creating an election object. This makes it difficult to point to our code as a reference implementation and it is difficult for others to share.

To this end, we should also decouple the ID creation part of the process from the creation of an Election object (which is both coupled to a data model and includes additional meta-data not relevant to ID generation such as source, Notice of Election doc, etc). Once refactored, the ElectionBuilder should assemble the necessary data (such as organisation names) from the input data and our data model and hand that off to a separate object or function which only implements the logic necessary to build the ID string. That object/function is then much more suited to serve as a definition of how we create IDs.

API: Get elections by area (and/or postcode?)

I made a slightly off-hand comment about this on slack, but thought it would be useful to formalise this a bit/start a discussion.

As a user, I would like to be able to query elections by making a call like:
https://elections.democracyclub.org.uk/api/elections/area/W06000001 or
https://elections.democracyclub.org.uk/api/elections/postcode/SW1A%201AA
(for example)

This should also be filterable by date in some way (i.e: it should be possible to construct an API call which returns a list of all elections where poll_open_date > now() or where poll_open_date == '2017-05-04', etc).

This should return a list of election objects or an empty array [] if there are no upcoming elections for the given area.

This query should also be capable of determining elections which are relevant to a higher level of geography. For example, calling https://elections.democracyclub.org.uk/api/elections/area/E07000004 should return an array which contains an election object for local.buckinghamshire.2017-05-04 (Aylesbury Vale being a child of Buckinghamshire) and any national elections + so on.

I think the first step on the road to this would be to make sure every organisation that an election can be associated with directly maps to an appropriate boundary in Mapit (some of them currently don't but could do e.g: Greater London Assembly, House of Commons). Some of them will/may require some additional importing (e.g: Police Force areas for Police and Crime Comissioner elections?). Having that will allow the codes returned by an applicable covers query to be referenced against the organisations in the DB to construct this output.

..that and actually having some elections to return :)

Also, woo - first issue!

Add "source" field for elections

We should track the sources of election IDs somehow.

The main thing to think about is how to add this to the ID creator form.

Paginate radar view

These lists are going to get big.
We should use pagination (or lazy loading) to stop the pages/DB queries from getting too crazy.

Fix boundary imports

Steps to reproduce:

  1. init a blank DB
  2. python manage.py import_organisations (once PR #55 merged)
  3. python manage.py import_organisation_divisions
  4. https://mapit.mysociety.org/ will start throwing
Status: 429
Response: Usage limit reached.

game over, no boundaries :(

Find a clearer way to explain project scope

We want to know of every distinct council level election and above

I realise that 'above' here means in the context of geographical hierarchy, but I don't feel like this is worded in a way that is going to be clear to everyone. I don't necessarily have a better proposal.

Maybe someone like @JoeMitchell or @davidmiller has opinions on how this could be explained clearly in one sentence? (i.e: without explicitly listing every election type that is in/out of scope)

Slack push messages when elections are created

Does what it says, but useful to know if something needs moderation as per #79

Could have one message for "An election was created by an admin" and another for "A election was created and needs moderation"

Can't add Ettrick, Roxburgh and Berwickshire by-election

I am trying to add Scottish Parliament by-election for Ettrick, Roxburgh and Berwickshire ( https://www.scotborders.gov.uk/info/20057/elections_and_voting/199/elections ) but if I add an election for Scottish parliament, when I get to the stage where I pick an organisation there are no organisations to choose from. I can only mark everything as contested. This means I can't add a by-election:

screenshot at 2017-05-10 11 44 09

Assume something has gone wonky with the geography import?

More human election date picker?

_democracy_club_elections

Obvs it gets recorded as a number, but I wonder if a user could choose from a list of month-names. Reads more naturally, makes it easier to avoid errors.

Deal with typos in the wards (from legislation!)

  • Dorset - Broadway - should be Broadwey
  • East Renfrewshire - Newton Means North and Neilston - should be Newton Mearns North and Neilston
  • Falkirk - Boâ��ness and Blackness - should be Bo'ness and Blackness
  • Highland - Eilean aâ�² Chèo - should be Eilean a' Cheò (according to the SOPN anyway - spelling seems to be variable)
  • Rhondda Cynon Taff - should be Rhondda Cynon Taf (council uses the same in both Welsh and English)

Not a 'uuuge priority.

Moderate elections

  • Add authentication/login
  • Election IDs created by admin users are automatically approved
  • Anonymous users can still create election ids, but ids created by anonymous users are submitted for moderation/approval. Once approved by a moderator they can be synced through to YNR etc

Handle official IDs better

We have a gss field on Organisation, but in a lot of cases this isn't actually a GSS code (going forward we won't have GSS codes for anywhere at the point of import).

We should rename the field to something, but also support different ID schemes for one object.

Consistently name mayoral elections

(Thanks to Fred Bann for this!)

Looking at https://candidates.democracyclub.org.uk/posts there's a mixture of formats in the titles of the mayoral elections: some include "Combined Authority", some don't, and the two Local Authority Mayors don't include the word "Mayor" at all.

For consistency my suggestion would be to change, for example;
"Mayor of Greater Manchester" to "Greater Manchester Combined Authority Mayoral Election"
and "Greater Manchester" to "Mayor of Greater Manchester"

The first part is how the elections will appear on the notice at polling stations [1] plus the titles on the candidates pages would be like how they were last year [2]

[1] http://www.legislation.gov.uk/uksi/2017/67/contents/made (Rule 28, para 6b - see page 19 on the pdf)
[2] https://candidates.democracyclub.org.uk/election/mayor.liverpool.2016-05-05/post/mayor:liverpool/mayor-of-liverpool

UX improvement: Search Elections

As a creator of election IDs I find it hard to answer a question like "did I already create an election ID for the Stockton-onTees Billingham North by-election?" using the existing views/outputs.

I would like a search box so I can type "stockton" into it (for example) and see what comes up.

Add election_status to EE data model

The 2017-05-04 by-election for Manchester, Gorton should be marked in EE as canceled, and EE could benefit from being able to assign this and other status values to any election. Example values below.

election_status:
Expected
Announced
Cancelled
Completed - or this could be: Polls Closed; Result Announced

If a changelog can accept a source then for the above example it would be: http://www.manchester.gov.uk/download/downloads/id/24869/notice_of_cancellation_of_manchester_gorton_parliamentary_by_election.pdf

Issue with the Liverpool election ID

From fbrc again:

On last week's blog you were talking about groups of elections. I noticed the mayor ID for Liverpool's combined authority has the same format as last year's for Mayor of Liverpool City Council i.e. mayor.liverpool.{date} but they are two different people. Is this a problem?

This seems like a problem. In the EveryElection spreadsheet (column I, row 19), it has mayor.liverpool-city-region.2017-05-04, which seems right.

So I'm a bit confused as to what's happening. Nothing new there then!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.