1- import csv
21import json
3-
42from mapswipe_workers .definitions import logger
53from mapswipe_workers import auth
64from mapswipe_workers .project_types .change_detection import tile_functions as t
@@ -12,80 +10,79 @@ def create_tutorial(tutorial):
1210
1311
1412def 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 } " )
1715
1816 groups_dict = {}
1917 tasks_dict = {}
2018
21- with open (tutorial [' examplesFile' ]) as json_file :
19+ with open (tutorial [" examplesFile" ]) as json_file :
2220 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' ]:
2721
28- print (feature )
22+ for feature in tutorial_tasks ["features" ]:
23+ category = feature ["properties" ]["category" ]
24+ group_id = 100 + feature ["properties" ]["id" ]
2925
30- category = feature ['properties' ]['category' ]
31- group_id = 100 + feature ['properties' ]['id' ]
26+ if group_id not in groups_dict .keys ():
3227
33- if not group_id in groups_dict . keys ():
28+ # yMin 32768 represents a tile located at the equator at zoom level 16
3429 groups_dict [group_id ] = {
35- "xMax" : "104 " ,
30+ "xMax" : "105 " ,
3631 "xMin" : "100" ,
37- "yMax" : "200 " ,
38- "yMin" : "200 " ,
32+ "yMax" : "32768 " ,
33+ "yMin" : "32768 " ,
3934 "requiredCount" : 5 ,
4035 "finishedCount" : 0 ,
4136 "groupId" : group_id ,
4237 "projectId" : tutorial_id ,
4338 "numberOfTasks" : 4 ,
44- "progress" : 0
39+ "progress" : 0 ,
4540 }
4641
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 )
5247
5348 urlA = t .tile_coords_zoom_and_tileserver_to_URL (
5449 task_x ,
5550 task_y ,
5651 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" ],
6055 None ,
6156 )
6257 urlB = t .tile_coords_zoom_and_tileserver_to_URL (
6358 task_x ,
6459 task_y ,
6560 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" ],
6964 None ,
7065 )
7166
72- if not group_id in tasks_dict .keys ():
67+ if group_id not in tasks_dict .keys ():
7368 tasks_dict [group_id ] = {}
74- task_id = ' {}-{}-{}' .format (16 , 100 , 200 )
69+ task_id = " {}-{}-{}" .format (16 , 100 , 32768 )
7570 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+ )
7774
7875 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 ,
8986 }
9087
9188 tasks_dict [group_id ][len (tasks_dict [group_id ].keys ())] = task
@@ -95,13 +92,15 @@ def generate_tutorial_data(tutorial):
9592
9693def upload_tutorial_to_firebase (tutorial , groups_dict , tasks_dict ):
9794 # upload groups and tasks to firebase
98- tutorial_id = tutorial [' projectId' ]
95+ tutorial_id = tutorial [" projectId" ]
9996
10097 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