Skip to content

Commit 542f57a

Browse files
committed
Add urlB to dataclass to pass data to firebase
NOTE: dataclasses.asdict is used to convert dataclass to dict to json for firebase
1 parent eea3334 commit 542f57a

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

mapswipe_workers/mapswipe_workers/project_types/tile_map_service/change_detection/tutorial.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
from dataclasses import asdict, dataclass
2+
13
from mapswipe_workers.definitions import logger
24
from mapswipe_workers.project_types.tile_map_service.tutorial import (
35
TileMapServiceBaseTutorial,
6+
TileMapServiceBaseTutorialTask,
47
)
58
from mapswipe_workers.project_types.tile_server import BaseTileServer
69
from mapswipe_workers.utils import tile_functions
710

811

12+
@dataclass
13+
class ChangeDetectionTutorialTask(TileMapServiceBaseTutorialTask):
14+
urlB: str
15+
16+
917
class ChangeDetectionTutorial(TileMapServiceBaseTutorial):
1018
"""The subclass for an TMS Grid based Tutorial."""
1119

@@ -36,11 +44,16 @@ def create_tutorial_tasks(self):
3644

3745
super().create_tutorial_tasks()
3846

47+
modified_tasks = []
3948
for task in self.tasks[101]:
4049
_, tile_x, tile_y = task.taskId_real.split("-")
41-
task.urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
50+
urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
4251
int(tile_x), int(tile_y), self.zoomLevel, self.tileServerB
4352
)
53+
modified_tasks.append(
54+
ChangeDetectionTutorialTask(**asdict(task), urlB=urlB)
55+
)
56+
self.tasks[101] = modified_tasks
4457

4558
logger.info(
4659
f"{self.projectId}"

mapswipe_workers/mapswipe_workers/project_types/tile_map_service/completeness/tutorial.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
from dataclasses import asdict, dataclass
2+
13
from mapswipe_workers.definitions import logger
24
from mapswipe_workers.project_types.tile_map_service.tutorial import (
35
TileMapServiceBaseTutorial,
6+
TileMapServiceBaseTutorialTask,
47
)
58
from mapswipe_workers.project_types.tile_server import BaseTileServer
69
from mapswipe_workers.utils import tile_functions
710

811

12+
@dataclass
13+
class CompletenessTutorialTask(TileMapServiceBaseTutorialTask):
14+
urlB: str
15+
16+
917
class CompletenessTutorial(TileMapServiceBaseTutorial):
1018
"""The subclass for an TMS Grid based Tutorial."""
1119

@@ -36,11 +44,14 @@ def create_tutorial_tasks(self):
3644

3745
super().create_tutorial_tasks()
3846

47+
modified_tasks = []
3948
for task in self.tasks[101]:
4049
_, tile_x, tile_y = task.taskId_real.split("-")
41-
task.urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
50+
urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
4251
int(tile_x), int(tile_y), self.zoomLevel, self.tileServerB
4352
)
53+
modified_tasks.append(CompletenessTutorialTask(**asdict(task), urlB=urlB))
54+
self.tasks[101] = modified_tasks
4455

4556
logger.info(
4657
f"{self.projectId}"

mapswipe_workers/mapswipe_workers/project_types/tile_map_service/tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
from typing import Dict, List
2+
from typing import Dict, List, Union
33

44
from mapswipe_workers.definitions import logger
55
from mapswipe_workers.firebase.firebase import Firebase
@@ -25,8 +25,8 @@ class TileMapServiceBaseTutorial(BaseTutorial):
2525
def __init__(self, tutorial_draft):
2626
super().__init__(tutorial_draft)
2727

28-
self.groups: Dict[str, TileMapServiceBaseGroup] = {}
29-
self.tasks: Dict[str, List[TileMapServiceBaseTutorialTask]] = (
28+
self.groups: Dict[Union[str, int], TileMapServiceBaseGroup] = {}
29+
self.tasks: Dict[Union[str, int], List[TileMapServiceBaseTutorialTask]] = (
3030
{}
3131
) # dict keys are group ids
3232

0 commit comments

Comments
 (0)