Skip to content

Commit

Permalink
Log specific issues with DSR fields in validator
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianDAlessandro committed Nov 14, 2023
1 parent 891705b commit 541e933
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion datahub/dsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from numpy.typing import NDArray
from pydantic import BaseModel, Field

from . import log


class DSRModel(BaseModel):
"""Define required key values for Demand Side Response data."""
Expand Down Expand Up @@ -76,10 +78,14 @@ def validate_dsr_data(data: dict[str, NDArray | str]) -> None:
array.dtype, np.number
):
aliases.append(alias)
log.error(
f"'{alias}' has shape {array.shape}, expected {field['shape']}"
)

if aliases:
raise HTTPException(
status_code=422,
detail=f"Invalid size for: {', '.join(aliases)}.",
detail=f"Invalid size or data type for: {', '.join(aliases)}.",
)


Expand Down
4 changes: 2 additions & 2 deletions datahub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create_opal_data(data: OpalModel | OpalArrayData) -> dict[str, str]:
Returns:
A Dict of the Opal data that has just been added to the Dataframe
""" # noqa: D301
log.info("Recieved Opal data.")
log.info("Received Opal data.")

raw_data = data.dict()

Expand Down Expand Up @@ -141,7 +141,7 @@ def upload_dsr(file: UploadFile) -> dict[str, str | None]:
Returns:
dict[str, str]: dictionary with the filename
""" # noqa: D301
log.info("Recieved Opal data.")
log.info("Received Opal data.")
data = read_dsr_file(file.file)

validate_dsr_data(data)
Expand Down

0 comments on commit 541e933

Please sign in to comment.