Skip to content

Commit

Permalink
Merge pull request #69 from luftdaten-at/67-city-current-filter-outlier
Browse files Browse the repository at this point in the history
added filter in city current for pm2_5
  • Loading branch information
n11ik authored Feb 19, 2025
2 parents da9cf9c + d576238 commit ba3683f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions code/routers/city.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi import APIRouter, Depends, HTTPException, Query, Response
from sqlalchemy.orm import Session
from database import get_db
from sqlalchemy import func, desc
from sqlalchemy import func, or_, distinct, and_
from datetime import datetime, timezone, timedelta
from zoneinfo import ZoneInfo

Expand Down Expand Up @@ -60,7 +60,7 @@ async def get_average_measurements_by_city(
now = datetime.now(timezone.utc)
start = now - timedelta(hours=1)

from sqlalchemy import distinct
LOWER, UPPER = Dimension.get_filter_threshold(Dimension.PM2_5)

q = (
db.query(
Expand All @@ -77,9 +77,13 @@ async def get_average_measurements_by_city(
.filter(City.slug == city_slug)
.filter(Values.value != 'nan')
.filter(Measurement.time_measured >= start)
# filter outlier
.filter(or_(Values.dimension != Dimension.PM2_5, and_(LOWER <= Values.value, Values.value <= UPPER)))
.group_by(Values.dimension)
)

print(len(q.all()))

station_count = db.query(Station).join(Location).join(City).filter(City.slug == city_slug).count()

j = {
Expand Down

0 comments on commit ba3683f

Please sign in to comment.