Skip to content

Commit 75e6750

Browse files
authored
Merge pull request #972 from mapswipe/fix/urlB-issue
Fix/url b issue
2 parents 071d187 + c0e4ae0 commit 75e6750

File tree

15 files changed

+119
-16
lines changed

15 files changed

+119
-16
lines changed

django/apps/existing_database/migrations/0002_mappingsession_mappingsessionresult.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Migration(migrations.Migration):
2222
("start_time", models.DateTimeField(blank=True, null=True)),
2323
("end_time", models.DateTimeField(blank=True, null=True)),
2424
("items_count", models.SmallIntegerField(default=0)),
25+
("app_version", models.CharField(max_length=999)),
26+
("client_type", models.CharField(max_length=999)),
2527
],
2628
options={
2729
"db_table": "mapping_sessions",

django/apps/existing_database/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ class MappingSession(Model):
233233
start_time = models.DateTimeField(blank=True, null=True)
234234
end_time = models.DateTimeField(blank=True, null=True)
235235
items_count = models.SmallIntegerField(null=False, default=0)
236+
app_version = models.CharField(max_length=999)
237+
client_type = models.CharField(max_length=999)
236238

237239
class Meta:
238240
managed = False

mapswipe_workers/mapswipe_workers/firebase_to_postgres/transfer_results.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ def results_to_file(
264264
start_time = dateutil.parser.parse(result_data["startTime"])
265265
end_time = dateutil.parser.parse(result_data["endTime"])
266266
timestamp = end_time
267+
app_version = result_data.get("appVersion", "")
268+
client_type = result_data.get("clientType", "")
267269

268270
if type(result_data["results"]) is dict:
269271
for taskId, result in result_data["results"].items():
@@ -279,6 +281,8 @@ def results_to_file(
279281
start_time,
280282
end_time,
281283
result,
284+
app_version,
285+
client_type,
282286
]
283287
)
284288
elif type(result_data["results"]) is list:
@@ -303,6 +307,8 @@ def results_to_file(
303307
start_time,
304308
end_time,
305309
result,
310+
app_version,
311+
client_type,
306312
]
307313
)
308314
else:
@@ -361,6 +367,8 @@ def save_results_to_postgres(
361367
"start_time",
362368
"end_time",
363369
"result",
370+
"app_version",
371+
"client_type",
364372
]
365373
p_con.copy_from(results_file, result_temp_table, columns)
366374
results_file.close()
@@ -420,9 +428,11 @@ def save_results_to_postgres(
420428
nextval('mapping_sessions_mapping_session_id_seq'),
421429
min(start_time),
422430
max(end_time),
423-
count(*)
431+
count(*),
432+
app_version,
433+
client_type
424434
FROM {result_temp_table}
425-
GROUP BY project_id, group_id, user_id
435+
GROUP BY project_id, group_id, user_id, app_version, client_type
426436
ON CONFLICT (project_id,group_id,user_id)
427437
DO NOTHING;
428438
INSERT INTO {result_table}

mapswipe_workers/mapswipe_workers/generate_stats/project_stats.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def get_results(
121121
ms.start_time as timestamp,
122122
ms.start_time,
123123
ms.end_time,
124+
ms.app_version,
125+
ms.client_type,
124126
{result_sql},
125127
-- the username for users which login to MapSwipe with their
126128
-- OSM account is not defined or ''.

mapswipe_workers/mapswipe_workers/project_types/tile_map_service/change_detection/tutorial.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
from dataclasses import asdict, dataclass
2+
13
from mapswipe_workers.definitions import logger
24
from mapswipe_workers.project_types.tile_map_service.tutorial import (
35
TileMapServiceBaseTutorial,
6+
TileMapServiceBaseTutorialTask,
47
)
58
from mapswipe_workers.project_types.tile_server import BaseTileServer
69
from mapswipe_workers.utils import tile_functions
710

811

12+
@dataclass
13+
class ChangeDetectionTutorialTask(TileMapServiceBaseTutorialTask):
14+
urlB: str
15+
16+
917
class ChangeDetectionTutorial(TileMapServiceBaseTutorial):
1018
"""The subclass for an TMS Grid based Tutorial."""
1119

@@ -36,11 +44,16 @@ def create_tutorial_tasks(self):
3644

3745
super().create_tutorial_tasks()
3846

47+
modified_tasks = []
3948
for task in self.tasks[101]:
4049
_, tile_x, tile_y = task.taskId_real.split("-")
41-
task.urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
50+
urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
4251
int(tile_x), int(tile_y), self.zoomLevel, self.tileServerB
4352
)
53+
modified_tasks.append(
54+
ChangeDetectionTutorialTask(**asdict(task), urlB=urlB)
55+
)
56+
self.tasks[101] = modified_tasks
4457

4558
logger.info(
4659
f"{self.projectId}"

mapswipe_workers/mapswipe_workers/project_types/tile_map_service/completeness/tutorial.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
from dataclasses import asdict, dataclass
2+
13
from mapswipe_workers.definitions import logger
24
from mapswipe_workers.project_types.tile_map_service.tutorial import (
35
TileMapServiceBaseTutorial,
6+
TileMapServiceBaseTutorialTask,
47
)
58
from mapswipe_workers.project_types.tile_server import BaseTileServer
69
from mapswipe_workers.utils import tile_functions
710

811

12+
@dataclass
13+
class CompletenessTutorialTask(TileMapServiceBaseTutorialTask):
14+
urlB: str
15+
16+
917
class CompletenessTutorial(TileMapServiceBaseTutorial):
1018
"""The subclass for an TMS Grid based Tutorial."""
1119

@@ -36,11 +44,14 @@ def create_tutorial_tasks(self):
3644

3745
super().create_tutorial_tasks()
3846

47+
modified_tasks = []
3948
for task in self.tasks[101]:
4049
_, tile_x, tile_y = task.taskId_real.split("-")
41-
task.urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
50+
urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
4251
int(tile_x), int(tile_y), self.zoomLevel, self.tileServerB
4352
)
53+
modified_tasks.append(CompletenessTutorialTask(**asdict(task), urlB=urlB))
54+
self.tasks[101] = modified_tasks
4455

4556
logger.info(
4657
f"{self.projectId}"

mapswipe_workers/mapswipe_workers/project_types/tile_map_service/tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
from typing import Dict, List
2+
from typing import Dict, List, Union
33

44
from mapswipe_workers.definitions import logger
55
from mapswipe_workers.firebase.firebase import Firebase
@@ -25,8 +25,8 @@ class TileMapServiceBaseTutorial(BaseTutorial):
2525
def __init__(self, tutorial_draft):
2626
super().__init__(tutorial_draft)
2727

28-
self.groups: Dict[str, TileMapServiceBaseGroup] = {}
29-
self.tasks: Dict[str, List[TileMapServiceBaseTutorialTask]] = (
28+
self.groups: Dict[Union[str, int], TileMapServiceBaseGroup] = {}
29+
self.tasks: Dict[Union[str, int], List[TileMapServiceBaseTutorialTask]] = (
3030
{}
3131
) # dict keys are group ids
3232

mapswipe_workers/mapswipe_workers/utils/api_calls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def remove_noise_and_add_user_info(json: dict) -> dict:
149149
for i, subset in enumerate(chunk_list):
150150
changeset_results = query_osmcha(subset, changeset_results)
151151
progress = round(100 * ((i + 1) / len(chunk_list)), 1)
152-
logger.info(f"finished query {i+1}/{len(chunk_list)}, {progress}")
152+
logger.info(f"finished query {i + 1}/{len(chunk_list)}, {progress}")
153153

154154
missing_ids = [i for i, v in changeset_results.items() if v is None]
155155
chunk_list = chunks(missing_ids, batch_size)
@@ -160,7 +160,7 @@ def remove_noise_and_add_user_info(json: dict) -> dict:
160160
for i, subset in enumerate(chunk_list):
161161
changeset_results = query_osm(subset, changeset_results)
162162
progress = round(100 * ((i + 1) / len(chunk_list)), 1)
163-
logger.info(f"finished query {i+1}/{len(chunk_list)}, {progress}")
163+
logger.info(f"finished query {i + 1}/{len(chunk_list)}, {progress}")
164164

165165
for feature in json["features"]:
166166
changeset = changeset_results[int(feature["properties"]["changesetId"])]

mapswipe_workers/tests/integration/set_up.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ def create_test_project(
8585
set_postgres_test_data(project_type, "users", "user")
8686
set_firebase_test_data(project_type, "user_groups", "user_group", "")
8787
set_firebase_test_data(project_type, "results", fixture_name, project_id)
88-
set_postgres_test_data(project_type, "mapping_sessions", fixture_name)
88+
set_postgres_test_data(project_type, "mapping_sessions", fixture_name, columns=[
89+
"project_id",
90+
"group_id",
91+
"user_id",
92+
"mapping_session_id",
93+
"start_time",
94+
"end_time",
95+
"items_count",
96+
])
8997
set_postgres_test_data(project_type, mapping_sessions_results, fixture_name)
9098
if create_user_group_session_data:
9199
set_postgres_test_data(

mapswipe_workers/tests/integration/set_up_db.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ CREATE TABLE IF NOT EXISTS results_temp (
9191
"timestamp" timestamp,
9292
start_time timestamp,
9393
end_time timestamp,
94-
result int
94+
result int,
95+
app_version varchar,
96+
client_type varchar
9597
);
9698

9799
-- create table for results import through csv
@@ -103,7 +105,9 @@ CREATE TABLE IF NOT EXISTS results_geometry_temp (
103105
"timestamp" timestamp,
104106
start_time timestamp,
105107
end_time timestamp,
106-
result varchar
108+
result varchar,
109+
app_version varchar,
110+
client_type varchar
107111
);
108112

109113

@@ -175,6 +179,8 @@ CREATE TABLE IF NOT EXISTS mapping_sessions (
175179
start_time timestamp DEFAULT NULL,
176180
end_time timestamp DEFAULT NULL,
177181
items_count int2 not null,
182+
app_version varchar,
183+
client_type varchar,
178184
PRIMARY KEY (project_id, group_id, user_id),
179185
FOREIGN KEY (project_id, group_id)
180186
REFERENCES groups (project_id, group_id),

0 commit comments

Comments
 (0)