Skip to content

Commit 0503717

Browse files
committed
work on PR comments
1 parent ac95130 commit 0503717

File tree

8 files changed

+42
-32
lines changed

8 files changed

+42
-32
lines changed

mapswipe_workers/mapswipe_workers/definitions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def constructor(self):
146146
def tutorial(self):
147147
# Imports are first made once this method get called to avoid circular imports.
148148
from mapswipe_workers.project_types.arbitrary_geometry.tutorial import (
149-
Tutorial as ArbitraryGeometriesTutorial,
149+
Tutorial as ArbitraryGeometryTutorial,
150150
)
151151
from mapswipe_workers.project_types.tile_map_service_grid.tutorial import (
152152
Tutorial as tmsg_tutorial,
@@ -159,7 +159,7 @@ def tutorial(self):
159159

160160
project_type_classes = {
161161
1: tmsg_tutorial,
162-
2: ArbitraryGeometriesTutorial,
162+
2: ArbitraryGeometryTutorial,
163163
3: tmsg_tutorial,
164164
4: tmsg_tutorial,
165165
}

mapswipe_workers/mapswipe_workers/mapswipe_workers.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def run_firebase_to_postgres() -> list:
120120
help=(
121121
"Project ids for which to generate stats as a list of strings: "
122122
""" '["project_a", "project_b"]' """
123+
"(You need the quotes.)"
123124
),
124125
)
125126
def run_generate_stats(project_ids: list) -> None:
@@ -150,8 +151,9 @@ def run_generate_stats_all_projects() -> None:
150151
cls=PythonLiteralOption,
151152
default="[]",
152153
help=(
153-
"The email of the MapSwipe users as a list of strings: "
154+
"The emails of the MapSwipe users as a list of strings: "
154155
""" '["email_a", "email_b"]' """
156+
"(You need the quotes.)"
155157
),
156158
)
157159
@click.option("--team_id", "-i", help="The id of the team in Firebase.", type=str)
@@ -173,10 +175,13 @@ def run_user_management(email, emails, action, team_id) -> None:
173175
174176
Grant or remove credentials.
175177
"""
176-
try:
177-
if email:
178-
emails = [email]
179-
for email in emails:
178+
if email:
179+
email_list = [email]
180+
else:
181+
email_list = emails
182+
183+
for email in email_list:
184+
try:
180185
if action == "add-manager-rights":
181186
user_management.set_project_manager_rights(email)
182187
elif action == "remove-manager-rights":
@@ -188,9 +193,9 @@ def run_user_management(email, emails, action, team_id) -> None:
188193
user_management.add_user_to_team(email, team_id)
189194
elif action == "remove-team":
190195
user_management.remove_user_from_team(email)
191-
except Exception:
192-
logger.exception("grant user credentials failed")
193-
sentry.capture_exception()
196+
except Exception:
197+
logger.exception("grant user credentials failed")
198+
sentry.capture_exception()
194199

195200

196201
@cli.command("team-management")

mapswipe_workers/mapswipe_workers/project_types/arbitrary_geometry/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(
4040
del self.groupId
4141

4242
# create wkt geometry from geojson
43+
# this geometry will be stored in postgres
4344
poly = ogr.CreateGeometryFromJson(str(featureGeometry))
4445
wkt_geometry = poly.ExportToWkt()
4546
self.geometry = wkt_geometry

mapswipe_workers/mapswipe_workers/project_types/arbitrary_geometry/tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, tutorial_draft):
2323

2424
# save tasks as geojson
2525
self.inputGeometries = (
26-
f"{DATA_PATH}/" f"input_geometries/valid_input_{self.projectId}.geojson"
26+
f"{DATA_PATH}/input_geometries/valid_input_{self.projectId}.geojson"
2727
)
2828

2929
with open(self.inputGeometries, "w") as f:

mapswipe_workers/mapswipe_workers/project_types/base/project.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import base64
21
import csv
32
import datetime as dt
43
import json
@@ -218,18 +217,10 @@ def save_to_firebase(self, project, groups, groupsOfTasks):
218217
for group_id, tasks_list in groupsOfTasks.items():
219218
c += 1
220219
if self.projectType in [ProjectType.FOOTPRINT.value]:
221-
# we compress tasks for footprint project type using gzip
222-
json_string_tasks = (
223-
json.dumps(tasks_list).replace(" ", "").replace("\n", "")
224-
)
225-
compressed_tasks = gzip_str.gzip_str(json_string_tasks)
226-
# we need to decode back, but only when using Python 3.6
227-
# when using Python 3.7 it just works
228-
# Unfortunately the docker image uses Python 3.7
229-
encoded_tasks = base64.b64encode(compressed_tasks).decode("ascii")
220+
compressed_tasks = gzip_str.compress_tasks(tasks_list)
230221
task_upload_dict[
231222
f"v2/tasks/{self.projectId}/{group_id}"
232-
] = encoded_tasks
223+
] = compressed_tasks
233224
else:
234225
task_upload_dict[f"v2/tasks/{self.projectId}/{group_id}"] = tasks_list
235226

mapswipe_workers/mapswipe_workers/project_types/base/tutorial.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import base64
2-
import json
31
from abc import ABCMeta, abstractmethod
42

53
from mapswipe_workers import auth
@@ -51,12 +49,8 @@ def save_tutorial(self):
5149

5250
if self.projectType in [ProjectType.FOOTPRINT.value]:
5351
# we compress tasks for footprint project type using gzip
54-
json_string_tasks = json.dumps(tasks).replace(" ", "").replace("\n", "")
55-
compressed_tasks = gzip_str.gzip_str(json_string_tasks)
56-
# we need to decode back, but only when using Python 3.6
57-
# when using Python 3.7 it just works
58-
# Unfortunately the docker image uses Python 3.7
59-
tasks = {"101": base64.b64encode(compressed_tasks).decode("ascii")}
52+
compressed_tasks = gzip_str.compress_tasks(tasks)
53+
tasks = {"101": compressed_tasks}
6054

6155
ref.update(
6256
{

mapswipe_workers/mapswipe_workers/project_types/tile_map_service_grid/project.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,16 @@ def validate_geometries(self):
147147
feat_geom.Transform(transform)
148148
project_area = +feat_geom.GetArea() / 1000000
149149

150-
# calculate max area based on zoom level
151-
# for zoom level 18 this will be 5000 square kilometers
152150
# max zoom level is 22
153151
if self.zoomLevel > 22:
154152
raise CustomError(f"zoom level is too large (max: 22): {self.zoomLevel}.")
155153

154+
# We calculate the max area based on zoom level.
155+
# This is an approximation to restrict the project size
156+
# in respect to the number of tasks.
157+
# At zoom level 22 the max area is set to 200 square kilometers.
158+
# For zoom level 18 this will result in an max area of 5000 square kilometers.
159+
# (23-18) * (23-18) * 200 = 5000
156160
max_area = (23 - int(self.zoomLevel)) * (23 - int(self.zoomLevel)) * 200
157161

158162
if project_area > max_area:

mapswipe_workers/mapswipe_workers/utils/gzip_str.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import base64
12
import gzip
23
import io
4+
import json
5+
from typing import Dict, List
36

47

58
def gzip_str(string_: str) -> bytes:
@@ -16,3 +19,15 @@ def gzip_str(string_: str) -> bytes:
1619
def gunzip_bytes_obj(bytes_obj: bytes) -> str:
1720
"""Decompress gzip-compatible binary string."""
1821
return gzip.decompress(bytes_obj).decode()
22+
23+
24+
def compress_tasks(tasks_list: List[Dict]) -> str:
25+
"""Compress tasks for footprint project type using gzip."""
26+
json_string_tasks = json.dumps(tasks_list).replace(" ", "").replace("\n", "")
27+
compressed_tasks = gzip_str.gzip_str(json_string_tasks)
28+
# we need to decode back, but only when using Python 3.6
29+
# when using Python 3.7 it just works
30+
# Unfortunately the docker image uses Python 3.6
31+
encoded_tasks = base64.b64encode(compressed_tasks).decode("ascii")
32+
33+
return encoded_tasks

0 commit comments

Comments
 (0)