Skip to content

Commit c69e8f4

Browse files
committed
fix(exports): fix exports for find project
- use label instead of value for client type in results export - use project firebase_id instead of id in history export - read tile_x, tile_y, tile_z instead of task_x, task_y, task_z in hot tm exports - skip flattening hot tm exports - add url in tile map service project tasks - fix calculation of required_count, progress
1 parent 7586492 commit c69e8f4

File tree

13 files changed

+202
-220
lines changed

13 files changed

+202
-220
lines changed

apps/mapping/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def get_client_type(cls, value: str) -> "MappingSessionClientTypeEnum":
2626
"web": cls.WEB,
2727
}.get(value, cls.UNKNOWN)
2828

29+
@classmethod
30+
def get_client_type_label_sql(cls, field: str) -> str:
31+
return f"""
32+
CASE {field}
33+
WHEN {cls.MOBILE_ANDROID.value} THEN 'android'
34+
WHEN {cls.MOBILE_IOS.value} THEN 'ios'
35+
WHEN {cls.WEB.value} THEN 'web'
36+
ELSE 'unknown'
37+
END
38+
"""
39+
2940

3041
class MappingSession(models.Model):
3142
"""Model representing a mapping session where a contributor user worked on a specific project task group."""

apps/project/exports/mapping_results.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from apps.contributor.models import ContributorUser
99
from apps.mapping.models import (
1010
MappingSession,
11+
MappingSessionClientTypeEnum,
1112
MappingSessionResult,
1213
)
1314
from apps.project.models import Project, ProjectTask, ProjectTaskGroup
@@ -19,7 +20,6 @@
1920

2021

