|
5 | 5 | from typing import Optional
|
6 | 6 | from fastapi import HTTPException
|
7 | 7 | from uuid import UUID
|
| 8 | +import sentry_sdk |
8 | 9 |
|
9 | 10 | from pvsite_datamodel import DatabaseConnection
|
10 | 11 | from pvsite_datamodel.read import (
|
@@ -370,6 +371,31 @@ def post_site_generation(
|
370 | 371 | )
|
371 | 372 |
|
372 | 373 | generation_values_df = pd.DataFrame(generations)
|
| 374 | + capacity_factor = 1.1 |
| 375 | + site = get_site_by_uuid(session=session, site_uuid=site_uuid) |
| 376 | + site_capacity_kw = site.capacity_kw |
| 377 | + exceeded_capacity = generation_values_df[ |
| 378 | + generation_values_df["power_kw"] > site_capacity_kw * capacity_factor |
| 379 | + ] |
| 380 | + if len(exceeded_capacity) > 0: |
| 381 | + # alert Sentry and return 422 validation error |
| 382 | + sentry_sdk.capture_message( |
| 383 | + f"Error processing generation values. " |
| 384 | + f"One (or more) values are larger than {capacity_factor} " |
| 385 | + f"times the site capacity of {site_capacity_kw} kWp. " |
| 386 | + # f"User: {auth['https://openclimatefix.org/email']}" |
| 387 | + f"Site: {site_uuid}" |
| 388 | + ) |
| 389 | + raise HTTPException( |
| 390 | + status_code=422, |
| 391 | + detail=( |
| 392 | + f"Error processing generation values. " |
| 393 | + f"One (or more) values are larger than {capacity_factor} " |
| 394 | + f"times the site capacity of {site_capacity_kw} kWp. " |
| 395 | + "Please adjust this generation value, the site capacity, " |
| 396 | + "or contact quartz.support@openclimatefix.org." |
| 397 | + ), |
| 398 | + ) |
373 | 399 |
|
374 | 400 | insert_generation_values(session, generation_values_df)
|
375 | 401 | session.commit()
|
|
0 commit comments