Skip to content

Commit

Permalink
Track app_version and client_type in mapping_sessions table
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Oct 22, 2024
1 parent 542f57a commit 07557a2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Migration(migrations.Migration):
("start_time", models.DateTimeField(blank=True, null=True)),
("end_time", models.DateTimeField(blank=True, null=True)),
("items_count", models.SmallIntegerField(default=0)),
("app_version", models.CharField(max_length=999)),
("client_type", models.CharField(max_length=999)),
],
options={
"db_table": "mapping_sessions",
Expand Down
2 changes: 2 additions & 0 deletions django/apps/existing_database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ class MappingSession(Model):
start_time = models.DateTimeField(blank=True, null=True)
end_time = models.DateTimeField(blank=True, null=True)
items_count = models.SmallIntegerField(null=False, default=0)
app_version = models.CharField(max_length=999)
client_type = models.CharField(max_length=999)

class Meta:
managed = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ def results_to_file(
start_time = dateutil.parser.parse(result_data["startTime"])
end_time = dateutil.parser.parse(result_data["endTime"])
timestamp = end_time
app_version = result_data.get("appVersion", "")
client_type = result_data.get("clientType", "")

if type(result_data["results"]) is dict:
for taskId, result in result_data["results"].items():
Expand All @@ -279,6 +281,8 @@ def results_to_file(
start_time,
end_time,
result,
app_version,
client_type,
]
)
elif type(result_data["results"]) is list:
Expand All @@ -303,6 +307,8 @@ def results_to_file(
start_time,
end_time,
result,
app_version,
client_type,
]
)
else:
Expand Down Expand Up @@ -361,6 +367,8 @@ def save_results_to_postgres(
"start_time",
"end_time",
"result",
"app_version",
"client_type",
]
p_con.copy_from(results_file, result_temp_table, columns)
results_file.close()
Expand Down Expand Up @@ -420,9 +428,11 @@ def save_results_to_postgres(
nextval('mapping_sessions_mapping_session_id_seq'),
min(start_time),
max(end_time),
count(*)
count(*),
app_version,
client_type
FROM {result_temp_table}
GROUP BY project_id, group_id, user_id
GROUP BY project_id, group_id, user_id, app_version, client_type
ON CONFLICT (project_id,group_id,user_id)
DO NOTHING;
INSERT INTO {result_table}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def get_results(
ms.start_time as timestamp,
ms.start_time,
ms.end_time,
ms.app_version,
ms.client_type,
{result_sql},
-- the username for users which login to MapSwipe with their
-- OSM account is not defined or ''.
Expand Down
6 changes: 5 additions & 1 deletion mapswipe_workers/tests/integration/set_up_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ CREATE TABLE IF NOT EXISTS results_temp (
"timestamp" timestamp,
start_time timestamp,
end_time timestamp,
result int
result int,
app_version varchar,
client_type varchar
);

-- create table for results import through csv
Expand Down Expand Up @@ -175,6 +177,8 @@ CREATE TABLE IF NOT EXISTS mapping_sessions (
start_time timestamp DEFAULT NULL,
end_time timestamp DEFAULT NULL,
items_count int2 not null,
app_version varchar,
client_type varchar,
PRIMARY KEY (project_id, group_id, user_id),
FOREIGN KEY (project_id, group_id)
REFERENCES groups (project_id, group_id),
Expand Down
6 changes: 5 additions & 1 deletion postgres/initdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ CREATE TABLE IF NOT EXISTS results_temp (
"timestamp" timestamp,
start_time timestamp,
end_time timestamp,
result int
result int,
app_version varchar,
client_type varchar
);

-- create table for results import through csv
Expand Down Expand Up @@ -175,6 +177,8 @@ CREATE TABLE IF NOT EXISTS mapping_sessions (
start_time timestamp DEFAULT NULL,
end_time timestamp DEFAULT NULL,
items_count int2 not null,
app_version varchar,
client_type varchar,
PRIMARY KEY (project_id, group_id, user_id),
FOREIGN KEY (project_id, group_id)
REFERENCES groups (project_id, group_id),
Expand Down
15 changes: 15 additions & 0 deletions postgres/scripts/v2_to_v3/07_update_mapping_sessions_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This script updates the `mapping_sessions` table by adding the following columns:
* - `app_version`: Stores the version of the client application.
* - `client_type`: Indicates the type of client (currently supporting 'web' and 'mobile').
*
* Existing entries for `app_version` and `client_type` will be set to an empty string
* to indicate that they can correspond to either web or mobile, as web is already in use.
*
* Related issue: https://github.com/mapswipe/mapswipe/issues/852#issuecomment-2400077760
*/


ALTER TABLE mapping_sessions
ADD COLUMN app_version varchar,
ADD COLUMN client_type varchar;

0 comments on commit 07557a2

Please sign in to comment.