Skip to content

Commit 2787665

Browse files
authored
Merge pull request #241 from mapswipe/fix-tutorial-scale-bar
Fix tutorial scale bar
2 parents 489a3bb + 0a53717 commit 2787665

File tree

2 files changed

+120
-112
lines changed

2 files changed

+120
-112
lines changed

mapswipe_workers/mapswipe_workers/project_types/build_area/build_area_tutorial.py

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,112 +11,119 @@ def create_tutorial(tutorial):
1111

1212

1313
def generate_tutorial_data(tutorial):
14-
tutorial_id = tutorial['projectId']
15-
categories = tutorial['categories'].keys()
16-
logger.info(f'create tutorial for tutorial id: {tutorial_id}')
14+
tutorial_id = tutorial["projectId"]
15+
categories = tutorial["categories"].keys()
16+
logger.info(f"create tutorial for tutorial id: {tutorial_id}")
1717

1818
grouped_tasks = {
19-
'building_easy_1': {},
20-
'building_easy_2': {},
21-
'maybe_1': {},
22-
'no_building_easy_1': {},
23-
'no_building_easy_2': {},
24-
'bad_clouds_1': {},
25-
'bad_no_imagery_1': {},
26-
'bad_no_imagery_2': {},
19+
"building_easy_1": {},
20+
"building_easy_2": {},
21+
"maybe_1": {},
22+
"no_building_easy_1": {},
23+
"no_building_easy_2": {},
24+
"bad_clouds_1": {},
25+
"bad_no_imagery_1": {},
26+
"bad_no_imagery_2": {},
2727
}
2828

2929
c = 0
30-
with open(tutorial['examplesFile']) as csvDataFile:
30+
with open(tutorial["examplesFile"]) as csvDataFile:
3131
logger.info(f'tutorial tasks are based on: {tutorial["examplesFile"]}')
3232
csvReader = csv.reader(csvDataFile)
3333
for row in csvReader:
3434
c += 1
3535
if c == 1:
36-
header = row
36+
pass
3737
else:
3838
category = row[2]
3939
if not row[3] in grouped_tasks[category].keys():
4040
grouped_tasks[category][row[3]] = {
41-
'task_id_list': [],
42-
'task_x_list': [],
43-
'task_y_list': [],
44-
'reference_answer_list': [],
45-
'category': category,
46-
'url_list': []
41+
"task_id_list": [],
42+
"task_x_list": [],
43+
"task_y_list": [],
44+
"reference_answer_list": [],
45+
"category": category,
46+
"url_list": [],
4747
}
4848

49-
grouped_tasks[category][row[3]]['task_id_list'].append(row[0])
50-
zoom = row[0].split('-')[0]
51-
task_x = int(row[0].split('-')[1])
52-
task_y = int(row[0].split('-')[2])
53-
grouped_tasks[category][row[3]]['task_x_list'].append(task_x)
54-
grouped_tasks[category][row[3]]['task_y_list'].append(task_y)
55-
url = t.tile_coords_zoom_and_tileserver_to_URL(task_x, task_y, zoom, tutorial['tileServer']['name'],
56-
auth.get_api_key(tutorial['tileServer']['name']), None,
57-
None)
58-
grouped_tasks[category][row[3]]['url_list'].append(url)
59-
grouped_tasks[category][row[3]]['reference_answer_list'].append(row[1])
49+
grouped_tasks[category][row[3]]["task_id_list"].append(row[0])
50+
zoom = row[0].split("-")[0]
51+
task_x = int(row[0].split("-")[1])
52+
task_y = int(row[0].split("-")[2])
53+
grouped_tasks[category][row[3]]["task_x_list"].append(task_x)
54+
grouped_tasks[category][row[3]]["task_y_list"].append(task_y)
55+
url = t.tile_coords_zoom_and_tileserver_to_URL(
56+
task_x,
57+
task_y,
58+
zoom,
59+
tutorial["tileServer"]["name"],
60+
auth.get_api_key(tutorial["tileServer"]["name"]),
61+
None,
62+
None,
63+
)
64+
grouped_tasks[category][row[3]]["url_list"].append(url)
65+
grouped_tasks[category][row[3]]["reference_answer_list"].append(row[1])
6066

6167
groups_dict = {}
6268
tasks_dict = {}
6369

6470
for i in range(0, 1):
65-
print(i)
6671
group_id = 101 + i
72+
# the yMin represents a tile located at the equator at zoom level 18
6773
groups_dict[group_id] = {
6874
"xMax": "115",
6975
"xMin": "100",
70-
"yMax": "202",
71-
"yMin": "200",
76+
"yMax": "131074",
77+
"yMin": "131072",
7278
"requiredCount": 5,
7379
"finishedCount": 0,
7480
"groupId": group_id,
7581
"projectId": tutorial_id,
7682
"numberOfTasks": 36,
77-
"progress": 0
83+
"progress": 0,
7884
}
7985

