Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add time zone in import #72

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions code/routers/city.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ async def get_average_measurements_by_city(
now = datetime.now(timezone.utc)
start = now - timedelta(hours=1)

LOWER, UPPER = Dimension.get_filter_threshold(Dimension.PM2_5)

q = (
db.query(
Values.dimension,
Expand All @@ -78,8 +76,6 @@ 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)
)

Expand Down
6 changes: 4 additions & 2 deletions code/services/data_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def sensor_community_import_grouped_by_location(db: Session, data: dict, source:
Station.location == loc
).first()

timestamp = datetime.strptime(row['timestamp'], "%Y-%m-%d %H:%M:%S").replace(tzinfo=timezone.utc)

# create if not exists
if not station:
# creaet station
Expand All @@ -34,12 +36,12 @@ def sensor_community_import_grouped_by_location(db: Session, data: dict, source:
firmware = None,
apikey = None,
location_id = loc.id,
last_active = row['timestamp'],
last_active = timestamp,
source = source
)

# update last_active
station.last_active = row['timestamp']
station.last_active = timestamp

db.add(station)
db.commit()
Expand Down