LP#1728677 - Add survey data to concerto test dataset.
authorChris Sharp <csharp@georgialibraries.org>
Mon, 30 Oct 2017 16:29:20 +0000 (12:29 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 9 Nov 2017 14:34:33 +0000 (09:34 -0500)
To more closely approximate a realistic test environment,
this branch adds data to the concerto test dataset.  Most users
are given a randomized response to a simple 3-question survey.

Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>

Open-ILS/tests/datasets/sql/load_all.sql
Open-ILS/tests/datasets/sql/surveys.sql [new file with mode: 0644]

index df4e532..ce89563 100644 (file)
@@ -87,6 +87,9 @@ INSERT INTO biblio.record_entry (marc, last_xact_id)
 -- load MR copies, etc.
 \i assets_mr.sql
 
+-- load survey data
+\i surveys.sql
+
 -- clean up the env
 \i env_destroy.sql
 
diff --git a/Open-ILS/tests/datasets/sql/surveys.sql b/Open-ILS/tests/datasets/sql/surveys.sql
new file mode 100644 (file)
index 0000000..f45de8d
--- /dev/null
@@ -0,0 +1,52 @@
+/** Create a survey */
+INSERT INTO action.survey (id, owner, name, description) VALUES (1, 1, 'Who would cross the Bridge of Death must answer me these questions three, ere the other side he see.', 'Test survey for concerto dataset');
+
+/** Populate with questions */
+INSERT INTO action.survey_question (id, survey, question) VALUES (1, 1, 'What... is your name?');
+INSERT INTO action.survey_question (id, survey, question) VALUES (2, 1, 'What... is your quest?');
+INSERT INTO action.survey_question (id, survey, question) VALUES (3, 1, 'What... is your favorite color?');
+
+/** Attach answers to questions */
+INSERT INTO action.survey_answer (id, question, answer) VALUES (1, 1, 'My name is Sir Lancelot of Camelot.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (2, 1, 'Sir Robin of Camelot.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (3, 1, 'Sir Galahad of Camelot.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (4, 1, 'General Leia Organa.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (5, 1, 'Dr. Beverly Crusher.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (6, 1, 'Rose Tyler.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (7, 1, 'Sorry, not interested.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (8, 2, 'To seek the Holy Grail.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (9, 2, 'To go where no one has gone before.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (10, 2, 'To steal the plans for the Death Star.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (11, 2, 'To save the universe from the Daleks again.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (12, 2, 'What is this again?');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (13, 3, 'Blue');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (14, 3, 'Blue. No yellow... AAAGGH!');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (15, 3, 'Jedi cloak brown.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (16, 3, 'Redshirt red.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (17, 3, 'TARDIS blue.');
+INSERT INTO action.survey_answer (id, question, answer) VALUES (18, 3, 'This is getting too silly - I quit.');
+
+/** for every user with an id not evenly divisible by 6, 
+ *  add a randomized response for every question in the survey
+ */
+CREATE FUNCTION populate_survey_responses(usr INTEGER) RETURNS VOID AS
+$BODY$
+DECLARE q INT;
+BEGIN
+IF usr % 6 <> 0 THEN
+    FOR q in 1..3 LOOP
+        INSERT INTO action.survey_response (usr, survey, question, answer, answer_date) VALUES (
+        usr,
+        1,
+        q,
+        (SELECT id FROM action.survey_answer WHERE question = q ORDER BY random() LIMIT 1),
+        now());
+    END LOOP;
+END IF;
+END;
+$BODY$
+LANGUAGE plpgsql;
+
+SELECT populate_survey_responses(id) FROM actor.usr;
+
+DROP FUNCTION populate_survey_responses(usr INTEGER);