8086
tasks_dict[group_id] = {}
8187
# select 6 tasks for each category and add to group
8288
counter = -1
8389
task_x = 100
84-
task_y = 200
90+
# the task_y represents a tile located at the equator at zoom level 18
91+
task_y = 131072
8592
for category in categories:
8693
# print(category)
8794
keys = list(grouped_tasks[category].keys())
8895
tasks = grouped_tasks[category][keys[i]]
8996

90-
x_min = min(tasks['task_x_list'])
91-
y_min = min(tasks['task_y_list'])
97+
x_min = min(tasks["task_x_list"])
98+
y_min = min(tasks["task_y_list"])
9299

93100
# replace taskX and TaskY
94101
# TaskY between 0 and 2
95102
# TaskX between 0 and 11
96-
for j in range(0, len(tasks['task_id_list'])):
103+
for j in range(0, len(tasks["task_id_list"])):
97104
counter += 1
98105
task = {
99-
'taskId_real': tasks['task_id_list'][j],
100-
'groupId': group_id,
101-
'projectId': tutorial_id,
102-
'referenceAnswer': tasks['reference_answer_list'][j],
103-
'category': tasks['category'],
104-
'url': tasks['url_list'][j]
106+
"taskId_real": tasks["task_id_list"][j],
107+
"groupId": group_id,
108+
"projectId": tutorial_id,
109+
"referenceAnswer": tasks["reference_answer_list"][j],
110+
"category": tasks["category"],
111+
"url": tasks["url_list"][j],
105112
}
106113

107-
if tasks['task_x_list'][j] == x_min:
108-
task['taskX'] = str(task_x)
109-
elif tasks['task_x_list'][j] == (x_min + 1):
110-
task['taskX'] = str(task_x + 1)
114+
if tasks["task_x_list"][j] == x_min:
115+
task["taskX"] = str(task_x)
116+
elif tasks["task_x_list"][j] == (x_min + 1):
117+
task["taskX"] = str(task_x + 1)
111118

112-
if tasks['task_y_list'][j] == y_min:
113-
task['taskY'] = str(task_y)
114-
elif tasks['task_y_list'][j] == (y_min + 1):
115-
task['taskY'] = str(task_y + 1)
116-
elif tasks['task_y_list'][j] == (y_min + 2):
117-
task['taskY'] = str(task_y + 2)
119+
if tasks["task_y_list"][j] == y_min:
120+
task["taskY"] = str(task_y)
121+
elif tasks["task_y_list"][j] == (y_min + 1):
122+
task["taskY"] = str(task_y + 1)
123+
elif tasks["task_y_list"][j] == (y_min + 2):
124+
task["taskY"] = str(task_y + 2)
118125

119-
task['taskId'] = '18-{}-{}'.format(task['taskX'], task['taskY'])
126+
task["taskId"] = "18-{}-{}".format(task["taskX"], task["taskY"])
120127
tasks_dict[group_id][counter] = task
121128

122129
task_x += 2
@@ -126,13 +133,15 @@ def generate_tutorial_data(tutorial):
126133

127134
def upload_tutorial_to_firebase(tutorial, groups_dict, tasks_dict):
128135
# upload groups and tasks to firebase
129-
tutorial_id = tutorial['projectId']
136+
tutorial_id = tutorial["projectId"]
130137

131138
fb_db = auth.firebaseDB()
132-
ref = fb_db.reference('')
133-
ref.update({
134-
'v2/projects/{}'.format(tutorial_id): tutorial,
135-
'v2/groups/{}'.format(tutorial_id): groups_dict,
136-
'v2/tasks/{}'.format(tutorial_id): tasks_dict,
137-
})
138-
logger.info(f'uploaded tutorial data to firebase for {tutorial_id}')
139+
ref = fb_db.reference("")
140+
ref.update(
141+
{
142+
"v2/projects/{}".format(tutorial_id): tutorial,
143+
"v2/groups/{}".format(tutorial_id): groups_dict,
144+
"v2/tasks/{}".format(tutorial_id): tasks_dict,
145+
}
146+
)
147+
logger.info(f"uploaded tutorial data to firebase for {tutorial_id}")
Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import csv
21
import json
3-
42
from mapswipe_workers.definitions import logger
53
from mapswipe_workers import auth
64
from mapswipe_workers.project_types.change_detection import tile_functions as t
@@ -12,80 +10,79 @@ def create_tutorial(tutorial):
1210

1311

1412
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}")
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

9693
def 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

Comments
 (0)