0

I have the next code. I want to count the number of responses for each option in the Likert scale. I have a general model form that only save the response for each participant, but don't count the total of responses of all the participants. I need to generate the results for each question and each item on the scale. For example, for the snippet below, there should be 8 spaces with the total responses. (4 for each item for 2 which are the total number of questions)

This is the code in my models for each question of the Likert scale:

    class Group(BaseGroup):   
        def set_payoffs(self):
        players = self.get_players()
        sumPoints_e11a = [p.Points_e11a for p in players]
        sumPoints_e11b = [p.Points_e11b for p in players]
        sumPoints_e11c = [p.Points_e11c for p in players]
        sumPoints_e11d = [p.Points_e11d for p in players]
        self.Pointsa = sum(sumPoints_e11a)
        self.Pointsb  = sum(sumPoints_e11b)
        self.Pointsc  = sum(sumPoints_e11c)
        self.Pointsd  = sum(sumPoints_e11d)

    class Group(BaseGroup):   
    eleccion1 = models.PositiveIntegerField(
        choices=[[-3, "Muy Socialmente Inapropiado"],
                 [-1, "Muy Socialmente Inapropiado"],
                 [ 1, "Algo Socialmente Apropiado" ],
                 [ 3, "Muy Socialmente Apropiado"  ]
        ],
        widget=widgets.RadioSelect
    )
    eleccion2 = models.PositiveIntegerField(
        choices=[[-3, "Muy Socialmente Inapropiado"],
                 [-1, "Muy Socialmente Inapropiado"],
                 [1, "Algo Socialmente Apropiado"],
                 [3, "Muy Socialmente Apropiado"]
                 ],
        widget=widgets.RadioSelect
    )

This is my Page.py code

    class situaciond1(Page):
       form_model = 'player'
       form_fields = ['e11','e12','e13','e14','e15','e16', ]
       def before_next_page(self):
          for p in self.group.get_players():
              if p.e11 == -3:
               g.Points_e11a += 1    
              if p.e11 == -1:
               g.Points_e11b += 1
            if p.e11 ==  1:
               g.Points_e11c += 1
            if p.e11 ==  3:
               g.Points_e11d += 1  
            if p.e12 == -3:
               g.Points_e12a += 1
            if p.e12 == -1:
               g.Points_e12b += 1
            if p.e12 ==  1:
               g.Points_e12c += 1
            if p.e12 ==  3:
               g.Points_e12d += 1  
            if p.e13 == -3:

```

This is my html code, I used a sub-index to call the response of each item the future.

    <table class="tg">
      <tr>
        <th class="tg-mqa1">Elecciones Individuo A</th>
        <th class="tg-mqa1">Muy Socialmente Inapropiado</th>
        <th class="tg-mqa1">Algo socialmente Inapropriado</th>
        <th class="tg-mqa1">Algo socialmente Apropriadp</th>
        <th class="tg-mqa1">Muy Socilamente Apropiado</th>
      </tr>
      <tr>
        <td class="tg-wp8o"><span style="font-weight:bold">Tomar $COP 5 del Individuo B</span>     <br> (Individuo A obtiene $COP 10, Individuo B obtiene  $0)</td>
        <td class="tg-73oq"><input type="radio" name="elección1" value="1" > <br></td>
        <td class="tg-73oq"><input type="radio" name="elección1" value="1" > <br></td>
        <td class="tg-73oq"><input type="radio" name="elección1" value="1" > <br></td>
        <td class="tg-73oq"><input type="radio" name="elección1" value="1" > <br></td>
      </tr>
      <tr>
        <td class="tg-wp8o"><span style="font-weight:bold">Tomar $COP 5 del Individuo B</span>      <br>(Individuo A obtiene $COP 10, Individuo B obtiene  $0)</td>
        <td class="tg-73oq"><input type="radio" name="elección2" value="1" > </td>
        <td class="tg-73oq"><input type="radio" name="elección2" value="1" > </td>
        <td class="tg-73oq"><input type="radio" name="elección2" value="1" > </td>
        <td class="tg-73oq"><input type="radio" name="elección2" value="1" > </td>
      </tr>
      <tr>
  • Can you provide a [mcve] that others can run, please? – IonicSolutions Mar 11 '20 at 11:43
  • I just read the link that you posted but I am not clear of how to make the minimal reproducible example that you ask me. – Sebastián Ramírez Mar 12 '20 at 01:04
  • In the case of oTree, in most cases a [mcve] consists of a `pages.py`, `models.py` and a template, all of which should contain only the most essential elements and clearly highlight your problem. In the code you gave, there is a lot of "noise" like CSS formatting, which distracts from the problem, and it is not possible for others to copy the code and work on it on their own computer. You will find that the chances of a helpful answer rise a lot if you make it easy for others to play with and expand on your code. – IonicSolutions Mar 12 '20 at 06:52
  • Oh ! Thank you, I tried making some changes in my code, may in that way someone can help me. – Sebastián Ramírez Mar 12 '20 at 15:50

0 Answers0