improve route serialization
This commit is contained in:
parent
dfe7d10574
commit
480850b8ea
1 changed files with 25 additions and 1 deletions
|
@ -3,6 +3,7 @@ import copy
|
|||
from collections import OrderedDict, deque
|
||||
|
||||
import numpy as np
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
|
@ -37,13 +38,36 @@ class RouteItem:
|
|||
self.edge = edge
|
||||
self.last_item = last_item
|
||||
|
||||
@cached_property
|
||||
def waytype(self):
|
||||
if self.edge and self.edge.waytype:
|
||||
return self.route.router.waytypes[self.edge.waytype]
|
||||
|
||||
@cached_property
|
||||
def space(self):
|
||||
return self.route.router.spaces[self.node.space]
|
||||
|
||||
@cached_property
|
||||
def level(self):
|
||||
return self.route.router.levels[self.space.level_id]
|
||||
|
||||
def serialize(self):
|
||||
return OrderedDict((
|
||||
result = OrderedDict((
|
||||
('id', self.node.pk),
|
||||
('coords', (self.node.x, self.node.y, self.node.altitude)),
|
||||
('waytype', (self.route.router.waytypes[self.edge.waytype].serialize(detailed=False)
|
||||
if self.edge and self.edge.waytype else None)),
|
||||
))
|
||||
if self.waytype:
|
||||
result['waytype'] = self.waytype.serialize(detailed=False)
|
||||
|
||||
if not self.last_item or self.space.pk != self.last_item.space.pk:
|
||||
result['space'] = self.space.serialize(detailed=False)
|
||||
|
||||
if not self.last_item or self.level.pk != self.last_item.level.pk:
|
||||
result['level'] = self.level.serialize(detailed=False)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
class NoRoute:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue