Vertikalni profil trasy, generovani bodu v planu
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import math
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from sqlalchemy import select, delete
|
||||
from database import models
|
||||
from database.transaction import get_session
|
||||
from utils.gps import generate_points, get_bearing
|
||||
from utils.gps import generate_points
|
||||
|
||||
|
||||
async def generate_track_for_flight_plan(flight_plan_id: int):
|
||||
@@ -44,8 +42,6 @@ async def generate_track_for_flight_plan(flight_plan_id: int):
|
||||
point_to = (to.gps_latitude, to.gps_longitude)
|
||||
points_between = generate_points(point_from, point_to)
|
||||
|
||||
print(delta_t_sec, speed_m_s, "AAAAAAAAAAAA")
|
||||
|
||||
for point in points_between:
|
||||
await models.TrackPoint.create(db, {
|
||||
"track_id": track.id,
|
||||
|
||||
@@ -2,6 +2,8 @@ import asyncio
|
||||
from typing import Optional
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
|
||||
from background_jobs.flight_plan_track import generate_track_for_flight_plan
|
||||
from database import models
|
||||
from database.models import flight_plan_has_copilot
|
||||
from database.transaction import get_session
|
||||
@@ -10,6 +12,7 @@ from graphql_schema.entities.resolvers.base import BaseMutationResolver, BaseQue
|
||||
from graphql_schema.entities.resolvers.flight import handle_aircraft_save
|
||||
from graphql_schema.entities.types.mutation_input import CreateFlightPlanInput, EditFlightPlanInput
|
||||
from graphql_schema.entities.types.types import FlightPlan
|
||||
from utils.list_utils import evenly_spaced_elements
|
||||
from utils.str_utils import random_str
|
||||
|
||||
|
||||
@@ -70,8 +73,6 @@ class FlightPlanMutationResolver(BaseMutationResolver):
|
||||
})
|
||||
position += 1
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
async def reset_plan_markers(db, flight_plan: models.FlightPlan):
|
||||
await db.execute(
|
||||
@@ -118,7 +119,10 @@ class FlightPlanMutationResolver(BaseMutationResolver):
|
||||
if data.markers:
|
||||
markers = data.markers
|
||||
else:
|
||||
markers = (await db.scalars(select(models.FlightPlanMarker).filter(models.FlightPlanMarker.flight_plan_id == id))).all()
|
||||
markers = (await db.scalars(
|
||||
select(models.FlightPlanMarker)
|
||||
.filter(models.FlightPlanMarker.flight_plan_id == id)
|
||||
)).all()
|
||||
|
||||
used_markers = evenly_spaced_elements(markers, 5)
|
||||
input_data['name'] = " - ".join(m.name for m in used_markers)
|
||||
@@ -132,11 +136,7 @@ class FlightPlanMutationResolver(BaseMutationResolver):
|
||||
)
|
||||
|
||||
flight_plan = await self._do_update(db, obj=flight_plan_model, data=input_data)
|
||||
return flight_plan
|
||||
|
||||
await generate_track_for_flight_plan(flight_plan.id)
|
||||
|
||||
def evenly_spaced_elements(lst: list, count: int) -> list:
|
||||
if count > len(lst):
|
||||
return lst
|
||||
interval = (len(lst) - 1) / (count - 1) if count > 1 else 0
|
||||
return [lst[int(round(i * interval))] for i in range(count)]
|
||||
return flight_plan
|
||||
|
||||
@@ -40,8 +40,6 @@ async def add_elevation_to_tracks():
|
||||
print("all done")
|
||||
return
|
||||
await update_track_points_elevation(db, track_points)
|
||||
await db.flush()
|
||||
await db.commit()
|
||||
|
||||
|
||||
async def run_all():
|
||||
|
||||
@@ -12,3 +12,10 @@ def chunks(items: list | dict, n: int) -> typing.Generator:
|
||||
it = iter(items)
|
||||
for i in range(0, len(items), n):
|
||||
yield {k: items[k] for k in islice(it, n)}
|
||||
|
||||
|
||||
def evenly_spaced_elements(lst: list, count: int) -> list:
|
||||
if count > len(lst):
|
||||
return lst
|
||||
interval = (len(lst) - 1) / (count - 1) if count > 1 else 0
|
||||
return [lst[int(round(i * interval))] for i in range(count)]
|
||||
|
||||
Reference in New Issue
Block a user