Skip to content

Commit

Permalink
Merge pull request #78 from freezingsaddles/sync-private-tracks
Browse files Browse the repository at this point in the history
Sync private tracks for weather and maps, and fix weather date limits
  • Loading branch information
merlinorg authored Jan 1, 2025
2 parents eb573e1 + 3171cb1 commit a786f18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions freezing/sync/data/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
from freezing.model import meta
from freezing.model.orm import Athlete, Ride, RideTrack
from geoalchemy2.elements import WKTElement
from sqlalchemy import and_, or_, update
from sqlalchemy.orm import joinedload
from stravalib.exc import ObjectNotFound
from stravalib.model import Activity, Stream

from freezing.sync.config import config
from freezing.sync.exc import ActivityNotFound, ConfigurationError
from freezing.sync.exc import ActivityNotFound
from freezing.sync.utils import wktutils
from freezing.sync.utils.cache import CachingStreamFetcher

Expand All @@ -33,8 +32,8 @@ def sync_streams(

q = session.query(Ride).options(joinedload(Ride.athlete))

# We do not fetch streams for private rides. Or manual rides (since there would be none).
q = q.filter(and_(Ride.private == False, Ride.manual == False))
# We do not fetch streams for manual rides (since there would be none).
q = q.filter(Ride.manual == False)

if not rewrite:
q = q.filter(
Expand Down
8 changes: 4 additions & 4 deletions freezing/sync/data/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ def sync_weather(
self.logger.info("Fetching weather for all rides")

# Find rides that have geo, but no weather
# We only look at rides that ended over an hour ago, so we know there is weather observation rather than
# forecast, and we have to care that now() is in system timezone.
sess.query(orm.RideWeather)
q = text(
"""
select R.id, ST_AsText(G.start_geo) AS start_geo from rides R
join ride_geo G on G.ride_id = R.id
left join ride_weather W on W.ride_id = R.id
where W.ride_id is null
and date_add(CONVERT_TZ(R.start_date, R.timezone, '{0}'), INTERVAL R.elapsed_time SECOND) < (NOW() - INTERVAL 1 HOUR) -- Only include rides that ended over an hour ago
and date_add(CONVERT_TZ(R.start_date, R.timezone, 'SYSTEM'), INTERVAL R.elapsed_time SECOND) < (NOW() - INTERVAL 1 HOUR)
;
""".format(
config.TIMEZONE
)
"""
)

visual_crossing = HistoVisualCrossing(
Expand Down

0 comments on commit a786f18

Please sign in to comment.