diff --git a/mapswipe_workers/mapswipe_workers/project_types/build_area/build_area_tutorial.py b/mapswipe_workers/mapswipe_workers/project_types/build_area/build_area_tutorial.py index 8ec2bd8fa..d3efb4001 100644 --- a/mapswipe_workers/mapswipe_workers/project_types/build_area/build_area_tutorial.py +++ b/mapswipe_workers/mapswipe_workers/project_types/build_area/build_area_tutorial.py @@ -11,112 +11,119 @@ def create_tutorial(tutorial): def generate_tutorial_data(tutorial): - tutorial_id = tutorial['projectId'] - categories = tutorial['categories'].keys() - logger.info(f'create tutorial for tutorial id: {tutorial_id}') + tutorial_id = tutorial["projectId"] + categories = tutorial["categories"].keys() + logger.info(f"create tutorial for tutorial id: {tutorial_id}") grouped_tasks = { - 'building_easy_1': {}, - 'building_easy_2': {}, - 'maybe_1': {}, - 'no_building_easy_1': {}, - 'no_building_easy_2': {}, - 'bad_clouds_1': {}, - 'bad_no_imagery_1': {}, - 'bad_no_imagery_2': {}, + "building_easy_1": {}, + "building_easy_2": {}, + "maybe_1": {}, + "no_building_easy_1": {}, + "no_building_easy_2": {}, + "bad_clouds_1": {}, + "bad_no_imagery_1": {}, + "bad_no_imagery_2": {}, } c = 0 - with open(tutorial['examplesFile']) as csvDataFile: + with open(tutorial["examplesFile"]) as csvDataFile: logger.info(f'tutorial tasks are based on: {tutorial["examplesFile"]}') csvReader = csv.reader(csvDataFile) for row in csvReader: c += 1 if c == 1: - header = row + pass else: category = row[2] if not row[3] in grouped_tasks[category].keys(): grouped_tasks[category][row[3]] = { - 'task_id_list': [], - 'task_x_list': [], - 'task_y_list': [], - 'reference_answer_list': [], - 'category': category, - 'url_list': [] + "task_id_list": [], + "task_x_list": [], + "task_y_list": [], + "reference_answer_list": [], + "category": category, + "url_list": [], } - grouped_tasks[category][row[3]]['task_id_list'].append(row[0]) - zoom = row[0].split('-')[0] - task_x = int(row[0].split('-')[1]) - task_y = int(row[0].split('-')[2]) - grouped_tasks[category][row[3]]['task_x_list'].append(task_x) - grouped_tasks[category][row[3]]['task_y_list'].append(task_y) - url = t.tile_coords_zoom_and_tileserver_to_URL(task_x, task_y, zoom, tutorial['tileServer']['name'], - auth.get_api_key(tutorial['tileServer']['name']), None, - None) - grouped_tasks[category][row[3]]['url_list'].append(url) - grouped_tasks[category][row[3]]['reference_answer_list'].append(row[1]) + grouped_tasks[category][row[3]]["task_id_list"].append(row[0]) + zoom = row[0].split("-")[0] + task_x = int(row[0].split("-")[1]) + task_y = int(row[0].split("-")[2]) + grouped_tasks[category][row[3]]["task_x_list"].append(task_x) + grouped_tasks[category][row[3]]["task_y_list"].append(task_y) + url = t.tile_coords_zoom_and_tileserver_to_URL( + task_x, + task_y, + zoom, + tutorial["tileServer"]["name"], + auth.get_api_key(tutorial["tileServer"]["name"]), + None, + None, + ) + grouped_tasks[category][row[3]]["url_list"].append(url) + grouped_tasks[category][row[3]]["reference_answer_list"].append(row[1]) groups_dict = {} tasks_dict = {} for i in range(0, 1): - print(i) group_id = 101 + i + # the yMin represents a tile located at the equator at zoom level 18 groups_dict[group_id] = { "xMax": "115", "xMin": "100", - "yMax": "202", - "yMin": "200", + "yMax": "131074", + "yMin": "131072", "requiredCount": 5, "finishedCount": 0, "groupId": group_id, "projectId": tutorial_id, "numberOfTasks": 36, - "progress": 0 + "progress": 0, } tasks_dict[group_id] = {} # select 6 tasks for each category and add to group counter = -1 task_x = 100 - task_y = 200 + # the task_y represents a tile located at the equator at zoom level 18 + task_y = 131072 for category in categories: # print(category) keys = list(grouped_tasks[category].keys()) tasks = grouped_tasks[category][keys[i]] - x_min = min(tasks['task_x_list']) - y_min = min(tasks['task_y_list']) + x_min = min(tasks["task_x_list"]) + y_min = min(tasks["task_y_list"]) # replace taskX and TaskY # TaskY between 0 and 2 # TaskX between 0 and 11 - for j in range(0, len(tasks['task_id_list'])): + for j in range(0, len(tasks["task_id_list"])): counter += 1 task = { - 'taskId_real': tasks['task_id_list'][j], - 'groupId': group_id, - 'projectId': tutorial_id, - 'referenceAnswer': tasks['reference_answer_list'][j], - 'category': tasks['category'], - 'url': tasks['url_list'][j] + "taskId_real": tasks["task_id_list"][j], + "groupId": group_id, + "projectId": tutorial_id, + "referenceAnswer": tasks["reference_answer_list"][j], + "category": tasks["category"], + "url": tasks["url_list"][j], } - if tasks['task_x_list'][j] == x_min: - task['taskX'] = str(task_x) - elif tasks['task_x_list'][j] == (x_min + 1): - task['taskX'] = str(task_x + 1) + if tasks["task_x_list"][j] == x_min: + task["taskX"] = str(task_x) + elif tasks["task_x_list"][j] == (x_min + 1): + task["taskX"] = str(task_x + 1) - if tasks['task_y_list'][j] == y_min: - task['taskY'] = str(task_y) - elif tasks['task_y_list'][j] == (y_min + 1): - task['taskY'] = str(task_y + 1) - elif tasks['task_y_list'][j] == (y_min + 2): - task['taskY'] = str(task_y + 2) + if tasks["task_y_list"][j] == y_min: + task["taskY"] = str(task_y) + elif tasks["task_y_list"][j] == (y_min + 1): + task["taskY"] = str(task_y + 1) + elif tasks["task_y_list"][j] == (y_min + 2): + task["taskY"] = str(task_y + 2) - task['taskId'] = '18-{}-{}'.format(task['taskX'], task['taskY']) + task["taskId"] = "18-{}-{}".format(task["taskX"], task["taskY"]) tasks_dict[group_id][counter] = task task_x += 2 @@ -126,13 +133,15 @@ def generate_tutorial_data(tutorial): def upload_tutorial_to_firebase(tutorial, groups_dict, tasks_dict): # upload groups and tasks to firebase - tutorial_id = tutorial['projectId'] + tutorial_id = tutorial["projectId"] fb_db = auth.firebaseDB() - ref = fb_db.reference('') - ref.update({ - 'v2/projects/{}'.format(tutorial_id): tutorial, - 'v2/groups/{}'.format(tutorial_id): groups_dict, - 'v2/tasks/{}'.format(tutorial_id): tasks_dict, - }) - logger.info(f'uploaded tutorial data to firebase for {tutorial_id}') + ref = fb_db.reference("") + ref.update( + { + "v2/projects/{}".format(tutorial_id): tutorial, + "v2/groups/{}".format(tutorial_id): groups_dict, + "v2/tasks/{}".format(tutorial_id): tasks_dict, + } + ) + logger.info(f"uploaded tutorial data to firebase for {tutorial_id}") diff --git a/mapswipe_workers/mapswipe_workers/project_types/change_detection/change_detection_tutorial.py b/mapswipe_workers/mapswipe_workers/project_types/change_detection/change_detection_tutorial.py index 69ff920cf..32943f52a 100644 --- a/mapswipe_workers/mapswipe_workers/project_types/change_detection/change_detection_tutorial.py +++ b/mapswipe_workers/mapswipe_workers/project_types/change_detection/change_detection_tutorial.py @@ -1,6 +1,4 @@ -import csv import json - from mapswipe_workers.definitions import logger from mapswipe_workers import auth from mapswipe_workers.project_types.change_detection import tile_functions as t @@ -12,80 +10,79 @@ def create_tutorial(tutorial): def generate_tutorial_data(tutorial): - tutorial_id = tutorial['projectId'] - logger.info(f'create tutorial for tutorial id: {tutorial_id}') + tutorial_id = tutorial["projectId"] + logger.info(f"create tutorial for tutorial id: {tutorial_id}") groups_dict = {} tasks_dict = {} - with open(tutorial['examplesFile']) as json_file: + with open(tutorial["examplesFile"]) as json_file: tutorial_tasks = json.load(json_file) - print(len(tutorial_tasks['features'])) - #print(tutorial_tasks['features']) - - for feature in tutorial_tasks['features']: - print(feature) + for feature in tutorial_tasks["features"]: + category = feature["properties"]["category"] + group_id = 100 + feature["properties"]["id"] - category = feature['properties']['category'] - group_id = 100 + feature['properties']['id'] + if group_id not in groups_dict.keys(): - if not group_id in groups_dict.keys(): + # yMin 32768 represents a tile located at the equator at zoom level 16 groups_dict[group_id] = { - "xMax": "104", + "xMax": "105", "xMin": "100", - "yMax": "200", - "yMin": "200", + "yMax": "32768", + "yMin": "32768", "requiredCount": 5, "finishedCount": 0, "groupId": group_id, "projectId": tutorial_id, "numberOfTasks": 4, - "progress": 0 + "progress": 0, } - reference = feature['properties']['reference'] - zoom = feature['properties']['TileZ'] - task_x = feature['properties']['TileX'] - task_y = feature['properties']['TileY'] - task_id_real = '{}-{}-{}'.format(zoom, task_x, task_y) + reference = feature["properties"]["reference"] + zoom = feature["properties"]["TileZ"] + task_x = feature["properties"]["TileX"] + task_y = feature["properties"]["TileY"] + task_id_real = "{}-{}-{}".format(zoom, task_x, task_y) urlA = t.tile_coords_zoom_and_tileserver_to_URL( task_x, task_y, zoom, - tutorial['tileServerA']['name'], - tutorial['tileServerA']['apiKey'], - tutorial['tileServerA']['url'], + tutorial["tileServerA"]["name"], + tutorial["tileServerA"]["apiKey"], + tutorial["tileServerA"]["url"], None, ) urlB = t.tile_coords_zoom_and_tileserver_to_URL( task_x, task_y, zoom, - tutorial['tileServerB']['name'], - tutorial['tileServerB']['apiKey'], - tutorial['tileServerB']['url'], + tutorial["tileServerB"]["name"], + tutorial["tileServerB"]["apiKey"], + tutorial["tileServerB"]["url"], None, ) - if not group_id in tasks_dict.keys(): + if group_id not in tasks_dict.keys(): tasks_dict[group_id] = {} - task_id = '{}-{}-{}'.format(16, 100, 200) + task_id = "{}-{}-{}".format(16, 100, 32768) else: - task_id = '{}-{}-{}'.format(16, 100 + len(tasks_dict[group_id].keys()), 200) + task_id = "{}-{}-{}".format( + 16, 100 + len(tasks_dict[group_id].keys()), 32768 + ) task = { - 'taskId_real': task_id_real, - 'taskId': task_id, - 'taskX': 100 + len(tasks_dict[group_id].keys()), - 'taskY': 200, - 'groupId': group_id, - 'projectId': tutorial_id, - 'referenceAnswer': reference, - 'category': category, - 'urlA': urlA, - 'urlB': urlB, + "taskId_real": task_id_real, + "taskId": task_id, + "taskX": 100 + len(tasks_dict[group_id].keys()), + "taskY": 32768, + "groupId": group_id, + "projectId": tutorial_id, + "referenceAnswer": reference, + "category": category, + "urlA": urlA, + "urlB": urlB, } tasks_dict[group_id][len(tasks_dict[group_id].keys())] = task @@ -95,13 +92,15 @@ def generate_tutorial_data(tutorial): def upload_tutorial_to_firebase(tutorial, groups_dict, tasks_dict): # upload groups and tasks to firebase - tutorial_id = tutorial['projectId'] + tutorial_id = tutorial["projectId"] fb_db = auth.firebaseDB() - ref = fb_db.reference('') - ref.update({ - 'v2/projects/{}'.format(tutorial_id): tutorial, - 'v2/groups/{}'.format(tutorial_id): groups_dict, - 'v2/tasks/{}'.format(tutorial_id): tasks_dict, - }) - logger.info(f'uploaded tutorial data to firebase for {tutorial_id}') + ref = fb_db.reference("") + ref.update( + { + "v2/projects/{}".format(tutorial_id): tutorial, + "v2/groups/{}".format(tutorial_id): groups_dict, + "v2/tasks/{}".format(tutorial_id): tasks_dict, + } + ) + logger.info(f"uploaded tutorial data to firebase for {tutorial_id}")