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'
    NUM_ROUNDS = 1

class Subsession(BaseSubsession):

class Group(BaseGroup):

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

        ''', min=0, max=100
class Introduction(Page):

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

        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 %}

    {% 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 %}
      Please answer the following question.

    {{ formfields }}

    {{ next_button }}

{% endblock %}

Can someone kindly help me please?

Write a reply

Set forum username