Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/t 59 cpf naming #98

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/api/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ def create_cpf_summary(self, data_path: Path):
paths = data_path.glob("cpf/*_cpf_columns.parquet")
for path in paths:
df = pd.read_parquet(path)
# replacing col name row values with cpf alias value in shotmodel
df["name"] = df["name"].apply(
lambda x: models.ShotModel.__fields__.get("cpf_" + x.lower()).alias
if models.ShotModel.__fields__.get("cpf_" + x.lower())
else x
)
df.to_sql("cpf_summary", self.uri, if_exists="replace")

def create_scenarios(self, data_path: Path):
Expand Down Expand Up @@ -243,7 +249,7 @@ def create_db_and_tables(data_path):

# populate the database tables
logging.info("Create CPF summary")
client.create_cpf_summary(data_path / "cpf")
client.create_cpf_summary(data_path)

logging.info("Create Scenarios")
client.create_scenarios(data_path)
Expand All @@ -262,4 +268,5 @@ def create_db_and_tables(data_path):

if __name__ == "__main__":
dask.config.set({"dataframe.convert-string": False})
# print(models.ShotModel.__fields__)
create_db_and_tables()
2 changes: 1 addition & 1 deletion src/api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def apply_filters(query: Query, filters: str) -> Query:
def apply_sorting(query: Query, sort: t.Optional[str] = None) -> Query:
if sort is None:
return query

if sort.startswith("-"):
sort = sort[1:]
order = desc(column(sort))
Expand Down
Loading
Loading