Skip to content

Commit b0cfb56

Browse files
committed
change tile_y in tutorial for build area #240
1 parent 95ffc59 commit b0cfb56

File tree

1 file changed

+70
-63
lines changed

1 file changed

+70
-63
lines changed

mapswipe_workers/mapswipe_workers/project_types/build_area/build_area_tutorial.py

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,112 +11,117 @@ 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
6772
groups_dict[group_id] = {
6873
"xMax": "115",
6974
"xMin": "100",
70-
"yMax": "202",
71-
"yMin": "200",
75+
"yMax": "131074",
76+
"yMin": "131072",
7277
"requiredCount": 5,
7378
"finishedCount": 0,
7479
"groupId": group_id,
7580
"projectId": tutorial_id,
7681
"numberOfTasks": 36,
77-
"progress": 0
82+
"progress": 0,
7883
}
7984

8085
tasks_dict[group_id] = {}
8186
# select 6 tasks for each category and add to group
8287
counter = -1
8388
task_x = 100
84-
task_y = 200
89+
task_y = 131072
8590
for category in categories:
8691
# print(category)
8792
keys = list(grouped_tasks[category].keys())
8893
tasks = grouped_tasks[category][keys[i]]
8994

90-
x_min = min(tasks['task_x_list'])
91-
y_min = min(tasks['task_y_list'])
95+
x_min = min(tasks["task_x_list"])
96+
y_min = min(tasks["task_y_list"])
9297

9398
# replace taskX and TaskY
9499
# TaskY between 0 and 2
95100
# TaskX between 0 and 11
96-
for j in range(0, len(tasks['task_id_list'])):
101+
for j in range(0, len(tasks["task_id_list"])):
97102
counter += 1
98103
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]
104+
"taskId_real": tasks["task_id_list"][j],
105+
"groupId": group_id,
106+
"projectId": tutorial_id,
107+
"referenceAnswer": tasks["reference_answer_list"][j],
108+
"category": tasks["category"],
109+
"url": tasks["url_list"][j],
105110
}
106111

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)
112+
if tasks["task_x_list"][j] == x_min:
113+
task["taskX"] = str(task_x)
114+
elif tasks["task_x_list"][j] == (x_min + 1):
115+
task["taskX"] = str(task_x + 1)
111116

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)
117+
if tasks["task_y_list"][j] == y_min:
118+
task["taskY"] = str(task_y)
119+
elif tasks["task_y_list"][j] == (y_min + 1):
120+
task["taskY"] = str(task_y + 1)
121+
elif tasks["task_y_list"][j] == (y_min + 2):
122+
task["taskY"] = str(task_y + 2)
118123

119-
task['taskId'] = '18-{}-{}'.format(task['taskX'], task['taskY'])
124+
task["taskId"] = "18-{}-{}".format(task["taskX"], task["taskY"])
120125
tasks_dict[group_id][counter] = task
121126

122127
task_x += 2
@@ -126,13 +131,15 @@ def generate_tutorial_data(tutorial):
126131

127132
def upload_tutorial_to_firebase(tutorial, groups_dict, tasks_dict):
128133
# upload groups and tasks to firebase
129-
tutorial_id = tutorial['projectId']
134+
tutorial_id = tutorial["projectId"]
130135

131136
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}')
137+
ref = fb_db.reference("")
138+
ref.update(
139+
{
140+
"v2/projects/{}".format(tutorial_id): tutorial,
141+
"v2/groups/{}".format(tutorial_id): groups_dict,
142+
"v2/tasks/{}".format(tutorial_id): tasks_dict,
143+
}
144+
)
145+
logger.info(f"uploaded tutorial data to firebase for {tutorial_id}")

0 commit comments

Comments
 (0)