Skip to content

Commit 8c9d774

Browse files
committed
WIP: add tutorial for street project
1 parent dadca06 commit 8c9d774

File tree

8 files changed

+259
-13
lines changed

8 files changed

+259
-13
lines changed

mapswipe_workers/mapswipe_workers/definitions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,14 @@ def tutorial(self):
170170
ClassificationTutorial,
171171
CompletenessTutorial,
172172
FootprintTutorial,
173+
StreetTutorial,
173174
)
174175

175176
project_type_classes = {
176177
1: ClassificationTutorial,
177178
2: FootprintTutorial,
178179
3: ChangeDetectionTutorial,
179180
4: CompletenessTutorial,
181+
7: StreetTutorial,
180182
}
181183
return project_type_classes[self.value]

mapswipe_workers/mapswipe_workers/project_types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .arbitrary_geometry.footprint.tutorial import FootprintTutorial
44
from .media_classification.project import MediaClassificationProject
55
from .street.project import StreetProject
6+
from .street.tutorial import StreetTutorial
67
from .tile_map_service.change_detection.project import ChangeDetectionProject
78
from .tile_map_service.change_detection.tutorial import ChangeDetectionTutorial
89
from .tile_map_service.classification.project import ClassificationProject
@@ -22,4 +23,5 @@
2223
"FootprintTutorial",
2324
"DigitizationProject",
2425
"StreetProject",
26+
"StreetTutorial",
2527
]
Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,84 @@
1+
from dataclasses import asdict, dataclass
2+
3+
from mapswipe_workers.definitions import logger
4+
from mapswipe_workers.firebase.firebase import Firebase
5+
from mapswipe_workers.project_types.street.project import StreetGroup, StreetTask
16
from mapswipe_workers.project_types.tutorial import BaseTutorial
27

38

9+
@dataclass
10+
class StreetTutorialTask(StreetTask):
11+
projectId: int
12+
taskId: str
13+
groupId: int
14+
referenceAnswer: int
15+
screen: int
16+
17+
418
class StreetTutorial(BaseTutorial):
5-
"""The subclass for an TMS Grid based Tutorial."""
19+
"""The subclass for an arbitrary geometry based Tutorial."""
620

7-
def save_tutorial(self):
8-
raise NotImplementedError("Currently Street has no Tutorial")
21+
def __init__(self, tutorial_draft):
22+
# this will create the basis attributes
23+
super().__init__(tutorial_draft)
24+
25+
# self.projectId = tutorial_draft["projectId"]
26+
self.projectType = tutorial_draft["projectType"]
27+
self.tutorial_tasks = tutorial_draft["tasks"]
28+
self.groups = dict()
29+
self.tasks = dict()
930

1031
def create_tutorial_groups(self):
11-
raise NotImplementedError("Currently Street has no Tutorial")
32+
"""Create group for the tutorial based on provided examples in geojson file."""
33+
# load examples/tasks from file
34+
35+
group = StreetGroup(
36+
groupId=101,
37+
projectId=self.projectId,
38+
numberOfTasks=len(self.tutorial_tasks),
39+
progress=0,
40+
finishedCount=0,
41+
requiredCount=0,
42+
)
43+
self.groups[101] = group
44+
45+
# Add number of tasks for the group here. This needs to be set according to
46+
# the number of features/examples in the geojson file
47+
48+
logger.info(
49+
f"{self.projectId}"
50+
f" - create_tutorial_groups - "
51+
f"created groups dictionary"
52+
)
1253

1354
def create_tutorial_tasks(self):
14-
raise NotImplementedError("Currently Street has no Tutorial")
55+
"""Create the tasks dict based on provided examples in geojson file."""
56+
task_list = []
57+
for i, task in enumerate(self.tutorial_tasks):
58+
task = StreetTutorialTask(
59+
projectId=self.projectId,
60+
groupId=101,
61+
taskId=f"{task['taskImageId']}",
62+
geometry="",
63+
referenceAnswer=task["referenceAnswer"],
64+
screen=i,
65+
)
66+
task_list.append(asdict(task))
67+
if task_list:
68+
self.tasks[101] = task_list
69+
else:
70+
logger.info(f"group in project {self.projectId} is not valid.")
71+
72+
logger.info(
73+
f"{self.projectId}"
74+
f" - create_tutorial_tasks - "
75+
f"created tasks dictionary"
76+
)
77+
78+
def save_tutorial(self):
79+
firebase = Firebase()
80+
firebase.save_tutorial_to_firebase(
81+
self, self.groups, self.tasks, useCompression=True
82+
)
83+
logger.info(self.tutorialDraftId)
84+
firebase.drop_tutorial_draft(self.tutorialDraftId)

