Skip to content

Commit c0e4ae0

Browse files
committed
Track app_version and client_type in mapping_sessions table
1 parent 542f57a commit c0e4ae0

File tree

11 files changed

+88
-9
lines changed

11 files changed

+88
-9
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/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),

mapswipe_workers/tests/integration/test_get_results.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def test_get_results_df_from_postgres(self):
3535
"timestamp",
3636
"start_time",
3737
"end_time",
38+
"app_version",
39+
"client_type",
3840
"result",
3941
"username",
4042
"day",

mapswipe_workers/tests/integration/test_get_results_real_project.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ def setUp(self):
2929
),
3030
("tasks", None),
3131
("users", None),
32-
("mapping_sessions", None),
32+
("mapping_sessions", [
33+
"project_id",
34+
"group_id",
35+
"user_id",
36+
"mapping_session_id",
37+
"start_time",
38+
"end_time",
39+
"items_count",
40+
]),
3341
("mapping_sessions_results", None),
3442
]:
3543
set_up.set_postgres_test_data(
@@ -60,6 +68,8 @@ def test_get_results_df_from_postgres(self):
6068
"timestamp",
6169
"start_time",
6270
"end_time",
71+
"app_version",
72+
"client_type",
6373
"result",
6474
"username",
6575
"day",

mapswipe_workers/tests/integration/test_user_stats.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ def setUp(self):
3636
),
3737
("tasks", None),
3838
("users", None),
39-
("mapping_sessions", None),
39+
("mapping_sessions", [
40+
"project_id",
41+
"group_id",
42+
"user_id",
43+
"mapping_session_id",
44+
"start_time",
45+
"end_time",
46+
"items_count",
47+
]),
4048
("mapping_sessions_results", None),
4149
]:
4250
set_up.set_postgres_test_data(

postgres/initdb.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)