Skip to content

Commit

Permalink
Merge pull request #3 from dev-abuke/database
Browse files Browse the repository at this point in the history
Database
  • Loading branch information
dev-abuke authored Jun 21, 2024
2 parents d319723 + f3c7b5b commit 41ae2a6
Show file tree
Hide file tree
Showing 5 changed files with 735 additions and 29 deletions.
10 changes: 10 additions & 0 deletions backend/database.py
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()
25 changes: 25 additions & 0 deletions backend/models.py
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')
37 changes: 37 additions & 0 deletions db/schema/schema.sql
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
);
Loading

0 comments on commit 41ae2a6

Please sign in to comment.