简体   繁体   English

oTree Studio:为实验中的不同参与者显示不同的表单字段

[英]oTree Studio: display form fields differently for different participants in the experiment

I am new to oTree and oTree Studio , so I apologise in advance if my question doesn't make much sense.我是oTreeoTree Studio的新手,所以如果我的问题没有多大意义,我提前道歉。 I am also new to Stack Overflow, so I apologise if I am duplicate a question.我也是 Stack Overflow 的新手,所以如果我重复了一个问题,我深表歉意。

I am writing an application for a lab experiment using oTree Studio.我正在使用 oTree Studio 为实验室实验编写应用程序。 During that experiment, participants are given a series of “opportunities” to exchange resources in the form of “points” having monetary value.在该实验中,参与者获得了一系列“机会”,以具有货币价值的“点”的形式交换资源。 The opportunities are organised into rounds and, in a given round, each participant can share her resources with up to 2 other participants .机会分为几轮,在给定的一轮中,每个参与者可以与最多 2 个其他参与者共享她的资源。 Importantly, a participant cannot transfer her resources to herself;重要的是,参与者不能将她的资源转移给自己; the resources can only be transferred to another participant.资源只能转移给另一个参与者。

Now, in each round, all the participants in the experiment, except for the given one, are listed on the screen.现在,在每一轮中,实验中的所有参与者,除了给定的一个,都列在屏幕上。 The participant is then asked, for each of the other subjects, if she wants to transfer her resources to that participant.然后针对其他每个主题询问参与者是否想将她的资源转移给该参与者。 To that end, I have created an integer field form for each participant which takes value of 1 if the participant transfers her resources to the particular recipient and 0 (the default value) otherwise.为此,我为每个参与者创建了一个 integer 字段表单,如果参与者将她的资源转移给特定的接收者,则其值为 1,否则为 0(默认值)。 The point is that the form field corresponding to the given actor is hidden to keep the participant from transferring the resources to herself.关键是与给定参与者对应的表单字段是隐藏的,以防止参与者将资源转移给自己。 I did it as follows:我这样做如下:

{% if player.id_in_group != 1 %} {% formfield player.ile1 %} {% else %}     {% endif %}

The problem, however, is that once the participants completes the screen and clicks on “Next”, an error message is displayed saying然而,问题是,一旦参与者完成屏幕并单击“下一步”,就会显示一条错误消息说

Please fix the errors in the form.请更正表格中的错误。

One can try to avoid the problem by allowing “empty” forms, so that the hidden form field corresponding to the given participant can be left unfilled.可以尝试通过允许“空” forms 来避免该问题,这样与给定参与者对应的隐藏表单字段可以不填写。 But then I cannot impose additional restrictions, such as limiting the number of potential recipients to 2. I mean I have defined the following error message for participants:但是我不能施加额外的限制,例如将潜在收件人的数量限制为 2。我的意思是我已经为参与者定义了以下错误消息:

if values['ile1'] + values['ile2'] + ... > 2: return 'The maximum number of recipients exceeded.'

But then the application fails and displays an error message saying但随后应用程序失败并显示一条错误消息说

unsupported operand type(s) for +: 'NoneType' and 'int' + 不支持的操作数类型:“NoneType”和“int”

So, I guess, what I am looking for is a way to combine these two things: (a) allowing for the form fields to be left unfilled and, at the same time, (b) applying a restriction on the maximum number of recipients.所以,我想,我正在寻找一种将这两件事结合起来的方法:(a)允许表单字段不填写,同时,(b)对收件人的最大数量施加限制. Does anybody know how to do this?有人知道怎么做这个吗?

Use get_form_fields to show different fields depending on self.player.id_in_group: https://otree.readthedocs.io/en/latest/forms.html#determining-form-fields-dynamically使用 get_form_fields 根据 self.player.id_in_group 显示不同的字段: https://otree.readthedocs.io/en/latest/forms.html#determining-form-fields-dynamically

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM