Skip to content

Commit

Permalink
feat : add script for loading positions of the test dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan committed Feb 12, 2024
1 parent be4a194 commit 52526b1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ share/python-wheels/
*.egg
MANIFEST
zones_subset_02022024.csv

spire_positions_subset_02022024.csv

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ launch-dev-db:
load-amp-data:
$(BLOOM_DEV_DOCKER) --rm d4g/bloom:${VERSION} /venv/bin/python3 alembic/init_script/load_amp_data.py

load-test-positions-data:
$(BLOOM_DEV_DOCKER) --rm d4g/bloom:${VERSION} /venv/bin/python3 alembic/init_script/load_positions_data.py

launch-dev-container:
$(BLOOM_DEV_DOCKER) -dti d4g/bloom:${VERSION} /bin/bash

Expand Down
36 changes: 36 additions & 0 deletions alembic/init_script/load_positions_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import logging
import os
from pathlib import Path

import pandas as pd
from sqlalchemy import create_engine

logging.basicConfig()
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO)

postgres_user = os.environ.get("POSTGRES_USER")
postgres_password = os.environ.get("POSTGRES_PASSWORD")
postgres_hostname = os.environ.get("POSTGRES_HOSTNAME")
postgres_db = os.environ.get("POSTGRES_DB")
postgres_port = os.environ.get("POSTGRES_PORT")

# The db url is configured with the db connexion variables declared in the db.yaml file.
db_url = (
"postgresql://"
+ postgres_user
+ ":"
+ postgres_password
+ "@"
+ postgres_hostname
+ ":"
+ postgres_port
+ "/"
+ postgres_db
)
engine = create_engine(db_url)
df = pd.read_csv(
Path.joinpath(Path.cwd(), "spire_positions_subset_02022024.csv"),
sep=","
)

df.to_sql("spire_vessel_positions", engine, if_exists="append", index=False)

0 comments on commit 52526b1

Please sign in to comment.