Pular para o conteúdo principal

FV Decipher Support

Todos os tópicos, recursos necessários para FV Decipher.

Base de Conhecimento da FocusVision

Managing Data with the Transform Command


You can use the transform command to quickly access and modify your survey data with Python code.

Click here for information on modifying data using external data files.

1: Prepare a Python File

To modify your survey data using transform, you will first need to create a Python file (e.g.,somefile.py) containing your transformation code. This code can include variable, marker, and status modifications, as well as instructions for removing or replacing an entire record.

1.1: Modifying Variables

When modifying variables, include the variable label names, original data values (i.e., what will appear in the data file), and the values you would like assigned to them.

For example, assuming you have the variables q1, q2r1, and q2r2, you can add the following code to your file to assign a value of "q2r2" to q2r1 if q1 has a value of "1":

if q1 == 1:
q2r1 = q2r2.val

Keep in mind that a single question may have multiple variables assigned to it. Those variables are grouped in "variable groups", and you can get all the variables for a question by accessing its q.label.

For example, if you had a one-dimensional check-box question called "q1", with q1r1, r2, and r3 variables, accessing q.q1 would give you a list of these three (which you could then check for certain values or modify).

1.2: Modifying Markers

To modify survey markers using Python, run one of the following commands, specifying the marker you would like to modify:

  • hasMarker("..."):  will check for records with the specified marker
  • setMarker:  will set a marker for the specified record
  • removeMarker:  will remove the specified marker

1.3: Modifying Status

You can modify the status of a respondent using the status variable. For example, the code below would change the completion status to terminated for all respondents with q3r2 set to "1":

if q3r2 == 1:

1.4: Deleting a Record

To delete a record, simply call the delete() function:

if q3r3 == 1:

1.5: Replacing a Record

The replace function allows you to specify the default values for variables using the variable labels and the new values.

For example, if you have variables q1r1 and q1r2 and would like to replace their values with " 0 "  and " 1 ", respectively, you could use the following command:

replace([q1r1, q1r2], 0, 1)

2: Run the transform Command

Next, run the transform command, specifying your Python file:

transform survey somefile.py

If desired, you can include one of the following attributes to further define your command:

  • -v:  will trace changes as they happen
  • -t:  will run your transformation on test data
  • -a:  will run your transformation while allowing modification of hidden variables (where="notdp")

Note: If your code transformation is simple, you can alternatively pass it through on the command line by adding a space to the command (the extra space will designate a command code rather than a file). For example, transform.'setMarker(“qualified”)' would set the qualified marker on every respondent in the current survey.

Once run, you will be given a summary of the changes and prompted to continue before those changes are saved. The code in your Python file is run on each row of the survey data, and works similarly to variables in a tab-delimited file: each variable in the data corresponds to one Python variable.

3: Additional Considerations

  • Similar to the TabImport script, transform makes a backup to the data/old-results/ directory.
  • If using the -t switch, you can also use a script to create your own customized output file. For example:
transform -t . 'print "uuid = %s, status = %s" % (uuid, status)'
  • Este artigo foi útil?