prepare tables
This commit is contained in:
parent
fe45c913a6
commit
4828b84d79
@ -20,6 +20,8 @@ LOGGING_TO_FILE: Final[bool] = True
|
||||
LOGGING_TO_STDERR: Final[bool] = True
|
||||
LOG_FILENAME: Final[str] = "dopt-delbar.log"
|
||||
|
||||
# ** databases
|
||||
DB_ECHO: Final[bool] = True
|
||||
|
||||
# ** error handling
|
||||
DEFAULT_INTERNAL_ERR_CODE: Final[int] = 100
|
||||
|
||||
61
src/delta_barth/databases.py
Normal file
61
src/delta_barth/databases.py
Normal file
@ -0,0 +1,61 @@
|
||||
from pathlib import Path
|
||||
|
||||
import sqlalchemy as sql
|
||||
|
||||
from delta_barth.constants import DB_ECHO
|
||||
|
||||
# ** meta
|
||||
metadata = sql.MetaData()
|
||||
|
||||
|
||||
def get_engine(
|
||||
db_path: Path,
|
||||
) -> sql.Engine:
|
||||
path = db_path.resolve()
|
||||
connection_str: str = f"sqlite:///{str(path)}"
|
||||
engine = sql.create_engine(connection_str, echo=DB_ECHO)
|
||||
return engine
|
||||
|
||||
|
||||
# ** table declarations
|
||||
# ** ---- common
|
||||
perf_meas = sql.Table(
|
||||
"performance_measurement",
|
||||
metadata,
|
||||
sql.Column("id", sql.Integer, primary_key=True),
|
||||
sql.Column("execution_duration", sql.Float),
|
||||
sql.Column("pipeline_name", sql.String(length=30)),
|
||||
)
|
||||
# ** ---- forecasts
|
||||
sf_stats = sql.Table(
|
||||
"sales_forecast_statistics",
|
||||
metadata,
|
||||
sql.Column("id", sql.Integer, primary_key=True),
|
||||
sql.Column("error_code", sql.Integer),
|
||||
sql.Column("error_msg", sql.String(length=200)),
|
||||
sql.Column("length_dataset", sql.Integer),
|
||||
sql.Column("score_mae", sql.Float, nullable=True),
|
||||
sql.Column("score_r2", sql.Float, nullable=True),
|
||||
sql.Column("best_start_year", sql.Integer, nullable=True),
|
||||
)
|
||||
sf_XGB = sql.Table(
|
||||
"sales_forecast_XGB_parameters",
|
||||
metadata,
|
||||
sql.Column("id", sql.Integer, primary_key=True),
|
||||
sql.Column(
|
||||
"forecast_id",
|
||||
sql.Integer,
|
||||
sql.ForeignKey(
|
||||
"sales_forecast_statistics.id", onupdate="CASCADE", ondelete="CASCADE"
|
||||
),
|
||||
unique=True,
|
||||
),
|
||||
sql.Column("n_estimators", sql.Integer),
|
||||
sql.Column("learning_rate", sql.Float),
|
||||
sql.Column("max_depth", sql.Integer),
|
||||
sql.Column("min_child_weight", sql.Integer),
|
||||
sql.Column("gamma", sql.Float),
|
||||
sql.Column("subsample", sql.Float),
|
||||
sql.Column("colsample_bytree", sql.Float),
|
||||
sql.Column("early_stopping_rounds", sql.Integer),
|
||||
)
|
||||
Loading…
x
Reference in New Issue
Block a user