2122
def generate_mapping_results(*, destination_filename: Path, project: Project) -> pd.DataFrame:
22-
# TODO: client_type IS ENUM -- CONVERT TO VALUE?
2323
sql_query = sql.SQL(f"""
2424
COPY (
2525
SELECT
@@ -38,7 +38,9 @@ def generate_mapping_results(*, destination_filename: Path, project: Project) ->
3838
MS.{fd_name(MappingSession.start_time)} as start_time,
3939
MS.{fd_name(MappingSession.end_time)} as end_time,
4040
MS.{fd_name(MappingSession.app_version)} as app_version,
41-
MS.{fd_name(MappingSession.client_type)} as client_type,
41+
(
42+
{MappingSessionClientTypeEnum.get_client_type_label_sql(f"MS.{fd_name(MappingSession.client_type)}")}
43+
) as client_type,
4244
MSR.{fd_name(MappingSessionResult.result)} as result,
4345
-- the username for users which login to MapSwipe with their
4446
-- OSM account is not defined or ''.

apps/project/exports/project_stats_by_date.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,6 @@ def get_project_history(
177177

178178
# merge contributors and progress
179179
project_history_df = progress_by_date_df.merge(contributors_by_date_df, left_on="day", right_on="day")
180-
project_history_df["project_id"] = project.id
180+
project_history_df["project_id"] = project.firebase_id
181181
project_history_df.to_csv(destination_filename)
182182
return project_history_df

apps/project/exports/project_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def generate_project_tasks(
4444
PTG.{fd_name(ProjectTaskGroup.firebase_id)} as group_id,
4545
PT.{fd_name(ProjectTask.firebase_id)} as task_id,
4646
-- Metadata
47-
ST_AsText({fd_name(ProjectTask.geometry)}) AS geom,
47+
ST_AsText(ST_Multi({fd_name(ProjectTask.geometry)})) AS geom,
4848
'{project.project_type_specifics.get("zoom_level")}' as tile_z,
4949
-- NOTE: Existing tile_x and tile_y are passed from project_type_specifics now
5050
-- NOTE: this is destructured by normalize_project_type_specifics(write_sql_to_gzipped_csv)

apps/project/exports/tasking_manager_geometries.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def _get_row_value[T: int | float](
5959

6060
task_id = row[1]
6161

62-
task_x = _get_row_value(column_index_map, row, "task_x")
63-
task_y = _get_row_value(column_index_map, row, "task_y")
64-
task_z = _get_row_value(column_index_map, row, "task_z")
62+
task_x = _get_row_value(column_index_map, row, "tile_x")
63+
task_y = _get_row_value(column_index_map, row, "tile_y")
64+
task_z = _get_row_value(column_index_map, row, "tile_z")
6565

6666
# TODO: Add no_count here and use later
6767
project_data.append(
@@ -108,6 +108,7 @@ def _get_row_value[T: int | float](
108108
task_x,
109109
task_y,
110110
task_z,
111+
skip_flatten=True,
111112
),
112113
},
113114
)

apps/project/tests/e2e_create_project_tile_map_service_test.py

Lines changed: 124 additions & 186 deletions
Large diffs are not rendered by default.

apps/project/tests/export_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def setUpClass(cls):
9595
project_type_specifics=FindProjectTaskProperty(
9696
tile_x=1,
9797
tile_y=2,
98+
url="https://some-service.com/14/1/2/",
9899
).model_dump(),
99100
)
100101
]

apps/project/tests/mutation_test.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ class TaskGroupType(typing.TypedDict):
13931393
{
13941394
"firebase_id": "g101",
13951395
"number_of_tasks": 18,
1396-
"required_count": 18 * 10,
1396+
"required_count": 10,
13971397
"total_area": 210.10735845202447,
13981398
"project_type_specifics": {
13991399
"x_max": 24152,
@@ -1405,7 +1405,7 @@ class TaskGroupType(typing.TypedDict):
14051405
{
14061406
"firebase_id": "g102",
14071407
"number_of_tasks": 24,
1408-
"required_count": 24 * 10,
1408+
"required_count": 10,
14091409
"total_area": 280.2915392364502,
14101410
"project_type_specifics": {
14111411
"x_max": 24153,
@@ -1417,7 +1417,7 @@ class TaskGroupType(typing.TypedDict):
14171417
{
14181418
"firebase_id": "g103",
14191419
"number_of_tasks": 24,
1420-
"required_count": 24 * 10,
1420+
"required_count": 10,
14211421
"total_area": 280.4398676951218,
14221422
"project_type_specifics": {
14231423
"x_max": 24153,
@@ -1429,7 +1429,7 @@ class TaskGroupType(typing.TypedDict):
14291429
{
14301430
"firebase_id": "g104",
14311431
"number_of_tasks": 6,
1432-
"required_count": 6 * 10,
1432+
"required_count": 10,
14331433
"total_area": 70.14703242812156,
14341434
"project_type_specifics": {
14351435
"x_max": 24150,
@@ -1445,34 +1445,44 @@ class TaskGroupType(typing.TypedDict):
14451445
"project_type_specifics": {
14461446
"tile_x": 24147,
14471447
"tile_y": 13753,
1448+
"url": "https://hi-there/24147/13753/15",
1449+
"url_b": "https://services.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/DigitalGlobe%3AImageryTileService@EPSG%3A3857@jpg/15/24147/13753.jpg?connectId=dummy-maxar-standard",
14481450
},
14491451
},
14501452
{
14511453
"firebase_id": "15-24147-13754",
14521454
"project_type_specifics": {
14531455
"tile_x": 24147,
14541456
"tile_y": 13754,
1457+
"url": "https://hi-there/24147/13754/15",
1458+
"url_b": "https://services.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/DigitalGlobe%3AImageryTileService@EPSG%3A3857@jpg/15/24147/13754.jpg?connectId=dummy-maxar-standard",
14551459
},
14561460
},
14571461
{
14581462
"firebase_id": "15-24147-13755",
14591463
"project_type_specifics": {
14601464
"tile_x": 24147,
14611465
"tile_y": 13755,
1466+
"url": "https://hi-there/24147/13755/15",
1467+
"url_b": "https://services.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/DigitalGlobe%3AImageryTileService@EPSG%3A3857@jpg/15/24147/13755.jpg?connectId=dummy-maxar-standard",
14621468
},
14631469
},
14641470
{
14651471
"firebase_id": "15-24148-13753",
14661472
"project_type_specifics": {
14671473
"tile_x": 24148,
14681474
"tile_y": 13753,
1475+
"url": "https://hi-there/24148/13753/15",
1476+
"url_b": "https://services.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/DigitalGlobe%3AImageryTileService@EPSG%3A3857@jpg/15/24148/13753.jpg?connectId=dummy-maxar-standard",
14691477
},
14701478
},
14711479
{
14721480
"firebase_id": "15-24148-13754",
14731481
"project_type_specifics": {
14741482
"tile_x": 24148,
14751483
"tile_y": 13754,
1484+
"url": "https://hi-there/24148/13754/15",
1485+
"url_b": "https://services.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/DigitalGlobe%3AImageryTileService@EPSG%3A3857@jpg/15/24148/13754.jpg?connectId=dummy-maxar-standard",
14761486
},
14771487
},
14781488
]
@@ -1482,7 +1492,7 @@ class TaskGroupType(typing.TypedDict):
14821492
project_task_qs = ProjectTask.objects.filter(task_group__project=latest_project)
14831493

14841494
assert {
1485-
"required_results": sum(task_group["required_count"] for task_group in expected_task_groups),
1495+
"required_results": (18 + 24 + 24 + 6) * 10,
14861496
"tasks_groups_count": project_task_group_qs.count(),
14871497
"tasks_groups": list(
14881498
project_task_group_qs.order_by("id").values(

project_types/base/project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ def analyze_groups(self):
142142
)
143143
# NOTE: After number_of_tasks is calculated
144144
project_task_groups_qs.update(
145-
required_count=models.F("number_of_tasks") * self.project.verification_number,
145+
required_count=self.project.verification_number,
146146
time_spent_max_allowed=(models.F("number_of_tasks") * self.get_max_time_spend_percentile()),
147147
)
148148

149149
self.project.required_results = (
150150
ProjectTaskGroup.objects.filter(project_id=self.project.pk).aggregate(
151-
required_results=models.Sum("required_count"),
151+
required_results=models.Sum("number_of_tasks") * self.project.verification_number,
152152
)
153153
)["required_results"] or 0
154154

0 commit comments

Comments
 (0)