Skip to content

Commit 9fcc2be

Browse files
authored
Merge pull request #507 from mapswipe/fix-footprint-tutorial
fix order or tutorial screens
2 parents 431e02e + cff4578 commit 9fcc2be

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

mapswipe_workers/mapswipe_workers/project_types/arbitrary_geometry/grouping_functions.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22

33

4-
def group_input_geometries(input_geometries_file, group_size):
4+
def group_input_geometries(input_geometries_file, group_size, tutorial=False):
55
"""
66
The function to create groups of input geometries using the given size (number of
77
features) per group
@@ -12,6 +12,8 @@ def group_input_geometries(input_geometries_file, group_size):
1212
the path to the GeoJSON file containing the input geometries
1313
group_size : int
1414
the maximum number of features per group
15+
tutorial: boolean
16+
if this function is called to create the grouping within a tutorial
1517
1618
Returns
1719
-------
@@ -44,7 +46,15 @@ def group_input_geometries(input_geometries_file, group_size):
4446

4547
# we use a new id here based on the count
4648
# since we are not sure that GetFID returns unique values
47-
groups[group_id_string]["feature_ids"].append(feature_count)
49+
if not tutorial:
50+
groups[group_id_string]["feature_ids"].append(feature_count)
51+
else:
52+
# In the tutorial the feature id is defined by the "screen" attribute.
53+
# We do this so that we can sort by the feature id later and
54+
# get the screens displayed in the right order on the app.
55+
groups[group_id_string]["feature_ids"].append(
56+
feature["properties"]["screen"]
57+
)
4858
groups[group_id_string]["features"].append(feature)
4959

5060
return groups

mapswipe_workers/mapswipe_workers/project_types/arbitrary_geometry/tutorial.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
22

3+
import numpy as np
4+
35
from mapswipe_workers.definitions import DATA_PATH, logger
46
from mapswipe_workers.project_types.arbitrary_geometry import grouping_functions as g
57
from mapswipe_workers.project_types.arbitrary_geometry.group import Group
@@ -53,11 +55,23 @@ def create_tutorial_tasks(self):
5355
"""Create the tasks dict based on provided examples in geojson file."""
5456

5557
raw_groups = g.group_input_geometries(
56-
self.inputGeometries, len(self.tutorial_tasks) + 1
58+
self.inputGeometries,
59+
len(self.tutorial_tasks["features"]) + 1,
60+
tutorial=True,
5761
)
62+
5863
for group_id, item in raw_groups.items():
5964
group = Group(self, groupId=101)
60-
group.create_tasks(item["feature_ids"], item["features"])
65+
66+
# Make sure that we sort the tasks.
67+
# For the tutorial the feature_id represents the number of the screen.
68+
# The group_input_geometries functions doesn't return
69+
# the screens in the right order.
70+
sorted_idx = np.array(item["feature_ids"]).argsort()
71+
sorted_feature_ids = [item["feature_ids"][x] for x in sorted_idx]
72+
sorted_features = [item["features"][x] for x in sorted_idx]
73+
74+
group.create_tasks(sorted_feature_ids, sorted_features)
6175

6276
for task in group.tasks:
6377
logger.info(task)

0 commit comments

Comments
 (0)