In this article
The umerge command allows for flexible copy, transformation and
review of data from the shell environment when one or both surveys have
delphi="1".
Data is converted based on matching answer labels. You can correctly merge data
from q1 with r1, r2, r3 as answers into a survey where
q1 answers are r3, r2,
r1.
1: Merging Data
You can use umerge to transfer data. When invoking
umerge, you must provide the path to the source and target surveys
in your command. For example, if you want to copy all records from
selfserve/9d3/200800 that do not already exist in
selfserve/9d3/210700, enter the following code:
$ umerge append selfserve/9d3/200800 selfserve/9d3/210700
When you run the umerge command, you will be presented with a basic
plan that tells you what data will be transferred. You will be asked to press
Y to begin the data import. If you do not want to begin the
data import, press Control+C to cancel the
request.
To view the data that will be imported in the target survey, press V. The data preview is limited to 1 megabyte and the differences preview is truncated to the first 10,000 differences.
Note: Only projects in the selfserve directory can use the
umerge command.
2: umerge Commands
You can specify the full name (e.g. umerge join) or just the first
character (e.g. umerge j of the command.
Command |
Effect |
|
Copy every record from A that does not already exist in B. Use
|
|
Update records in B that also exist in A. This is similar to
tabimport without
the |
|
Update or create records. |
|
Create a data file to be used for importing the data into the
other survey. This can be used to extract a subset of data, perhaps
transforming it via |
|
Update records in A with data from A, after transforming it.
Use the |
|
Compare data in A to that in B, for records that exist in both.
Only non-virtuals are compared. At most 10,000 lines of changes
are returned. Use the |
3: umerge Options
Options (e.g. --yes) can appear before or after the command.
Modifier |
Effect |
|
or
|
Include only these specific variables or question labels in the data processed.
E.g. |
|
or
|
Exclude specific variables or questions from the output. These are removed after the inclusion is processed.
E.g.
Use |
|
Do not output the “plan” that describes what data will be transferred and what questions might be missing. Do not output the summary afterwards. Do not show progress bars. |
|
Do not ask for confirmation. This is the default if run from cron and not from a terminal. |
|
By default, all completes from the source (ALL). Specify
|
|
Run custom code for each row after generating the data. Give
a filename as an argument to this function. In the file you can
reference |
|
Change the name of the question while transferring data over.
E.g. if a question with the same structure is named |
|
Do not try to copy over field data. Field data is normally copied only when records are created and using UUID key; see Additional Considerations below for details. |
|
Usable only with |
|
When displaying a list of changed variables, show them in tab delimited format without truncation. Normal output: zcggkga0ma99ghmu q5 5255643.6 -> 5255643.60001 With uuid var old new |
3.1: Transformation
The code you specify with --code can reference the d
variable which will contain all the data (using symbolic values only: for radio/select
questions, it is the row labels (e.g. “r1” and not “1”).
d is a dictionary so you can use d[“varname”] to read/write
that variable, which will always be a string. You can reference the survey environment,
but can only access question data through the d variable. Alternatively,
use d.varname if this is a valid Python varname.
Convenience methods allow you to easily modify markers:
d.setMarker(“name”), d.deleteMarker(“name”) and
d.hasMarker(“name”) for checking whether a marker is set.
Calling d.delete() will mark the record as deleted.
Note: You can only look at the values of the variables in transformation
code. You cannot use survey-style conditions such as if q3.r1.
4: Example Commands with Options
You can specify the full name (e.g. umerge join) or just the first
character (e.g. umerge j) of the command.
Options
(e.g. --yes ) can appear before or after the command.
Example Task |
Effect |
|
Copy every record in survey A to survey B. Records whose UUID
(or variable specified with |
|
Copy only qualified participants from A to B. Do not ask for confirmation and do not describe what is about to happen. Exclude the “record” variable so it is reset in B. |
|
Output |
|
Output |
|
Output |
|
For every participant in A, delete the matching source in B.
|
|
For participants that exist between A and B, update existing data
and create other records. When transferring data over, rename
|
|
Modify data for this survey, copying what is in |
5: Additional Considerations
-
Layouts are not applied to ensure all data will be transferred even if hidden
or relabeled from
survey.xml. -
Field data is only copied for new records if you are merging based on UUID.
-
If one survey has
delphi="1"enabled and the other does not, page data and auxiliary DB data are not copied. -
If both surveys have
delphi="1"enabled, field data includes page-level data (i.e. 50 seconds were spent onq1page). Field data question labels are not renamed. -
If both surveys do not have
delphi="1"enabled,data/variables.datanddata/completions.datare updated in the target, based on the new UUIDs that have been created and have data in the source.
-
If one survey has
- Virtual data is not copied, even if there is a matching non-virtual target variable.
- Text and textarea elements can be copied to/from number and float. Invalid data will not be imported.
- Image questions will not have their uploaded data copied.
- Video Testimonials that store data outside will not have their data copied.
6: Error Codes
When an error occurs, the following codes may display:
Error Code |
Explanation |
|
You have asked for data to be merged based on a key other than UUID. However, it does not exist in this survey you have specified. |
|
You used the |
|
Because |