-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from dev-abuke/database
Database
- Loading branch information
Showing
5 changed files
with
735 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
import os | ||
|
||
DATABASE_URL = os.getenv('DATABASE_URL', "postgresql+psycopg2://group_three:lbRFEbA2bf3g5x6iDRrIsNqLycCznpab@dpg-cp6uiansc6pc73cnh6f0-a.oregon-postgres.render.com/amharic_contents") | ||
|
||
engine = create_engine(DATABASE_URL) | ||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | ||
Base = declarative_base() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from sqlalchemy import Column, Integer, Float, Date, ForeignKey, TIMESTAMP | ||
from sqlalchemy.orm import relationship | ||
from .database import Base | ||
|
||
class Scene(Base): | ||
__tablename__ = 'scenes' | ||
id = Column(Integer, primary_key=True, index=True) | ||
period = Column(Integer, nullable=False) | ||
start_date = Column(Date, nullable=False) | ||
end_date = Column(Date, nullable=False) | ||
backtests = relationship('BacktestResult', back_populates='scene') | ||
|
||
class BacktestResult(Base): | ||
__tablename__ = 'backtest_results' | ||
id = Column(Integer, primary_key=True, index=True) | ||
scene_id = Column(Integer, ForeignKey('scenes.id')) | ||
gross_profit = Column(Float, nullable=False) | ||
net_profit = Column(Float, nullable=False) | ||
number_of_trades = Column(Integer, nullable=False) | ||
winning_trades = Column(Integer) | ||
losing_trades = Column(Integer) | ||
max_drawdown = Column(Float) | ||
sharpe_ratio = Column(Float) | ||
created_at = Column(TIMESTAMP, server_default='CURRENT_TIMESTAMP') | ||
scene = relationship('Scene', back_populates='backtests') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
CREATE TABLE backtest_results ( | ||
id SERIAL PRIMARY KEY, | ||
scene_id INT REFERENCES scenes(id), | ||
gross_profit FLOAT NOT NULL, | ||
net_profit FLOAT NOT NULL, | ||
number_of_trades INT NOT NULL, | ||
winning_trades INT, | ||
losing_trades INT, | ||
max_drawdown FLOAT, | ||
sharpe_ratio FLOAT, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TABLE scenes ( | ||
id SERIAL PRIMARY KEY, | ||
period INT NOT NULL, | ||
start_date DATE NOT NULL, | ||
end_date DATE NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS users ( | ||
"id" SERIAL PRIMARY KEY NOT NULL, | ||
"name" varchar NOT NULL, | ||
"email" varchar NOT NULL, | ||
"password" varchar NOT NULL, | ||
"created_at" timestamp NOT NULL | ||
"updated_at" timestamp NOT NULL | ||
"deleted_at" timestamp NOT NULL | ||
|
||
UNIQUE (email) | ||
); | ||
|
||
CREATE TABLE indicators ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(50) NOT NULL, | ||
description TEXT | ||
); |
Oops, something went wrong.