-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
165 additions
and
13 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import datetime as dt | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Depends, Query | ||
from geoalchemy2 import WKTElement | ||
from sqlalchemy.orm import Session | ||
|
||
from aross_stations_db.api.v1.output import ( | ||
ClimatologyJsonElement, | ||
climatology_query_results_to_json, | ||
) | ||
from aross_stations_db.middleware import get_db_session | ||
from aross_stations_db.query import climatology_query | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/monthly") | ||
def get_monthly_climatology( | ||
db: Annotated[Session, Depends(get_db_session)], | ||
*, | ||
start: Annotated[dt.datetime, Query(description="ISO-format timestamp")], | ||
end: Annotated[dt.datetime, Query(description="ISO-format timestamp")], | ||
polygon: Annotated[str | None, WKTElement, Query(description="WKT shape")] = None, | ||
) -> list[ClimatologyJsonElement]: | ||
"""Get a monthly climatology of events matching query parameters.""" | ||
# TODO: Validate query spans >1 year? Or >= 2 years? Should the query parameters be | ||
# changed to enforce best practices for visualizing a climatology (e.g. there | ||
# should always be the same number of Januaries as Februaries as ...etc., so we | ||
# could accept a start year, end year, and start month.) | ||
query = climatology_query(db=db, start=start, end=end, polygon=polygon) | ||
|
||
return climatology_query_results_to_json(query.all()) |
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
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,9 +1,10 @@ | ||
from fastapi import APIRouter | ||
|
||
from aross_stations_db.api.v1.climatology import router as climatology_router | ||
from aross_stations_db.api.v1.stations import router as stations_router | ||
from aross_stations_db.api.v1.timeseries import router as timeseries_router | ||
|
||
router = APIRouter() | ||
router.include_router(stations_router, prefix="/stations") | ||
router.include_router(timeseries_router, prefix="/events/timeseries") | ||
# router.include_router(climatology_router, prefix="/events/climatology") | ||
router.include_router(climatology_router, prefix="/events/climatology") |
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