mapswipe_workers/tests/fixtures/projectDrafts/street.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,5 @@
4646
"requestingOrganisation": "test",
4747
"verificationNumber": 3,
4848
"groupSize": 25,
49-
"startTimestamp": "2019-07-01T00:00:00.000Z",
5049
"samplingThreshold": 0.1
5150
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
{
2+
"createdBy": "LtCUyou6CnSSc1H0Q0nDrN97x892",
3+
"tutorialDraftId": "waste_mapping_dar_es_salaam",
4+
"taskImageIds": [
5+
888464808378923,
6+
1552821322020271,
7+
2969692853315413,
8+
1036040467918366,
9+
837497816845037
10+
],
11+
"answers": [
12+
1,
13+
2,
14+
1,
15+
2,
16+
3
17+
],
18+
"customOptions": [
19+
{
20+
"description": "the shape does outline a building in the image",
21+
"icon": "hand-right-outline",
22+
"iconColor": "#00796B",
23+
"subOptions": [
24+
{
25+
"description": "doppelt",
26+
"value": 2
27+
},
28+
{
29+
"description": "dreifach",
30+
"value": 3
31+
}
32+
],
33+
"title": "Jetzt rede ich",
34+
"value": 1
35+
},
36+
{
37+
"description": "the shape doesn't match a building in the image",
38+
"icon": "close-outline",
39+
"iconColor": "#D32F2F",
40+
"title": "No",
41+
"value": 0
42+
}
43+
],
44+
"informationPages": [
45+
{
46+
"blocks": [
47+
{
48+
"blockNumber": 1,
49+
"blockType": "text",
50+
"textDescription": "asdf"
51+
},
52+
{
53+
"blockNumber": 2,
54+
"blockType": "image",
55+
"image": "https://firebasestorage.googleapis.com/v0/b/dev-mapswipe.appspot.com/o/tutorialImages%2F1705402528654-block-image-2-base-query-form.png?alt=media&token=54325ab8-c5e7-45a3-be41-1926a5984a05"
56+
}
57+
],
58+
"pageNumber": 1,
59+
"title": "asdf"
60+
}
61+
],
62+
"lookFor": "waste",
63+
"name": "Waste Mapping Dar es Salaam",
64+
"projectType": 7,
65+
"screens": [
66+
null,
67+
{
68+
"hint": {
69+
"description": "Swipe to learn some more.",
70+
"icon": "swipe-left",
71+
"title": "We've marked the correct square green."
72+
},
73+
"instructions": {
74+
"description": "Tap once to mark the squares with buildings green.",
75+
"icon": "tap-1",
76+
"title": "There are some buildings in this image"
77+
},
78+
"success": {
79+
"description": "Swipe to the next screen to look for more.",
80+
"icon": "check",
81+
"title": "You found your first areas with buildings!"
82+
}
83+
},
84+
{
85+
"hint": {
86+
"description": "Swipe to learn some more.",
87+
"icon": "swipe-left",
88+
"title": "We've marked the correct square green."
89+
},
90+
"instructions": {
91+
"description": "Tap once to mark the squares with buildings green.",
92+
"icon": "tap-1",
93+
"title": "There are some buildings in this image"
94+
},
95+
"success": {
96+
"description": "Swipe to the next screen to look for more.",
97+
"icon": "check",
98+
"title": "You found your first"
99+
}
100+
},
101+
{
102+
"hint": {
103+
"description": "Swipe to learn some more.",
104+
"icon": "swipe-left",
105+
"title": "We've marked the correct square green."
106+
},
107+
"instructions": {
108+
"description": "Tap once to mark the squares with buildings green.",
109+
"icon": "tap-1",
110+
"title": "There are some buildings in this image"
111+
},
112+
"success": {
113+
"description": "Swipe to the next screen to look for more.",
114+
"icon": "check",
115+
"title": "You found your first areas with buildings!"
116+
}
117+
},
118+
{
119+
"hint": {
120+
"description": "Swipe to learn some more.",
121+
"icon": "swipe-left",
122+
"title": "We've marked the correct square green."
123+
},
124+
"instructions": {
125+
"description": "Tap once to mark the squares with buildings green.",
126+
"icon": "tap-1",
127+
"title": "There are some buildings in this image"
128+
},
129+
"success": {
130+
"description": "Swipe to the next screen to look for more.",
131+
"icon": "check",
132+
"title": "You found your first areas with buildings!"
133+
}
134+
},
135+
{
136+
"hint": {
137+
"description": "Swipe to learn some more.",
138+
"icon": "swipe-left",
139+
"title": "We've marked the correct square green."
140+
},
141+
"instructions": {
142+
"description": "Tap once to mark the squares with buildings green.",
143+
"icon": "tap-1",
144+
"title": "There are some buildings in this image"
145+
},
146+
"success": {
147+
"description": "Swipe to the next screen to look for more.",
148+
"icon": "check",
149+
"title": "You found your first areas with buildings!"
150+
}
151+
},
152+
{
153+
"hint": {
154+
"description": "Swipe to learn some more.",
155+
"icon": "swipe-left",
156+
"title": "We've marked the correct square green."
157+
},
158+
"instructions": {
159+
"description": "Tap once to mark the squares with buildings green.",
160+
"icon": "tap-1",
161+
"title": "There are some buildings in this image"
162+
},
163+
"success": {
164+
"description": "Swipe to the next screen to look for more.",
165+
"icon": "check",
166+
"title": "You found your first areas with buildings!"
167+
}
168+
}
169+
]
170+
}

