Score:0

Perform and store a calculation from a common field in two different nodes

us flag

Summary

I am collecting survey results - one for a pre-test and one for a post-test and I am looking for a way to automatically generate a calculation on a numerical field in two nodes (one pre-test, one post-test) and store that calculation.

For example in a content type "Survey Result", I have the following two nodes:
Node A:

  • field_participant_id: 111
  • field_pre_or_post: pre
  • field_mean: .5

Node B:

  • field_participant_id: 111
  • field_pre_or_post: post
  • field_mean: .75

I am hoping to be able to be able to automate a way to calculate the difference between field_mean in the two nodes (.25) when a post-test comes through and be able to store that calculated value.

More Details Below is some additional context in case it is helpful, or there is an easier way to do what I am trying to do.

  1. Data comes in using Webform filled out two times by a participant on a pre and post survey. The goal is to have the calculation run when the post survey is submitted.
  2. Each webform results is converted to a Survey Result content type using Webform Content Creator module that includes fields with: participant id, pre or post test and the mean score from the survey.
  3. Once a post survey is created, I am hoping to trigger a calculation the difference in those scores and store that calculation either in Node B or a new node/content bundle. Then I hope to use that calculated number in some views.

Any ideas on how something like this may be possible - preferably using a contribu module?

cn flag
[Computed Field](https://www.drupal.org/project/computed_field) does this, but as the module page states, it is better to write the hooks yourself in a custom module instead of using that module. To use hooks, you can use `hook_node_presave()` and set the value of the field.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.