55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import asyncio
|
|
import sys
|
|
from sqlalchemy import select
|
|
|
|
sys.path.insert(0, "/app/src")
|
|
from paths import FLIGHT_GPX_TRACK_PATH # noqa
|
|
from database import async_session, models # noqa
|
|
from external.elevation import elevation_api, update_track_points_elevation # noqa
|
|
from external.gpx_parser import GPXParser # noqa
|
|
from database.transaction import get_session
|
|
|
|
|
|
async def add_elevation_to_photos():
|
|
async with get_session() as db:
|
|
photos = (await db.scalars(
|
|
select(models.Photo)
|
|
.filter(models.Photo.terrain_elevation.is_(None))
|
|
)).all()
|
|
|
|
coordinates = [
|
|
{"lat": p.gps_latitude, "lng": p.gps_longitude, "id": p.id} for p in photos if p.gps_latitude or p.gps_longitude
|
|
]
|
|
if not coordinates:
|
|
print("all done")
|
|
return
|
|
|
|
points = await elevation_api.get_elevation_for_points(coordinates)
|
|
for point in points:
|
|
await models.Photo.update(db_session=db, id=point.id, data={"terrain_elevation": point.elevation})
|
|
|
|
|
|
async def add_elevation_to_tracks():
|
|
async with get_session() as db:
|
|
track_points = (await db.scalars(
|
|
select(models.TrackPoint)
|
|
.filter(models.TrackPoint.terrain_elevation.is_(None))
|
|
)).all()
|
|
|
|
if not track_points:
|
|
print("all done")
|
|
return
|
|
await update_track_points_elevation(db, track_points)
|
|
|
|
|
|
async def run_all():
|
|
await asyncio.gather(
|
|
add_elevation_to_photos(),
|
|
add_elevation_to_tracks()
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
loop = asyncio.get_event_loop()
|
|
loop.run_until_complete(run_all())
|