Coder Social home page Coder Social logo

atlantic_demo's Introduction

To run

pip install virtualenv
virtualenv venv -p $(which python3)
source venv/bin/activate
make install
# Run tests
make test # tests do not pass yet
# start server
make start
open http://localhost:8000/

Progress

  • I was practicing TDD here, so I spent much more time setting up a testing environment than writing code, but my plan would be:
    • Upload the csv to a temp table using \copy
    • Update customers from temp table where customer.id is in the temp table, possibly using the django orm, but the resulting sql would look like
UPDATE customer
SET first_name=subquery.first_name,
    last_name=subquery.last_name,
    address=subquery.address,
    zip_code=subquery.zip_code,
    state=subquery.state
FROM (SELECT customer_id, first_name, last_name, ... FROM temp_table) AS subquery
WHERE customer.id=subquery.customer_id;
    • Create customers from temp table where customer id is not in the temp table
INSERT INTO customer (
    SELECT customer_id, first_name, last_name, ...
    FROM temp_table
    WHERE custome_id NOT IN ( SELECT id FROM customer)
);
    • Repeat for Products
    • Repeat for Purchases using timestamp as the id for lack of a better identifier
  • The reason for the temp table instead of is that looping through rows in the csv and creating Customers, Products and Purchases individually:
    • I could reduce the number of queries to ~7, increasing speed
    • This should result give me data locality and increase speed

##Further Optimizations ###Normalization of the database

  • I'm assuming that there are 3 types of objects
    • Customers
    • Products
    • Purchases
  • If a customer can purchase a product multiple times, a purchase must be defined by the time it occurred

###Authentication and authorization capabilities

  • Django can handle this. Any kind of single sign on seems unlikely if this provider can't integrate with an API endpoint or in some automated way ###Support for files larger than 3MB (upload progress indicator, etc)
  • This job could be handed off to a celery task that could be polled for progress ###Irregularity detection and alerting (for instance, if a purchase is canceled that has not been previously seen as new)
  • There could be a series of heuristic checks, such as cancelations of purchases that had not yet occurred
  • There could be anomaly detection done on number of new customers or new products ###Detecting and handling updating addresses for customers
  • We may want to store previous addresses for a customer, and therefore addresses might need to be stored in their own table with a foreign key to user

atlantic_demo's People

Watchers

James Cloos avatar Daniel Cohen 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.