mapswipe_workers/tests/integration/test_create_street_project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def test_create_street_project(self):
5656
result = ref.get(shallow=True)
5757
self.assertIsNotNone(result)
5858

59+
breakpoint()
60+
5961

6062
if __name__ == "__main__":
6163
unittest.main()

mapswipe_workers/tests/integration/test_create_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
class TestCreateTileClassificationProject(unittest.TestCase):
1111
def setUp(self):
1212
self.tutorial_id = set_up.create_test_tutorial_draft(
13-
"tile_classification",
14-
"tile_classification",
13+
"street",
14+
"street",
1515
"test_tile_classification_tutorial",
1616
)
1717

mapswipe_workers/tests/unittests/test_tutorial.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import os
22
import unittest
33

4-
from mapswipe_workers.project_types import ClassificationTutorial
4+
from mapswipe_workers.project_types import StreetTutorial
55
from tests.fixtures import FIXTURE_DIR, get_fixture
66

77

88
class TestTutorial(unittest.TestCase):
99
def test_init_tile_classification_project(self):
1010
tutorial_draft = get_fixture(
11-
os.path.join(FIXTURE_DIR, "tutorialDrafts", "tile_classification.json")
11+
os.path.join(FIXTURE_DIR, "tutorialDrafts", "street.json")
1212
)
13-
self.assertIsNotNone(ClassificationTutorial(tutorial_draft=tutorial_draft))
13+
self.assertIsNotNone(StreetTutorial(tutorial_draft=tutorial_draft))
1414

1515
def test_create_tile_classification_tasks(self):
1616
tutorial_draft = get_fixture(
17-
os.path.join(FIXTURE_DIR, "tutorialDrafts", "tile_classification.json")
17+
os.path.join(FIXTURE_DIR, "tutorialDrafts", "street.json")
1818
)
19-
tutorial = ClassificationTutorial(tutorial_draft=tutorial_draft)
19+
tutorial = StreetTutorial(tutorial_draft=tutorial_draft)
2020
tutorial.create_tutorial_groups()
2121
tutorial.create_tutorial_tasks()
2222
self.assertTrue(tutorial.groups)
2323
self.assertTrue(tutorial.tasks)
24+
breakpoint()
2425

2526

2627
if __name__ == "__main__":

0 commit comments

Comments
 (0)