Skip to content

Commit dd17040

Browse files
authored
do not upload tasks for projects of type build_area (#467)
* do not upload tasks for projects of type build_area, change detection and completeness
1 parent 6b5b71c commit dd17040

File tree

4 files changed

+104
-26
lines changed

4 files changed

+104
-26
lines changed

mapswipe_workers/mapswipe_workers/project_types/base/project.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,14 @@ def save_to_firebase(self, project, groups, groupsOfTasks):
213213
task_upload_dict = {}
214214

215215
logger.info(f"there are {len(groupsOfTasks)} groups for this project")
216-
c = 0
217-
for group_id in groupsOfTasks.keys():
218-
tasks_list = groupsOfTasks[group_id]
219-
c += 1
220-
if self.projectType in [ProjectType.FOOTPRINT.value]:
216+
group_counter = 0
217+
218+
if self.projectType in [ProjectType.FOOTPRINT.value]:
219+
# The building footprint project type is the only one
220+
# that uses tasks in Firebase.
221+
for group_id in groupsOfTasks.keys():
222+
tasks_list = groupsOfTasks[group_id]
223+
group_counter += 1
221224
# for tasks of a building footprint project
222225
# we use compression to reduce storage size in firebase
223226
# since the tasks hold geometries their storage size
@@ -226,21 +229,26 @@ def save_to_firebase(self, project, groups, groupsOfTasks):
226229
task_upload_dict[
227230
f"v2/tasks/{self.projectId}/{group_id}"
228231
] = compressed_tasks
229-
else:
230-
# for all other projects (build_area, completenesss, change detection)
231-
# we just upload the tasks without compression
232-
task_upload_dict[f"v2/tasks/{self.projectId}/{group_id}"] = tasks_list
233-
234-
# we upload tasks in batches of maximum 150 groups
235-
# this is to avoid the maximum write size limit in firebase
236-
if len(task_upload_dict) % 150 == 0 or c == len(groupsOfTasks):
237-
ref.update(task_upload_dict)
238-
logger.info(
239-
f"{self.projectId} -"
240-
f" uploaded 150 groups with tasks to firebase realtime database"
241-
)
242-
task_upload_dict = {}
243232

233+
# we upload tasks in batches of maximum 150 groups
234+
# this is to avoid the maximum write size limit in firebase
235+
if len(task_upload_dict) % 150 == 0 or group_counter == len(
236+
groupsOfTasks
237+
):
238+
ref.update(task_upload_dict)
239+
logger.info(
240+
f"{self.projectId} -"
241+
f" uploaded 150 groups with tasks to firebase realtime database"
242+
)
243+
task_upload_dict = {}
244+
else:
245+
# For all other projects (build_area, completeness, change detection)
246+
# tasks are not needed in Firebase.
247+
# The task urls are generated in the app based on the tile server
248+
# information which is set in the project attributes in Firebase
249+
pass
250+
251+
# delete project draft in Firebase once all things are in Firebase
244252
ref = fb_db.reference(f"v2/projectDrafts/{self.projectId}")
245253
ref.set({})
246254

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"createdBy": "Sample Admin",
3+
"inputGeometries": "https://firebasestorage.googleapis.com/v0/b/dev-mapswipe.appspot.com/o/buildings_heidelberg.geojson?alt=media&token=1631f7d4-5fb2-4e1b-a133-2e14582d116c",
4+
"image": "http://www.fragosus.com/test/Javita.jpg",
5+
"lookFor": "Buildings",
6+
"name": "Footprint Sample Project",
7+
"projectDetails": "This is a template for a building by building project. We use Bing as the tile server.",
8+
"verificationNumber": 3,
9+
"groupSize": 35,
10+
"projectType": 2,
11+
"tileServer": {
12+
"name": "bing",
13+
"url": "",
14+
"apiKey": "",
15+
"credits": "© 2019 Microsoft Corporation, Earthstar Geographics SIO"
16+
}
17+
}

mapswipe_workers/tests/integration/test_create_project.py renamed to mapswipe_workers/tests/integration/test_create_build_area_project.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,29 @@ def setUp(self):
1818
def tearDown(self):
1919
tear_down.delete_test_data(self.project_id)
2020

21-
def test_create_project(self):
21+
def test_create_build_area_project(self):
2222
runner = CliRunner()
2323
runner.invoke(mapswipe_workers.run_create_projects)
2424

2525
pg_db = auth.postgresDB()
26-
query = "SELECT project_id FROM projects WHERE project_id = '{0}'".format(
27-
self.project_id
28-
)
29-
result = pg_db.retr_query(query)[0][0]
26+
query = "SELECT project_id FROM projects WHERE project_id = %s"
27+
result = pg_db.retr_query(query, [self.project_id])[0][0]
3028
self.assertEqual(result, self.project_id)
3129

3230
fb_db = auth.firebaseDB()
33-
ref = fb_db.reference("/v2/projects/{0}".format(self.project_id))
34-
result = ref.get()
31+
ref = fb_db.reference(f"/v2/projects/{self.project_id}")
32+
result = ref.get(shallow=True)
33+
self.assertIsNotNone(result)
34+
35+
ref = fb_db.reference(f"/v2/groups/{self.project_id}")
36+
result = ref.get(shallow=True)
3537
self.assertIsNotNone(result)
3638

39+
# Build area project do not have tasks in Firebase
40+
ref = fb_db.reference(f"/v2/tasks/{self.project_id}")
41+
result = ref.get(shallow=True)
42+
self.assertIsNone(result)
43+
3744

3845
if __name__ == "__main__":
3946
unittest.main()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import unittest
2+
3+
import set_up
4+
import tear_down
5+
from click.testing import CliRunner
6+
7+
from mapswipe_workers import auth, mapswipe_workers
8+
from mapswipe_workers.utils.create_directories import create_directories
9+
10+
11+
class TestCreateProject(unittest.TestCase):
12+
def setUp(self):
13+
self.project_id = set_up.create_test_project_draft(
14+
"footprint", "footprint"
15+
)
16+
create_directories()
17+
18+
def tearDown(self):
19+
tear_down.delete_test_data(self.project_id)
20+
21+
def test_create_footprint_project(self):
22+
runner = CliRunner()
23+
runner.invoke(mapswipe_workers.run_create_projects)
24+
25+
pg_db = auth.postgresDB()
26+
query = "SELECT project_id FROM projects WHERE project_id = %s"
27+
result = pg_db.retr_query(query, [self.project_id])[0][0]
28+
self.assertEqual(result, self.project_id)
29+
30+
fb_db = auth.firebaseDB()
31+
ref = fb_db.reference(f"/v2/projects/{self.project_id}")
32+
result = ref.get(shallow=True)
33+
self.assertIsNotNone(result)
34+
35+
ref = fb_db.reference(f"/v2/groups/{self.project_id}")
36+
result = ref.get(shallow=True)
37+
self.assertIsNotNone(result)
38+
39+
# Footprint projects have tasks in Firebase
40+
ref = fb_db.reference(f"/v2/tasks/{self.project_id}")
41+
result = ref.get(shallow=True)
42+
self.assertIsNotNone(result)
43+
44+
45+
if __name__ == "__main__":
46+
unittest.main()

0 commit comments

Comments
 (0)