Issues with bots

93 views
Skip to first unread message

Inbal

unread,
Jul 19, 2021, 2:09:57 PM7/19/21
to oTree help & discussion

Hi everyone,

I'm trying to write bots for my app, but run into two issues:

* There are pages whose execution depends on a few constants. They work fine when I'm testing the app by myself, but when I try running bots with the same if statements, I get an error message that the bot expected to be on another page.

* How can I define dead-ends for bots? (e.g., some participants are screened out because of full quotas or wrong answers to attention checks, so I want bots simulating those participants to remain on pages that don't have a next button)

 

Best,

Inbal 

Chris @ oTree

unread,
Jul 19, 2021, 2:53:00 PM7/19/21
to oTree help & discussion
On Monday, July 19, 2021 at 12:09:57 PM UTC-6 Inbal wrote:

Hi everyone,

I'm trying to write bots for my app, but run into two issues:

* There are pages whose execution depends on a few constants. They work fine when I'm testing the app by myself, but when I try running bots with the same if statements, I get an error message that the bot expected to be on another page.

This is working fine on my end; many of the sample games have bots that use if-statements also: https://github.com/oTree-org/otree
Can you provide some minimal sample code that reproduces the issue?

* How can I define dead-ends for bots? (e.g., some participants are screened out because of full quotas or wrong answers to attention checks, so I want bots simulating those participants to remain on pages that don't have a next button)

In subsequent apps, you should use an if-statement that depends on whether they were screened out (using the participant field you define yourself):

if not self.participant.screened_out:
  yield Page1
  yield Page2
  # etc...
 

 

Best,

Inbal 

Inbal

unread,
Jul 19, 2021, 3:06:37 PM7/19/21
to oTree help & discussion

Thanks Chris!

Sure.

On pages I have:


class Policy_Choice_No_Social_Info(Page):
    def is_displayed(self):
        return self.player.is_policy_choice==1 and (Constants.pre_survey == True or self.player.is_control == True)

    form_model = 'player'
   
form_fields = ['policy_choice']


class Policy_Choice(Page):
    def is_displayed(self):
        return self.player.is_policy_choice==1 and Constants.pre_survey == False and self.player.is_control == False # display this page at policy choice rounds, when there is social info

   
form_model = 'player'
   
form_fields = ['policy_choice']

 

So in tests I define accordingly:

# Policy Choice No Social Info

if self.player.is_policy_choice == 1 and (Constants.pre_survey == True or self.player.is_control == True):
    my_policy_choice = random.randint(0,1)
    yield Submission(pages.Policy_Choice_No_Social_Info, dict(policy_choice=my_policy_choice), check_html=False) # this disables the HTML check on the page, as there is a button added dynamically with JavaScript

# Policy Choice:

if self.player.is_policy_choice == 1 and Constants.pre_survey == False and self.player.is_control == False:
    my_policy_choice = random.randint(0, 1)
    yield Submission(pages.Policy_Choice_No_Social_Info, dict(policy_choice=my_policy_choice), check_html=False) # this disables the HTML check on the page, as there is a button added dynamically with JavaScript

 

Thank you!

Best,

Inbal 

Chris @ oTree

unread,
Jul 19, 2021, 3:11:48 PM7/19/21
to oTree help & discussion
Both of those yield statements submit  Policy_Choice_No_Social_Info...

ענבל דקל

unread,
Jul 19, 2021, 3:58:00 PM7/19/21
to Chris @ oTree, oTree help & discussion

Thank you, Chris!!

Another question: I want to allow a bot to respond with None to a form field, so I tried:

if self.player.is_policy_choice == 0 and self.round_number == self.participant.vars['task_choice_round_indices'][0]:
    my_attention_a = random.randint(
0, 7)
    my_attention_b =
''.join(random.choices(string.ascii_letters + string.digits + string.punctuation, k=3))
   
if self.player.id_in_group == 2:
       
# testing several cases of wrong answers to attention checks
       
attention_a = {
           
'wrong_random_number': my_attention_a,
           
'blank': None
       
}[self.case]
        attention_b = {
           
'wrong_random_string': my_attention_b,
           
'blank': None
       
}[self.case]

       
yield pages.Part_B, dict(attention_check_a=attention_a, attention_check_b=attention_b)

 

elif self.player.id_in_group > 2:
   
yield pages.Part_B, dict(attention_check_a=None, attention_check_b="כן")

 

But that gives me a "KeyError None" message for the bot whose id_in_group is 2.

How can I solve this?

Best,

Inbal


--
You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/bKgNCGeocRI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/bef6127d-f09c-498a-9649-3647c1f9b8b2n%40googlegroups.com.

Chris @ oTree

unread,
Jul 19, 2021, 4:06:11 PM7/19/21
to oTree help & discussion
Rather than submitting None, just try omitting that key altogether. Otherwise, please show the traceback of that KeyError.

ענבל דקל

unread,
Jul 20, 2021, 2:46:03 PM7/20/21
to Chris @ oTree, oTree help & discussion
Thanks, Chris! I removed it from 'cases' and then it worked fine.
Best,
Inbal

Reply all
Reply to author
Forward
0 new messages