oTree Forum >

Random signal generator

#1 by alid3mir

Hi everyone,
I am trying to write an app that will generate one of two types of strings randomly to the participants.
I couldnt success yet, and I dont know what is the problem:



----------------------------------------------------
from otree.api import *
import random

class C(BaseConstants):
    NAME_IN_URL = 'feedback'
    PLAYERS_PER_GROUP = None
    NUM_ROUNDS = 1


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    pass


class Player(BasePlayer):
    random_signal = models.StringField(initial=None)
    newsevaluation = models.IntegerField(
        label='''
        Do you think this information is from True News or Fake News?
        <br>
        Evaluate the probability of the correctness of the information from 0 to 100.

        ''', min=0, max=100
    )
# FUNCTIONS
# PAGES
class Introduction(Page):
    pass

class feedback(Page):
        form_model = 'player'
        form_fields = ['newsevaluation']

        @staticmethod
        def before_next_page(player: Player, timeout_happened):
            import random
            player.random_signal = random.choice(['yes', 'no'])
            print("Debug: Set player.random_signal =", player.random_signal)


page_sequence = [Introduction, feedback]
-----------------------------------------------
{% block title %}Elicitation3{% endblock %}

{% block content %}

    <p>
    {% if player.random_signal.field_maybe_none == "yes" %}
        Your actual performance was better than your previous guess.
    {% elif player.random_signal.field_maybe_none == "no" %}
        Your actual performance was not better than your previous guess.
    {% else %}
        Your actual performance information is not available at this moment.
    {% endif %}
    </p>
    
    <p>
      Please answer the following question.
    </p>

    {{ formfields }}

    {{ next_button }}

{% endblock %}
-----------------------------------------------

Can someone kindly help me please?

Write a reply

Set forum username