Skip to content

Commit 80821e1

Browse files
committed
Merge branch 'dev' of github.com:mapswipe/python-mapswipe-workers into dev
2 parents ee7f463 + fed3e18 commit 80821e1

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.csv

postgres/scripts/v1_to_v2/copy_from_csv.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ NAME="mapswipe"
55

66
for entity in projects groups tasks users results
77
do
8-
psql -h localhost -p 5432 -U ${USER} -d ${NAME} -a -f copy_${entity}_from_csv.sql
8+
psql \
9+
--host localhost \
10+
--port 5432 \
11+
--username ${USER} \
12+
--dbname ${NAME} \
13+
--echo-errors \
14+
--log-file copy_from_csv.log \
15+
--file copy_${entity}_from_csv.sql
916
done
1017

1118
# Commands if docker postgres port is not exposed:

postgres/scripts/v1_to_v2/copy_groups_from_csv.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
CREATE TEMP TABLE v1_groups (
77
project_id varchar,
88
v1_group_id int,
9-
group_id varchar DEFAULT NULL,
9+
group_id varchar,
1010
number_of_tasks int,
1111
finished_count int,
1212
required_count int,
@@ -29,12 +29,12 @@ WHERE required_count <= 0;
2929
UPDATE v1_groups
3030
SET group_id = cast(v1_group_id as varchar);
3131

32-
UPDATE groups
33-
SET (finished_count, required_count, progress) =
34-
(SELECT finished_count, required_count, progress
35-
FROM v1_groups
36-
WHERE groups.group_id = v1_groups.group_id
37-
AND groups.project_id = v1_groups.project_id);
32+
/* UPDATE groups */
33+
/* SET (finished_count, required_count, progress) = */
34+
/* (SELECT finished_count, required_count, progress */
35+
/* FROM v1_groups */
36+
/* WHERE groups.group_id = v1_groups.group_id */
37+
/* AND groups.project_id = v1_groups.project_id); */
3838

3939
-- Insert or update data of temp table to the permant table.
4040
-- Note that the special excluded table is used to

postgres/scripts/v1_to_v2/copy_projects_from_csv.sql

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,27 @@ FROM v1_imports
5555
WHERE v1_projects.import_id = v1_imports.import_id;
5656

5757
-- Convert geometry to postgis geometry type.
58-
UPDATE v1_projects
59-
SET geom = ST_Force2D(ST_Multi(ST_GeomFromKML(kml)))
60-
WHERE kml IS NOT NULL;
58+
-- If Geoemtry is invalid (Exception gets raised)
59+
-- Do Nothing. Continue with the next project.
60+
do $$
61+
DECLARE
62+
r record;
63+
BEGIN
64+
-- record is a structure that contains an element for each column in the select list
65+
FOR r IN SELECT * from v1_projects
66+
LOOP
67+
BEGIN
68+
UPDATE v1_projects
69+
SET geom = ST_Force2D(ST_Multi(ST_GeomFromKML(kml)))
70+
WHERE v1_projects.project_id = r.project_id;
71+
-- note the where condition that uses the value from the record variable
72+
EXCEPTION
73+
WHEN OTHERS THEN
74+
-- do nothing
75+
END;
76+
END LOOP;
77+
END
78+
$$ LANGUAGE plpgsql;
6179

6280
-- Insert or update data of temp table to the permant table (projects)
6381
-- Note that the special excluded table is used to reference values originally proposed for insertion
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-- Export v1 MapSwipe data to csv.
22
-- Rename attributes to conform to v2.
33
\copy (SELECT user_id, username FROM users) TO users.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
4-
\copy (SELECT project_id, task_id, user_id, timestamp as "timeint", info FROM results WHERE project_id = 5549) TO results.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
4+
\copy (SELECT project_id, task_id, user_id, timestamp as "timeint", info FROM results WHERE project_id in (SELECT project_id FROM projects GROUP BY project_id) AND user_id in (SELECT user_id FROM users)) TO results.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
-- Export v1 MapSwipe data to csv.
22
-- Rename attributes to conform to v2.
3-
\copy (SELECT archive, image, importkey as "import_id", isfeatured AS "is_featured", lookfor AS "look_for", name, progress, projectdetails AS "project_details", project_id, project_type, state AS "status", info AS "project_type_specifics" FROM projects WHERE project_id in (select project_id from results group by project_id) AND project_id = 5549) TO projects.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
4-
5-
\copy (SELECT i.import_id, i.info FROM imports i , projects p WHERE import_id in (select importkey as import_id from projects) AND p.project_id = 5549 AND p.importkey = i.import_id) TO imports.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
6-
7-
\copy (SELECT project_id, group_id as "v1_group_id", count as "number_of_tasks", completedcount as "finished_count", verificationcount as "required_count", info as "project_type_specifics" FROM groups WHERE project_id in (select project_id from results group by project_id) AND project_id = 5549 ) TO groups.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
8-
9-
\copy (SELECT project_id, group_id as "v1_group_id", task_id, info as "project_type_specifics" FROM tasks WHERE project_id in (select project_id from results group by project_id) AND project_id = 5549) TO tasks.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
3+
\copy (SELECT archive, image, importkey as "import_id", isfeatured AS "is_featured", lookfor AS "look_for", name, progress, projectdetails AS "project_details", project_id, project_type, state AS "status", info AS "project_type_specifics" FROM projects WHERE project_id in (select project_id from results group by project_id)) TO projects.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
4+
\copy (SELECT i.import_id, i.info FROM imports i WHERE import_id in (select importkey as import_id from projects)) TO imports.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
5+
\copy (SELECT project_id, group_id as "v1_group_id", count as "number_of_tasks", completedcount as "finished_count", verificationcount as "required_count", info as "project_type_specifics" FROM groups WHERE project_id in (select project_id from projects group by project_id) and project_id in (select project_id from results group by project_id) ) TO groups.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
6+
\copy (SELECT project_id, group_id as "v1_group_id", task_id, info as "project_type_specifics" FROM tasks WHERE project_id in (select project_id from projects group by project_id) and project_id in (select project_id from results group by project_id)) TO tasks.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);

0 commit comments

Comments
 (0)