Giter Club home page Giter Club logo

VisualCSV

VisualCSV is a web application built using Django, React and Redux for state management which allows users to upload CSVs and build graphs based on the data in the CSVs.

How it Works

Once authenticated, users are able to upload CSVs. With the uploaded CSVs users are asked to set any primary and foreign keys. Once the users are happy with their inputs they are able to send their CSVs to the backend by pressing an upload button. This converts a user's choices to JSON and along with the CSV data which is also converted to JSON and send this off to the backend.

The backend then creates database tables based on the POST data and updates the user_auth table which contains information on which table belongs to which user.

With this completed, the user is then able to access the graph_builder where they are able to use the UI to build graphs.

Presently, the only way to save the graph is to physically save the a copy of the graph as an image. However, in the future, this will be updated so that this can be saved directly onto the database.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Installation

The guide will cover installation using Docker and installing manually without Docker. It is recommended to use Docker to install and deploy the application as it is a lot faster and easier.

Installation Using Docker

Clone the repository

Clone (or fork) the repository to your working directory git clone https://github.com/Salaah01/visualCSV.git.

Setting up the environment variables

The docker version of the installation will use 3 containers:

  • Main web application
  • PostgreSQL database containing the main tables for the Django application.
  • PostgreSQL database for containing the user tables.
  • PostgreSQL test database for tests relating to the user database.

Docker will expect files from which it will retrieve values to set as environment variables. The get started, you can run bash quick_start_env_files.sh. This is for testing that the docker commands do work, in production you must replace these files with your own environment variables and once deployed, remove the files from your file system.

I recommend run the bash script and then running find | grep ".*\.env$". This will return a lit the files where the environment variables are stored.

Build the services

docker-compose build
docker-compose up -d

This can take a little while the first time round as it does install the node packages. The script will bind the visualCSV directory in the host machine to the same directory in the container. Therefore, updating files in the host will update the files in the container. Once docker-compose has finished it's magic, you are ready to access the site via port 8000 on localhost and start developing!

Installation Manually

Prerequisites

You will need to ensure that the following are installed:

Installing

The system uses two databases. One which is handled by Django's ORM and another that is handled via pure SQL. The Django ORM controlled database we will call visualCSV and the self managed database we will call visualCSVClient.

Database setup

Two separate databases are used to separate concerns. The visualCSV database will be used to handle authentication and other tables set up by Django. Whereas visualCSVClient will be used to store the end user's data. As each CSV is assigned its own table, we cannot control how fast the database grows. By designating the end-user tables to its own database, we can better control what is in the visualCSV (the main database).

I recommend using pgAdmin to set up the database as it provides a great GUI for interacting with postgreSQL. You will need to create three databases, visualCSV, visualCSVClient and visualCSVTest.

If you are using pgAdmin, access the query tool in visualCSVClient and run the following sql:

CREATE TABLE user_auth (id SERIAL PRIMARY KEY, user_id INTEGER NOT NULL, table_name VARCHAR(100) NOT NULL, table_alias VARCHAR(100) NOT NULL);

Repeat the query in the visualCSVClient.

If you choose not to use pgAdmin, you can achieve the same using the command line:

psql -U postgres
CREATE DATABASE "visualCSV";
CREATE DATABASE "visualCSVClient";
\c visualCSVClient
CREATE TABLE user_auth (id SERIAL PRIMARY KEY, user_id INTEGER NOT NULL, table_name VARCHAR(100) NOT NULL, table_alias VARCHAR(100) NOT NULL);

Clone the repository

Clone (or fork) the repository to your working directory git clone https://github.com/Salaah01/visualCSV.git. If you do not have git installed, you can download the files directly.

Create and activate a virtual environment

To create a virtual environment run python -m venv venv . Note: If you are using Linux you may need to run sudo apt-get install python3-venv. Activate the virtual environment. For Windows users: venv\scripts\activate. For Linux/Mac users: venv/bin/activate.

Install Python packages

Run pip install -r requirements.txt

Install Node packages

Run npm install. You may receive a warning about vulnerabilities in the installed node packages. By running npm audit fix you may be able to fix these vulnerabilities (only vulnerabilities which will not break the code).

