Calculate Average Rating from Radio Button with Microflows

0
Hello, I am quite new to Mendix, and I am currently creating a questionnaire for fun with questions that can evaluate one's personality traits. You can answer the questions on a scale from 1 to 5 with radio buttons. (I have created a enumeration attribute for this called Rating_Enum.) I have created an assessment entity and a questionnaire entity with a 1-* association. (On assessment can be associated with many questionnaires.) I have imported all the questions from an Excel importer into a data grid. And have put the data grid into a data view with the entity "assessment.". I want to be able to display the average score of the questions which were answered via radio buttons at the top of the data grid and, if possible, even colour code it. Any help would be really appreciated. :) 
asked
1 answers
0

Hello Ewan Mauersberger, 

 

You need to have an on change action on your rating so when it changes you recalculate the average value:

 

1.  create a on change micro/nanoflow

2. Retrieve all the question of the assesment 

3. Count the list of questions

4. Create a variable Divisor based and give it the value of the Count

5. then you need to create a variable called the Quotient which you can fill with the sum of values 

6. To get this sum you can do multiple things you but be aware of at least the following, an enumeration is not an integer so you need to parse it or filter on it but still use a variable with the integer value

7a. Option 1 you can do a Loop over the list and add the value corresponding to the integer to the Quotient

7b. Option 2 you can filter the list based on the enum and count that list then multiply the count with the corresponding integer and add it to the quotient

 

8. divide the quotient by the dividor, be also aware you do not divide 0 or divide by zero

9. set the value on the entity and refresh the entity !!!

 

Hope this helps,

 

Good luck!

 

answered