From 3ba7b0e3d57763314e77a6e8f27c1ba5462426de Mon Sep 17 00:00:00 2001 From: Oleksiy Protas Date: Tue, 22 Aug 2017 01:00:15 +0300 Subject: [PATCH] Altitude re-enabled Temporary countermeasure against #256 --- backend/promis/backend_api/models.py | 4 ++++ backend/promis/backend_api/serializer.py | 4 +++- backend/promis/classes/potential.py | 8 ++++++-- frontend/app/components/CesiumMap.js | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/promis/backend_api/models.py b/backend/promis/backend_api/models.py index ae92492..ca09e30 100644 --- a/backend/promis/backend_api/models.py +++ b/backend/promis/backend_api/models.py @@ -3,6 +3,7 @@ from django.db import models from django.db.models.fields import ( DateTimeField, IntegerField, CharField, DateField, FloatField, TextField ) +from django.contrib.postgres.fields import ArrayField from django.db.models.fields.related import ForeignKey from jsonfield import JSONField from django.contrib.gis.db.models import LineStringField @@ -92,6 +93,9 @@ class Session(models.Model): # but ensures distances and intersections are caclulated correctly # TODO: srid should eventually be 4979 see #222 geo_line = LineStringField(dim = 3, srid = 4326, geography=True) + + # TODO: 4D coordinates, see #256 + altitude = ArrayField(FloatField()) space_project = ForeignKey('Space_project', null = True) class Meta: diff --git a/backend/promis/backend_api/serializer.py b/backend/promis/backend_api/serializer.py index c193dee..cfbc616 100644 --- a/backend/promis/backend_api/serializer.py +++ b/backend/promis/backend_api/serializer.py @@ -83,7 +83,9 @@ def get_geo_line(self, obj): #return obj.geo_line.wkb.hex() # TODO: study whether pre-building the list or JSON would speed up things - return parsers.wkb(obj.geo_line.wkb) # <- Generator + # TODO: ugly hack before #256 + # geo_line.wkb calls a generator implicitly + return ( (*geo[:2], alt) for alt, geo in zip(obj.altitude, parsers.wkb(obj.geo_line.wkb)) ) def get_timelapse(self, obj): # TODO: change to time_start in model for consistency diff --git a/backend/promis/classes/potential.py b/backend/promis/classes/potential.py index 921e454..e1b09e0 100644 --- a/backend/promis/classes/potential.py +++ b/backend/promis/classes/potential.py @@ -132,7 +132,10 @@ def fetch(self, daydir): ez_time_end = time_end # Generator for the orbit - line_gen = ( (y.lon, y.lat, t) for t, y, _ in orbit.generate_orbit(orbit_path, time_start, time_end) ) + # TODO: rewrite as generator if possible at all + path = [ (y.lon, y.lat, y.alt, t) for t, y, _ in orbit.generate_orbit(orbit_path, time_start, time_end) ] + line_gen = [ (x, y, t) for x, y, _, t in path ] + alt_gen = [ alt for _, _, alt, _ in path ] # Converting time to python objects for convenience # This is the point where onboard time gets converted to the UTC time_start = unix_time.maketime(time_start) @@ -143,7 +146,8 @@ def fetch(self, daydir): # Creating a session object # TODO: make it more readable # TODO: srid should be 4979 see #222 - ez_sess_obj = model.Session.objects.create(time_begin = time_start, time_end = time_end, geo_line = LineString(*line_gen, srid = 4326), space_project = self.project_obj ) + ez_sess_obj = model.Session.objects.create(time_begin = time_start, time_end = time_end, altitude = alt_gen, + geo_line = LineString(*line_gen, srid = 4326), space_project = self.project_obj ) # TODO: record data_id in the object # TODO: somehow generalise this process maybe diff --git a/frontend/app/components/CesiumMap.js b/frontend/app/components/CesiumMap.js index c11bf9e..896904e 100644 --- a/frontend/app/components/CesiumMap.js +++ b/frontend/app/components/CesiumMap.js @@ -486,7 +486,7 @@ export default class CesiumContainer extends Component { /* data is [lat, lon, hgt] */ data.forEach(function(point) { // TODO temporary disabling altitude because it stores time temporarily - cartesians.push(Cartesian3.fromDegrees(point[1], point[0], /*point[2] ? point[2] :*/ 250000)); + cartesians.push(Cartesian3.fromDegrees(point[1], point[0], point[2] ? point[2] *1000 : 250000)); }); return this.viewer.entities.add({