-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from anxkhn/main
feat: validate generation values against site capacity
- Loading branch information
Showing
3 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
/src/.env | ||
.env | ||
*.pyc | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
from fastapi.responses import FileResponse, Response | ||
from pvlib import irradiance, location, pvsystem | ||
from pvsite_datamodel.pydantic_models import GenerationSum, PVSiteEditMetadata | ||
from pvsite_datamodel.read.site import get_site_by_uuid | ||
from pvsite_datamodel.read.status import get_latest_status | ||
from pvsite_datamodel.read.user import get_user_by_email | ||
from pvsite_datamodel.write.generation import insert_generation_values | ||
|
@@ -276,7 +277,26 @@ def post_pv_actual( | |
} | ||
) | ||
|
||
# Set the error generation capacity factor from environment variable | ||
capacity_factor = float(os.getenv("ERROR_GENERATION_CAPACITY_FACTOR", 1.1)) | ||
|
||
generation_values_df = pd.DataFrame(generations) | ||
site = get_site_by_uuid(session=session, site_uuid=site_uuid) | ||
site_capacity_kw = site.capacity_kw | ||
exceeded_capacity = generation_values_df[ | ||
generation_values_df["power_kw"] > site_capacity_kw * capacity_factor | ||
] | ||
if len(exceeded_capacity) > 0: | ||
raise HTTPException( | ||
status_code=422, | ||
detail=( | ||
f"Error processing generation values. " | ||
f"One (or more) values are larger than {capacity_factor} " | ||
f"times the site capacity of {site_capacity_kw} kWp. " | ||
"Please adjust this generation value, the site capacity, " | ||
"or contact [email protected]." | ||
), | ||
) | ||
|
||
logger.debug(f"Adding {len(generation_values_df)} generation values") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters