Git Product home page Git Product logo

wingz's Introduction

wingz

RESTful API for managing ride information

Development

# build docker container
make build

# start docker container
make up

# run migrations
make migrate

# create super user
make superuser

# serve locally on http://localhost:8000
# CTRL-C will stop the development server
make serve

# stop docker container
make down

OpenAPI Schema

Available as both SwaggerUI (http://localhost:8000/api/schema/swagger-ui/) and Redoc (http://localhost:8000/api/schema/redoc/)

Generate Report

Run make report to get count of trips that took more than one hour, grouped by month and driver

The complete SQL query is below for reference

SELECT
    TO_CHAR(ride.pickup_time, 'YYYY-MM') AS month,
    CONCAT(driver.first_name, ' ', LEFT(driver.last_name, 1), '.') AS name,
    COUNT(*) AS ride_count
FROM
    rides_ride ride
JOIN
    users_user driver ON ride.driver_id = driver.id
JOIN
    rides_rideevent pickup_event ON ride.id = pickup_event.ride_id AND pickup_event.description = 'Status changed to pickup'
JOIN
    rides_rideevent dropoff_event ON ride.id = dropoff_event.ride_id AND dropoff_event.description = 'Status changed to dropoff'
WHERE
    EXTRACT(HOUR FROM AGE(dropoff_event.created_at, pickup_event.created_at)) > 1
GROUP BY
    month,
    name

Design Decisions

Some notes on design decisions

Authentication

  • Defined custom user because modifying default user after migrations have been created is a royal pain
  • Extended AbstractBaseUser instead of AbstractUser in case the method of authentication changes

Database

  • Set the default on_delete behavior to models.SET_NULL out of convenience
  • Used DecimalField versus FloatField (as specified in the requirements) since decimal math is more precise compared to float math
    • Based on whether we are reading or writing more frequently to the database, "good enough" float math may be worth the performance benefits
  • Chose Postgres over MySQL because Postgres offers geospatial extensions
  • Calculated distance to pickup using the Haversine distance due to simpler math. If greater accuracy is needed, worth looking into proper geodesic distance using Vincenty algorithm

Other Notes

Miscellaneous notes and features to be implemented

  • Use django-environ to load settings from .env based on environment
  • Disable django-silk or require authentication
  • Validate user phone numbers as E.164
  • Lint with flake8
  • Write unit tests

wingz's People

Contributors

justicesuh avatar

Watchers

 avatar

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.