Survey Scoring Answered

Thejas Suvarna

I had a quick question about scoring surveys. Is MyDataHelps able to do some simple math to generate numerical scores based on survey answer values? I have a survey comprised of 15 questions with discrete, numerical scales from 0 to 10. To score this survey, you simply add the values from all 15 questions. Is this possible to do either with custom fields and branching logic or perhaps by editing the raw template.

0

Comments

1 comment

  • Comment author
    Thejas Suvarna
    • Edited
    • Official comment

    Thanks for reaching out. This is something MyDataHelps can support self-service. It will require the use of a Web View Step. 

    Below, please find a sample Web View step code that uses the getCurrentSurveyAnswers function to retrieve the participants answers to respective step identifier and then build logic to sum the values. This example sums the values of 3 questions and returns that as the result of the Web View step. This example makes all of this happens behind the scenes without any participant intervention by utilizing window.onload which permits an auto-submitting behavior. 

    Note: If you would like to retrieve an answer from a Question/Web View step use the syntax getAnswer(results, stepIdentifier). If you are trying to retrieve an answer from a form step (ex. Question 3 below), use the syntax getAnswer(results, stepIdentifier, resultIdentifier). 

    <!DOCTYPE html> <html> <head>  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">  <style type="text/css">    body {      height: 95%;      position: relative;      font-family: Helvetica, Arial, sans-serif;      font-size: 1.2em;      text-align: center;      display: block !important;    }        #message {      display: none;      padding-top: 80px;    }        #spinner {      border: 5px solid #f3f3f3;      border-top: 5px solid #366DBC;      border-radius: 50%;      width: 30px;      height: 30px;      animation: spin 1s linear infinite;      margin: 0 auto;    }        @keyframes spin {      0% {        transform: rotate(0deg);      }            100% {        transform: rotate(360deg);      }    }  </style>  <script src="https://cdn.careevolution.com/mydatahelps-js/3.8.0/MyDataHelps.min.js" integrity="sha384-AnvbLdDWX3rYJV1rHB/kOn4oDx2Tyc3bJWiikUWqHOhV/kJ00c1yk6Vjq4ryaIQm" crossorigin="anonymous"></script> </head> <body style="display:none">  <div id="spinner"></div>  <div id="log"></div>  <script type="text/javascript">    function getAnswer(results, stepIdentifier, resultIdentifier) {            resultIdentifier = resultIdentifier || stepIdentifier;            var answer = results.find(function (answer) {        return answer.stepIdentifier === stepIdentifier && answer.resultIdentifier === resultIdentifier;      });            return answer?.answers || [];    }        function getScore() {      return MyDataHelps.getCurrentSurveyAnswers().then(function(results){        var surveyScore = 0;        var q1 = getAnswer(results, "Question 1")[0] || 0;        var q2 = getAnswer(results, "Question 2")[0] || 0;        var q3 = getAnswer(results, "Question 3", "ResultIdentifier1")[0] || 0;        surveyScore = parseInt(q1) + parseInt(q2) + parseInt(q3);        console.log(surveyScore);        return (surveyScore);      });    }        function submit() {      getScore().then(function(score) {        if (score == null) {          window.webkit.messageHandlers.ResearchKit.postMessage("");        } else {          window.webkit.messageHandlers.ResearchKit.postMessage(score);        }      });    }    window.onload = submit;    submit();  </script> </body> </html>

Please sign in to leave a comment.