Giter VIP home page Giter VIP logo

commtechallyapi's Introduction

Election Results

This application is built on the flask microframework.

Installation

Use the package manager pip to install the requirements.

pip install -r requirements.txt

The web server reads a JSON file containing election results. You can use the supplied JSON file election_data.json if you would like. It contains several states and each state has several counties.

If you would like to generate a new data set you can do so by running the included python script gen_data.py

python3 gen_data.py

The file will be replaced.

Usage

Run the application with flask run. You should see the server running.

 Serving Flask app 'election_results.py' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
[2022-05-24 22:07:03,430] INFO in __init__: Elections startup
 * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)

Alternatively you can start the application in a docker file.
Build the docker image with

docker build . -t election_results

You can launch the container with

docker run --rm -it -p 5000:5000 election_results

Endpoints

The server has several endpoints. The main endpoints are:

/states/ - This endpoint returns a list of all states present in our data set
/states/Florida/ - When a state is present, each county is returned with the republican and democrat who received the most votes in that county.

/states/Florida/counties/ - This enpoint returns a list of all counties in that state present in our data set
/states/Florida/counties/Justinfurt/ - When a state and county is present, The republican and democrat who received the most votes in that county are returned.

There are 2 other endpoints registered but with no functionality due to time constraints. /overall - Intended to return the calculated overall winner across all states and counties
/index - No intended use. Just the root path.

TODO and other approaches

I originally explored pandas as a way to import and calculate the winners. It ended up being much to time-consuming for me to figure out how to load the data into usable data structures. It seemed like the out-of-the-box functionality was more useful for matrix data. I'm confident that the data could be loaded successfully, but it was out of scope for the task.

The final endpoint does not have any functionality. I would not have had time to document and finalize the code. I would have used a total votes approach and cumulatively added the ballots cast for each candidate in each county. I believe this is where the pandas library would have proved the most useful.

There are a lot of improvements that can be made. Some liberties were taken such as leniency on case-sensitive and white-space sanitization of input.
Error catching would be another improvement.

Author

Roy Myers: [email protected]

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.