From 436fd1be2ab66d6587c53c4b883f8d1e3c9126f4 Mon Sep 17 00:00:00 2001 From: James Shen Date: Tue, 12 Oct 2021 22:23:21 -0400 Subject: [PATCH] Change everything to lf, add .gitattribute --- .dockerignore | 8 +-- .gitattributes | 50 +++++++++++++++ .gitignore | 2 +- Dockerfile | 12 ++-- README.md | 20 +++--- init/create.sql | 144 +++++++++++++++++++++--------------------- init/data/Quotes.csv | 6 +- init/data/Users.csv | 20 +++--- init/initdata.sh | 6 +- init/load.sql | 4 +- init/todo.txt | 2 +- scripts/start.sh | 4 +- scripts/teardown.sh | 4 +- scripts/test_setup.py | 26 ++++---- 14 files changed, 179 insertions(+), 129 deletions(-) create mode 100644 .gitattributes diff --git a/.dockerignore b/.dockerignore index a094a7a..1899809 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,5 @@ -Dockerfile -LICENSE -README.md -scripts +Dockerfile +LICENSE +README.md +scripts scripts/ \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..826efdd --- /dev/null +++ b/.gitattributes @@ -0,0 +1,50 @@ + # .gitattributes snippet to force users to use same line endings for project. + # + # Handle line endings automatically for files detected as text + # and leave all files detected as binary untouched. + * text=auto + + # + # The above will handle all files NOT found below + # https://help.github.com/articles/dealing-with-line-endings/ + # https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes + + + + # These files are text and should be normalized (Convert crlf => lf) + *.php text + *.css text + *.js text + *.json text + *.htm text + *.html text + *.xml text + *.txt text + *.ini text + *.inc text + *.pl text + *.rb text + *.py text + *.scm text + *.sql text + .htaccess text + *.sh text + + # These files are binary and should be left untouched + # (binary is a macro for -text -diff) + *.png binary + *.jpg binary + *.jpeg binary + *.gif binary + *.ico binary + *.mov binary + *.mp4 binary + *.mp3 binary + *.flv binary + *.fla binary + *.swf binary + *.gz binary + *.zip binary + *.7z binary + *.ttf binary + *.pyc binary \ No newline at end of file diff --git a/.gitignore b/.gitignore index 795a084..48387d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -# MacOS +# MacOS .DS_Store \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f16ce6b..dcde07f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM timescale/timescaledb:latest-pg12 -ENV POSTGRES_USER root -ENV POSTGRES_PASSWORD password -ENV POSTGRES_DB quantx -COPY init/create.sql /docker-entrypoint-initdb.d/ -COPY init/load.sql /docker-entrypoint-initdb.d/ +FROM timescale/timescaledb:latest-pg12 +ENV POSTGRES_USER root +ENV POSTGRES_PASSWORD password +ENV POSTGRES_DB quantx +COPY init/create.sql /docker-entrypoint-initdb.d/ +COPY init/load.sql /docker-entrypoint-initdb.d/ COPY . . \ No newline at end of file diff --git a/README.md b/README.md index 2580756..56b8d8d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# SETUP - -## SETUP - -- Read through https://docs.timescale.com/ - -- Can be setup standalone (but intended for use with server) - - TO SETUP: bash ./scripts/start.sh - - TO TEARDOWN: bash ./scripts/teardown.sh - - TO TEST SETUP (setup and teardown): ./test_setup.py +# SETUP + +## SETUP + +- Read through https://docs.timescale.com/ + +- Can be setup standalone (but intended for use with server) + - TO SETUP: bash ./scripts/start.sh + - TO TEARDOWN: bash ./scripts/teardown.sh + - TO TEST SETUP (setup and teardown): ./test_setup.py diff --git a/init/create.sql b/init/create.sql index 76d1ffe..d12037d 100644 --- a/init/create.sql +++ b/init/create.sql @@ -1,72 +1,72 @@ -CREATE TABLE Users ( - id INT GENERATED BY DEFAULT AS IDENTITY, - email TEXT UNIQUE NOT NULL, - hashed_password TEXT NOT NULL, - firstname VARCHAR(255), - lastname VARCHAR(255), - description TEXT, - PRIMARY KEY(id) -); - -CREATE TABLE Strategy ( - id INT GENERATED BY DEFAULT AS IDENTITY, - uid INT REFERENCES Users(id), - code TEXT NOT NULL, - PRIMARY KEY(id) -); - -CREATE TABLE Backtest ( - id INT GENERATED BY DEFAULT AS IDENTITY, - result TEXT, - code_snapshot TEXT NOT NULL, - test_start TIMESTAMP NOT NULL, - test_end TIMESTAMP NOT NULL, - created TIMESTAMP NOT NULL, - PRIMARY KEY(id) -); - -CREATE TABLE Competition ( - id INT GENERATED BY DEFAULT AS IDENTITY, - title TEXT NOT NULL, - description TEXT NOT NULL, - owner INT REFERENCES Users(id), - created TIMESTAMP NOT NULL, - end_time TIMESTAMP NOT NULL, - test_start TIMESTAMP NOT NULL, - test_end TIMESTAMP NOT NULL, - PRIMARY KEY(id) -); - -CREATE TABLE CompetitionEnrollment ( - comp_id INT REFERENCES Competition(id), - uid INT REFERENCES Users(id), - PRIMARY KEY(uid, comp_id) -); - -CREATE TABLE CompetitionEntry ( - comp_id INT REFERENCES Competition(id), - backtest_id INT REFERENCES Backtest(id), - PRIMARY KEY(comp_id, backtest_id) -); - -CREATE TABLE Symbol ( - symbol TEXT NOT NULL PRIMARY KEY, - name TEXT NOT NULL, - description TEXT -); - -CREATE TABLE Quote ( - time TIMESTAMP NOT NULL, - symbol TEXT REFERENCES Symbol(symbol), - price_open DOUBLE PRECISION NULL, - price_high DOUBLE PRECISION NULL, - price_low DOUBLE PRECISION NULL, - price_close DOUBLE PRECISION NULL, - - PRIMARY KEY (symbol, time) -); - -CREATE EXTENSION IF NOT EXISTS timescaledb; - -/* Create hypertable from Quotes table */ -SELECT create_hypertable('Quote', 'time'); +CREATE TABLE Users ( + id INT GENERATED BY DEFAULT AS IDENTITY, + email TEXT UNIQUE NOT NULL, + hashed_password TEXT NOT NULL, + firstname VARCHAR(255), + lastname VARCHAR(255), + description TEXT, + PRIMARY KEY(id) +); + +CREATE TABLE Strategy ( + id INT GENERATED BY DEFAULT AS IDENTITY, + uid INT REFERENCES Users(id), + code TEXT NOT NULL, + PRIMARY KEY(id) +); + +CREATE TABLE Backtest ( + id INT GENERATED BY DEFAULT AS IDENTITY, + result TEXT, + code_snapshot TEXT NOT NULL, + test_start TIMESTAMP NOT NULL, + test_end TIMESTAMP NOT NULL, + created TIMESTAMP NOT NULL, + PRIMARY KEY(id) +); + +CREATE TABLE Competition ( + id INT GENERATED BY DEFAULT AS IDENTITY, + title TEXT NOT NULL, + description TEXT NOT NULL, + owner INT REFERENCES Users(id), + created TIMESTAMP NOT NULL, + end_time TIMESTAMP NOT NULL, + test_start TIMESTAMP NOT NULL, + test_end TIMESTAMP NOT NULL, + PRIMARY KEY(id) +); + +CREATE TABLE CompetitionEnrollment ( + comp_id INT REFERENCES Competition(id), + uid INT REFERENCES Users(id), + PRIMARY KEY(uid, comp_id) +); + +CREATE TABLE CompetitionEntry ( + comp_id INT REFERENCES Competition(id), + backtest_id INT REFERENCES Backtest(id), + PRIMARY KEY(comp_id, backtest_id) +); + +CREATE TABLE Symbol ( + symbol TEXT NOT NULL PRIMARY KEY, + name TEXT NOT NULL, + description TEXT +); + +CREATE TABLE Quote ( + time TIMESTAMP NOT NULL, + symbol TEXT REFERENCES Symbol(symbol), + price_open DOUBLE PRECISION NULL, + price_high DOUBLE PRECISION NULL, + price_low DOUBLE PRECISION NULL, + price_close DOUBLE PRECISION NULL, + + PRIMARY KEY (symbol, time) +); + +CREATE EXTENSION IF NOT EXISTS timescaledb; + +/* Create hypertable from Quotes table */ +SELECT create_hypertable('Quote', 'time'); diff --git a/init/data/Quotes.csv b/init/data/Quotes.csv index c6f90e0..43ff3a6 100644 --- a/init/data/Quotes.csv +++ b/init/data/Quotes.csv @@ -1,3 +1,3 @@ -2021-06-16 20:00:00,AAPL,129.21,129.1,129.21,129.21 -2021-06-16 19:59:00,AAPL,129.22,129.15,129.15,129.25 -2021-06-16 19:58:00,AAPL,129.33,129.2,129.2,129.33 +2021-06-16 20:00:00,AAPL,129.21,129.1,129.21,129.21 +2021-06-16 19:59:00,AAPL,129.22,129.15,129.15,129.25 +2021-06-16 19:58:00,AAPL,129.33,129.2,129.2,129.33 diff --git a/init/data/Users.csv b/init/data/Users.csv index e1491bc..63ebf52 100644 --- a/init/data/Users.csv +++ b/init/data/Users.csv @@ -1,10 +1,10 @@ -1,user1@gmail.com,$2b$12$wIFJhDVqFgvTX8nRENs5.uUtBpVZmgsEpgTgN6vFeRluy7riDl3vO,,, -2,user2@gmail.com,$2b$12$drK3vo5bvE.sM3XFoezJseAEp8grWu/Ahd5gL8qir4k4mOFFN92/O,,, -3,user3@gmail.com,$2b$12$XRmWWJYrR02Z6Dh1LFz73u67V5GwDSBgxwF300DAS4GbtPDDZ11.m,,, -4,user4@gmail.com,$2b$12$WpjkoreSHLLobze3LWDXmO7oPj2OdN01qIjIOufCHSz14OIwjfFf2,,, -5,user5@gmail.com,$2b$12$PGphjZB09baxtCPMFa8WA.p6Ri/Q5ZIAG.AzT6NLryQaDE0Nn0yO6,,, -6,user6@gmail.com,$2b$12$Tj.LIdkQlldq7PyS4qPuneV8pJm2.Qvi2CthMbkIGX8ecwx17MS5.,,, -7,user7@gmail.com,$2b$12$IDyQYvBSar3VIjkxaEDrWOUJJ/WvP.DW0gyA1t0oG.sXhANes9H12,,, -8,user8@gmail.com,$2b$12$8Nh7uzdAnc5Sk98o3qlexOXKaMQGd/BVQ1x6qUSyfx7QLbiCLPm4q,,, -9,user9@gmail.com,$2b$12$pNPLL73rtNcaZ3T4dsRcaetnUhsRzLMb9asXF5bI65u9.xcrMQLyy,,, -10,user10@gmail.com,$2b$12$H40Ad7BnYdzfT7pmC.7CSOZsHL16ePoIu0Bi8FOixOnEzxQ44vM2i,,, +1,user1@gmail.com,$2b$12$wIFJhDVqFgvTX8nRENs5.uUtBpVZmgsEpgTgN6vFeRluy7riDl3vO,,, +2,user2@gmail.com,$2b$12$drK3vo5bvE.sM3XFoezJseAEp8grWu/Ahd5gL8qir4k4mOFFN92/O,,, +3,user3@gmail.com,$2b$12$XRmWWJYrR02Z6Dh1LFz73u67V5GwDSBgxwF300DAS4GbtPDDZ11.m,,, +4,user4@gmail.com,$2b$12$WpjkoreSHLLobze3LWDXmO7oPj2OdN01qIjIOufCHSz14OIwjfFf2,,, +5,user5@gmail.com,$2b$12$PGphjZB09baxtCPMFa8WA.p6Ri/Q5ZIAG.AzT6NLryQaDE0Nn0yO6,,, +6,user6@gmail.com,$2b$12$Tj.LIdkQlldq7PyS4qPuneV8pJm2.Qvi2CthMbkIGX8ecwx17MS5.,,, +7,user7@gmail.com,$2b$12$IDyQYvBSar3VIjkxaEDrWOUJJ/WvP.DW0gyA1t0oG.sXhANes9H12,,, +8,user8@gmail.com,$2b$12$8Nh7uzdAnc5Sk98o3qlexOXKaMQGd/BVQ1x6qUSyfx7QLbiCLPm4q,,, +9,user9@gmail.com,$2b$12$pNPLL73rtNcaZ3T4dsRcaetnUhsRzLMb9asXF5bI65u9.xcrMQLyy,,, +10,user10@gmail.com,$2b$12$H40Ad7BnYdzfT7pmC.7CSOZsHL16ePoIu0Bi8FOixOnEzxQ44vM2i,,, diff --git a/init/initdata.sh b/init/initdata.sh index bd1611d..d9b15de 100644 --- a/init/initdata.sh +++ b/init/initdata.sh @@ -1,4 +1,4 @@ -#!/bin/bash - -psql -af ./init/create.sql quantx +#!/bin/bash + +psql -af ./init/create.sql quantx psql -af ./init/load.sql quantx \ No newline at end of file diff --git a/init/load.sql b/init/load.sql index dbfae7f..efccdca 100644 --- a/init/load.sql +++ b/init/load.sql @@ -1,3 +1,3 @@ --- \COPY Users FROM './init/data/Users.csv' WITH DELIMITER ',' NULL '' CSV; --- \COPY Symbol FROM './init/data/Symbols.csv' WITH DELIMITER ',' NULL '' CSV; +-- \COPY Users FROM './init/data/Users.csv' WITH DELIMITER ',' NULL '' CSV; +-- \COPY Symbol FROM './init/data/Symbols.csv' WITH DELIMITER ',' NULL '' CSV; -- \COPY Quote FROM './init/data/Quotes.csv' WITH DELIMITER ',' NULL '' CSV; \ No newline at end of file diff --git a/init/todo.txt b/init/todo.txt index 0f457c0..849305a 100644 --- a/init/todo.txt +++ b/init/todo.txt @@ -1,2 +1,2 @@ -- Create Result table +- Create Result table - Enforce only one competition entry per user \ No newline at end of file diff --git a/scripts/start.sh b/scripts/start.sh index f9421eb..fa955d6 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,3 +1,3 @@ -#!/bin/bash - +#!/bin/bash + docker build -t timedb . && docker run -d --name timedb -p 5432:5432 timedb \ No newline at end of file diff --git a/scripts/teardown.sh b/scripts/teardown.sh index 69ff684..f3bf30c 100644 --- a/scripts/teardown.sh +++ b/scripts/teardown.sh @@ -1,3 +1,3 @@ -#!/bin/bash - +#!/bin/bash + docker rm -f timedb \ No newline at end of file diff --git a/scripts/test_setup.py b/scripts/test_setup.py index 44449ad..87e80bc 100644 --- a/scripts/test_setup.py +++ b/scripts/test_setup.py @@ -1,14 +1,14 @@ -import os -import subprocess - -CURR_DIR = os.path.dirname(os.path.abspath(__file__)) -BASE_DIR = os.path.dirname(CURR_DIR) - -PYTHON = 'python3' - -def main(): - subprocess.call([PYTHON, os.path.join(CURR_DIR, "start.sh")]) - subprocess.call(os.path.join(CURR_DIR, 'teardown.sh')) - -if __name__ == "__main__": +import os +import subprocess + +CURR_DIR = os.path.dirname(os.path.abspath(__file__)) +BASE_DIR = os.path.dirname(CURR_DIR) + +PYTHON = 'python3' + +def main(): + subprocess.call([PYTHON, os.path.join(CURR_DIR, "start.sh")]) + subprocess.call(os.path.join(CURR_DIR, 'teardown.sh')) + +if __name__ == "__main__": main() \ No newline at end of file