Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Variable sometimes not logged

I have this inline_script:

def my_form_validator():
    """Checks whether both the gender and age fields have been filled out"""
    #also checks for the number of characters
    return var.sex != u'no' and var.byear != u'' and var.bmonth != u'' and var.bday != u'' and len(str(var.byear))==4 and len(str(var.bmonth)) in [1,2] and len(str(var.bday)) in [1,2]

def filter_digits(ch):

    """Allows only digit characters as input"""

    return ch in ['0','1','2','3','4','5','6','7','8','9','backspace']

# Define all widgets
button_ok = Button(text=u'Ok')
#label_gender= Label(u'Your gender')
checkbox_male = Checkbox(text=u'Maennlich', group=u'sex', var=u'sex')
checkbox_female = Checkbox(text=u'Weiblich', group=u'sex', var=u'sex')
label_age = Label(u'Bitte geben Sie Ihr Geburtsdatum ein')
label_year = Label(u'Jahr')
label_month = Label(u'Monat')
label_day = Label(u'Tag')
# Specify a key filter so that only digits are accepted as text input
input_year  = TextInput(stub=u'JJJJ', var=u'byear',  key_filter=filter_digits) #actually a selection thing would be nice
input_month = TextInput(stub=u'MM',   var=u'bmonth', key_filter=filter_digits)
input_day   = TextInput(stub=u'TT',   var=u'bday',   key_filter=filter_digits)

# Build the form. Specify a validator function to make sure that the form is
# completed.
my_form = Form( validator=my_form_validator, cols=3, rows=[3,1,1,1,1,1,1,1,1,3], spacing=10, margins=(100, 100, 100, 100),  )
#my_form.set_widget(label_gender, (0, 0))
my_form.set_widget(checkbox_male,   (1, 2))
my_form.set_widget(checkbox_female, (2, 2))
my_form.set_widget(label_age,   (1, 3))

my_form.set_widget(label_day,   (0, 4))
my_form.set_widget(label_month, (0, 5))
my_form.set_widget(label_year,  (0, 6))
my_form.set_widget(input_day,   (1, 4), colspan=2)
my_form.set_widget(input_month, (1, 5), colspan=2)
my_form.set_widget(input_year,  (1, 6), colspan=2)
my_form.set_widget(button_ok,   (1, 7))
my_form._exec()

# Calculate age from current time and Birtdate
import shutil,os,datetime

now = datetime.datetime.now()
current_year  = now.strftime("%Y")
current_month = now.strftime("%m")
current_day   = now.strftime("%d")
#current_time = now.strftime("%Y-%m-%d")

years  = int(current_year) - var.byear
months = int(current_month) - var.bmonth
days   = int(current_day) - var.bday

var.age= years + float(months)/12 + float(days)/365
var.Bday = str(var.byear)+'.'+str(var.bmonth)+'.'+str(var.bday)
var.Sex=str(var.sex)
print var.age, var.Bday
log.write_vars()

Mostly the variable sex is logged. But sometimes it is not. I have no clue about why it is sometimes not logged. And i cannot reproduce the behavior. It seems like random.
Could it have to do with garbage collection? Other ideas?
I tried full screen and quick run. In both it usually logs. But sometimes not.

Comments

  • Hi Stephan,

    What do you mean with sometimes? Some trials in one session, or some session? So, if you hit the RUN button will it either log everything (usually) or nothing (sometimes), or will it log some trials but not others?

    Eduard

  • Hi eduard,

    it is just in some sessions. If i repeat the session the variable usually appears in the inspector (and the logfile).
    The variable 'sex' is only coded once, so there is only one trial. It is logged at the same time as the birthday variables (which always appear in the inspector/output).

    You see that i tried a workaround with var.Sex=str(var.sex), which unfortunately does not really help.
    What i noticed is the following: Sex is always in the variable inspector. However, sometimes its values remain empty (and in those cases sex does not appear in the variable inspector).

    What's the meaning of the 'u' in var=u'sex'? Could it have to do with that?
    It is so strange, because if the variable is not filled the experiment should not go on (see my_form_validator), however it always does. So there must be a value for sex, but the variable gets lost on the way (somewhere)...

  • How often does that happen? I just tried it 10 times and it always worked. I used the expyriment backend and the quickrun button on a linux machine.

  • Hi eduard,

    I just replicated the error on the second run (new day, same problem). Yesterday i also made like 10 runs, where it worked. I cannot say how often it occurs.

    I am using Win7, expyriment backend. The error also occured on Mac.

    Maybe it has to do with the rest of my experiment? Can I send you the whole experiment privately somewhere?

  • edited August 2018

    I shortened the script a little:

    button_ok = Button(text=u'Ok')
    #label_gender= Label(u'Your gender')
    checkbox_male = Checkbox(text=u'Maennlich', group=u'sex', var=u'sex')
    checkbox_female = Checkbox(text=u'Weiblich', group=u'sex', var=u'sex')
    
    # Build the form. Specify a validator function to make sure that the form is
    # completed.
    my_form = Form( cols=3, rows=[3,1,1,1,1,1,1,1,1,3], spacing=10, margins=(100, 100, 100, 100),   )
    #my_form.set_widget(label_gender, (0, 0))
    my_form.set_widget(checkbox_male,   (1, 2))
    my_form.set_widget(checkbox_female, (2, 2))
    
    my_form.set_widget(button_ok,   (1, 3), colspan=2)
    my_form._exec()
    
    var.Sex=str(var.sex)
    log.write_vars()
    

    What i know for now:
    -the form_validator is not the problem
    -it is definitely the checkbox widget (if it occurs in one checkbox widget, the problem appears in another checkbox widget too)
    -most variables appear at the start of the experiment in the inspector, however the checkbox variables appear on presentation of the widget (which takes some miliseconds to appear in the inspector). But in some cases (don't know why nor when), the variables do not appear. Even if they do not appear in the inspector, they are somewhere, because they do work in the form_validator --> the experiment goes on.

  • Update:
    Actually, my workaround with the copy of the variable helped. Although not visible in the inspector, the values of the new variable Sex are logged in the logfile. However, the old variable sex is not in the logfile. Seems like a temporary variable, which surprises me, because in the form_validator i draw on it with var.sex and not with sex.

    Maybe it has to do with the group definition?

  • Honestly, I have no idea. I tried it now close to 20 times and the variable is always present. Maybe it has to do with the Operating System?

    Anyway, if this work around works for you, that that's good I guess. If you feel like it, It'd be cool if you could do some more testing, try to further hone in on the problem and eventually submit a bug report on github.

    Thanks,
    Eduard

  • Possibly, it had to do with the operating system. Actually, it was never present on a certain MacBook. And there it never appeared in the logfile. However, i want to be independent from operating systems (one of the strengths of OS!) using participants notebooks.
    Now i solved it by changing the OpenSesameVar to a PythonVar, and then back again. :blush:

    sex=var.sex (var.sex was defined in the checkbox, but not logged)
    var.Sex=sex (var.Sex is now always logged)
    
Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games