1
- import csv
2
1
import json
3
-
4
2
from mapswipe_workers .definitions import logger
5
3
from mapswipe_workers import auth
6
4
from mapswipe_workers .project_types .change_detection import tile_functions as t
@@ -12,80 +10,79 @@ def create_tutorial(tutorial):
12
10
13
11
14
12
def generate_tutorial_data (tutorial ):
15
- tutorial_id = tutorial [' projectId' ]
16
- logger .info (f' create tutorial for tutorial id: { tutorial_id } ' )
13
+ tutorial_id = tutorial [" projectId" ]
14
+ logger .info (f" create tutorial for tutorial id: { tutorial_id } " )
17
15
18
16
groups_dict = {}
19
17
tasks_dict = {}
20
18
21
- with open (tutorial [' examplesFile' ]) as json_file :
19
+ with open (tutorial [" examplesFile" ]) as json_file :
22
20
tutorial_tasks = json .load (json_file )
23
- print (len (tutorial_tasks ['features' ]))
24
- #print(tutorial_tasks['features'])
25
-
26
- for feature in tutorial_tasks ['features' ]:
27
21
28
- print (feature )
22
+ for feature in tutorial_tasks ["features" ]:
23
+ category = feature ["properties" ]["category" ]
24
+ group_id = 100 + feature ["properties" ]["id" ]
29
25
30
- category = feature ['properties' ]['category' ]
31
- group_id = 100 + feature ['properties' ]['id' ]
26
+ if group_id not in groups_dict .keys ():
32
27
33
- if not group_id in groups_dict . keys ():
28
+ # yMin 32768 represents a tile located at the equator at zoom level 16
34
29
groups_dict [group_id ] = {
35
- "xMax" : "104 " ,
30
+ "xMax" : "105 " ,
36
31
"xMin" : "100" ,
37
- "yMax" : "200 " ,
38
- "yMin" : "200 " ,
32
+ "yMax" : "32768 " ,
33
+ "yMin" : "32768 " ,
39
34
"requiredCount" : 5 ,
40
35
"finishedCount" : 0 ,
41
36
"groupId" : group_id ,
42
37
"projectId" : tutorial_id ,
43
38
"numberOfTasks" : 4 ,
44
- "progress" : 0
39
+ "progress" : 0 ,
45
40
}
46
41
47
- reference = feature [' properties' ][ ' reference' ]
48
- zoom = feature [' properties' ][ ' TileZ' ]
49
- task_x = feature [' properties' ][ ' TileX' ]
50
- task_y = feature [' properties' ][ ' TileY' ]
51
- task_id_real = ' {}-{}-{}' .format (zoom , task_x , task_y )
42
+ reference = feature [" properties" ][ " reference" ]
43
+ zoom = feature [" properties" ][ " TileZ" ]
44
+ task_x = feature [" properties" ][ " TileX" ]
45
+ task_y = feature [" properties" ][ " TileY" ]
46
+ task_id_real = " {}-{}-{}" .format (zoom , task_x , task_y )
52
47
53
48
urlA = t .tile_coords_zoom_and_tileserver_to_URL (
54
49
task_x ,
55
50
task_y ,
56
51
zoom ,
57
- tutorial [' tileServerA' ][ ' name' ],
58
- tutorial [' tileServerA' ][ ' apiKey' ],
59
- tutorial [' tileServerA' ][ ' url' ],
52
+ tutorial [" tileServerA" ][ " name" ],
53
+ tutorial [" tileServerA" ][ " apiKey" ],
54
+ tutorial [" tileServerA" ][ " url" ],
60
55
None ,
61
56
)
62
57
urlB = t .tile_coords_zoom_and_tileserver_to_URL (
63
58
task_x ,
64
59
task_y ,
65
60
zoom ,
66
- tutorial [' tileServerB' ][ ' name' ],
67
- tutorial [' tileServerB' ][ ' apiKey' ],
68
- tutorial [' tileServerB' ][ ' url' ],
61
+ tutorial [" tileServerB" ][ " name" ],
62
+ tutorial [" tileServerB" ][ " apiKey" ],
63
+ tutorial [" tileServerB" ][ " url" ],
69
64
None ,
70
65
)
71
66
72
- if not group_id in tasks_dict .keys ():
67
+ if group_id not in tasks_dict .keys ():
73
68
tasks_dict [group_id ] = {}
74
- task_id = ' {}-{}-{}' .format (16 , 100 , 200 )
69
+ task_id = " {}-{}-{}" .format (16 , 100 , 32768 )
75
70
else :
76
- task_id = '{}-{}-{}' .format (16 , 100 + len (tasks_dict [group_id ].keys ()), 200 )
71
+ task_id = "{}-{}-{}" .format (
72
+ 16 , 100 + len (tasks_dict [group_id ].keys ()), 32768
73
+ )
77
74
78
75
task = {
79
- ' taskId_real' : task_id_real ,
80
- ' taskId' : task_id ,
81
- ' taskX' : 100 + len (tasks_dict [group_id ].keys ()),
82
- ' taskY' : 200 ,
83
- ' groupId' : group_id ,
84
- ' projectId' : tutorial_id ,
85
- ' referenceAnswer' : reference ,
86
- ' category' : category ,
87
- ' urlA' : urlA ,
88
- ' urlB' : urlB ,
76
+ " taskId_real" : task_id_real ,
77
+ " taskId" : task_id ,
78
+ " taskX" : 100 + len (tasks_dict [group_id ].keys ()),
79
+ " taskY" : 32768 ,
80
+ " groupId" : group_id ,
81
+ " projectId" : tutorial_id ,
82
+ " referenceAnswer" : reference ,
83
+ " category" : category ,
84
+ " urlA" : urlA ,
85
+ " urlB" : urlB ,
89
86
}
90
87
91
88
tasks_dict [group_id ][len (tasks_dict [group_id ].keys ())] = task
@@ -95,13 +92,15 @@ def generate_tutorial_data(tutorial):
95
92
96
93
def upload_tutorial_to_firebase (tutorial , groups_dict , tasks_dict ):
97
94
# upload groups and tasks to firebase
98
- tutorial_id = tutorial [' projectId' ]
95
+ tutorial_id = tutorial [" projectId" ]
99
96
100
97
fb_db = auth .firebaseDB ()
101
- ref = fb_db .reference ('' )
102
- ref .update ({
103
- 'v2/projects/{}' .format (tutorial_id ): tutorial ,
104
- 'v2/groups/{}' .format (tutorial_id ): groups_dict ,
105
- 'v2/tasks/{}' .format (tutorial_id ): tasks_dict ,
106
- })
107
- logger .info (f'uploaded tutorial data to firebase for { tutorial_id } ' )
98
+ ref = fb_db .reference ("" )
99
+ ref .update (
100
+ {
101
+ "v2/projects/{}" .format (tutorial_id ): tutorial ,
102
+ "v2/groups/{}" .format (tutorial_id ): groups_dict ,
103
+ "v2/tasks/{}" .format (tutorial_id ): tasks_dict ,
104
+ }
105
+ )
106
+ logger .info (f"uploaded tutorial data to firebase for { tutorial_id } " )
0 commit comments