From 7b3e94a78ae05ec3327c9f9b722a8953f9a5aa49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Fri, 22 Dec 2017 15:16:28 +0100 Subject: [PATCH] Area.slow_down_factor --- src/c3nav/editor/forms.py | 2 +- .../migrations/0066_area_slow_down_factor.py | 22 +++++++++++++++++++ src/c3nav/mapdata/models/geometry/space.py | 2 ++ src/c3nav/routing/router.py | 5 +++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/c3nav/mapdata/migrations/0066_area_slow_down_factor.py diff --git a/src/c3nav/editor/forms.py b/src/c3nav/editor/forms.py index e2d5dd38..4fe25b1a 100644 --- a/src/c3nav/editor/forms.py +++ b/src/c3nav/editor/forms.py @@ -226,7 +226,7 @@ def create_editor_form(editor_model): 'ordering', 'category', 'width', 'groups', 'color', 'priority', 'icon_name', 'base_altitude', 'waytype', 'access_restriction', 'height', 'default_height', 'door_height', 'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label', - 'origin_space', 'target_space', 'data', 'comment', + 'origin_space', 'target_space', 'data', 'comment', 'slow_down_factor', 'extra_seconds', 'speed', 'description', 'speed_up', 'description_up', 'allow_levels', 'allow_spaces', 'allow_areas', 'allow_pois', 'left', 'top', 'right', 'bottom'] field_names = [field.name for field in editor_model._meta.get_fields() if not field.one_to_many] diff --git a/src/c3nav/mapdata/migrations/0066_area_slow_down_factor.py b/src/c3nav/mapdata/migrations/0066_area_slow_down_factor.py new file mode 100644 index 00000000..5eb878be --- /dev/null +++ b/src/c3nav/mapdata/migrations/0066_area_slow_down_factor.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2017-12-22 14:08 +from __future__ import unicode_literals + +from decimal import Decimal +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mapdata', '0065_access_restriction_group'), + ] + + operations = [ + migrations.AddField( + model_name='area', + name='slow_down_factor', + field=models.DecimalField(decimal_places=2, default=1, max_digits=6, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))], verbose_name='slow down factor'), + ), + ] diff --git a/src/c3nav/mapdata/models/geometry/space.py b/src/c3nav/mapdata/models/geometry/space.py index 040ad3f4..39285b16 100644 --- a/src/c3nav/mapdata/models/geometry/space.py +++ b/src/c3nav/mapdata/models/geometry/space.py @@ -112,6 +112,8 @@ class Area(SpaceGeometryMixin, SpecificLocation, models.Model): An area in a space. """ geometry = GeometryField('polygon') + slow_down_factor = models.DecimalField(_('slow down factor'), max_digits=6, decimal_places=2, default=1, + validators=[MinValueValidator(Decimal('0.01'))]) class Meta: verbose_name = _('Area') diff --git a/src/c3nav/routing/router.py b/src/c3nav/routing/router.py index dd73dfa3..4c732c81 100644 --- a/src/c3nav/routing/router.py +++ b/src/c3nav/routing/router.py @@ -220,6 +220,11 @@ class Router: if edge.access_restriction: restrictions.setdefault(edge.access_restriction, RouterRestriction()).edges.append(index) + for area in areas: + if area.slow_down_factor != 1: + area_nodes = np.array(area.nodes) + graph[area_nodes.reshape((-1, 1)), area_nodes] *= float(area.slow_down_factor) + # finalize waytype matrixes for waytype in waytypes: waytype.upwards_indices = np.array(waytype.upwards_indices, dtype=np.uint32).reshape((-1, 2))