Run Node build scripts

Run npm run build. This will compile the React, TypeScript and SASS modules to JavaScript and CSS.

Django migrations

Run python visualCSV\manage.py migrate. This will create the Django tables onto the visualCSV database.

Start development

Run python visualCSV\manage.py runserver to start the development start and run npm start to start watching for changes which would require node to recompile certain files.

A script exists which will start the JavaScript unit test on watch mode. This can be run using: npm run test:watch.

Production

The following instructions will enable you to deploy the application using Docker Stack to deploy a stack to a swarm. The documentation will describe the steps needed to install the application on an Ubuntu 18.04.3 x64 machine.

Install Docker

Ensure that whichever cloud provider you are using does have docker installed. To quickly check if your machine has docker installed, run docker --version. If you need to install docker, you can do so by running the following:

bash

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

The application runs 5 services with 3 replicas of the web service. You may wish to edit this to include other replicas and settings. Having 5 services does not mean that you must have 5 machines, all of the services can be run from a single machine.

Initialise Swarm

On one of your machines, run docker swarm init --advertise-addr <ip address>. This will initialise the swarm and provide two commands using which you can either add a worker to the swarm or add a manager. We will add 4 other managers, to do so, run docker swarm join-token manager on each of the other machines.

Update Environment Variables

bash quick_start_env_files.sh

This will very quickly create .env files which docker will expect when building the stack. We will test that the stack can be deployed, and once we are happy, we will stop the stack, update the .env files and redeploy the stack.

docker stack deploy -c output.yml visualCSV

Run docker stack services visualCSV to check the progress of the swarm. It is ready when all the replicas show the same number on the left and right. e.g: 0/3 means not ready, 3/3 means ready.

This may take a while as the web service needs to run through a number of installations and so you may find that web service and the nginx service (it depends on the web service) take longer than others to initialise.

Once all the services are running, access the public IP address to test that the application is running.

Next stop the stack and update the env file:

docker stack rm visualCSV
find | grep ".*\.env$"

This returns a list of env files that need to be updated. Update the value in each file and re-run docker stack deploy -c output.yml visualCSV. Once everything is running again run find | grep ".*\.env$" | while read in; do rm "$in"; done to remove all the .env files.

Updating Webiste

The image is held in Docker Hub and automation is setup were commits to the master branch will be picked up by Docker Hub resulting in a new image to be created. Once complete, run docker service update {{service name}}.

Testing

The packages comes with Python and JavaScript unit tests.

To run the Python unit tests run python visualCSV\manage.py test.

To test JavaScript unit tests run npm run test.

Salaah Amin's Projects

auto-gpt icon auto-gpt

An experimental open-source attempt to make GPT-4 fully autonomous.

django icon django

The Web framework for perfectionists with deadlines.

django-countries icon django-countries

A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.

django-debug-toolbar icon django-debug-toolbar

A configurable set of panels that display various debug information about the current request/response.

django-email-signals icon django-email-signals

A Django app that allows users to dynamically send emails whenever there are some changes on some tables.

email-unsuber icon email-unsuber

This program will parse through your emails and collect a list of unsubscribe links and output them into a CSV, XLSX (Excel) or JSON.

frood icon frood

A portfolio project where the user would be able to order food in a website which is to mimic a takeaway food service. Website uses 2 APIs to produce a map and JS for DOM manipulation and other logic.

gen-unit-tester icon gen-unit-tester

A generic to help build a project, test and move onto a staging area.

invoice-api icon invoice-api

A Django API service for uploading invoices and reading information on uploaded invoices.

json-lineage icon json-lineage

Tool to allow parsing large JSON files without laoding into memory. Developed in Rust with adapters in other programming langauges for easy adoption

linux-ios-debugger icon linux-ios-debugger

This program will allow you to run the inspect element tool using the Google Chrome/Chromium browser on your Linux (Debian) machine.

minipics icon minipics

An image optimisation/compression desktop app.

pubc-subc icon pubc-subc

Another pub-sub implementation no one asked for but built in C this time

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.