Howdy, Stranger!

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

Supported by

[open] Need help displaying performance after block trial loop

edited February 2015 in OpenSesame

I will paste the experiment section of the code below so that you can get a better idea, but we think that there is an issue with the scope of our variables. At the end of a block trial, we want to show the participant the percentage of correct responses. However, when the percentage function comes up on screen it only shows 1 of 2 different percentages-- it either gives us 100 percent if the trials were all completed correctly, or 0 percent if any referrals (space) or wrong choices were made, even if there were some correct responses. The task is to judge whether the presented field of asterisks is from a high or low distribution. We tried globalizing everything, and it looks a bit messy, but it did not work. Anyway, help is greatly appreciated! Here is the code:

#Initializing Starting Points
import random 

random.shuffle(lo_stim)
random.shuffle(hi_stim)

vv=0
ww=0

global total_correct
total_correct=0
global total
total=0
global total_referrals
total_referrals=0

#Keyboard Import
from openexp.keyboard import keyboard
kb=keyboard(exp, keylist=['z', '/', 'space'], timeout=2000)
kb.get_key()
kb.flush()

#Defining percentage correct and showing participant
def percentage_correct():
    global total_referrals
    global total_correct
    global total
    diagnosis_rate=int((total_correct/total)*100)
    from openexp.canvas import canvas
    my_canvas = canvas(exp)
    my_canvas.text('Correct Diagnosis Rate: '+str(diagnosis_rate)+' %')
    my_canvas.show()
    self.sleep(3000)

#Defining correct/incorrect/referral stimulus function
def correct_kp():
    global total_correct
    total_correct+=1
    global total
    total+=1
    from openexp.canvas import canvas
    my_canvas = canvas(exp)
    my_canvas.text('Patient Diagnosed Correctly!')
    my_canvas.show()
    self.sleep(500)


def incorrect_kp():
    global total
    total+=1
    from openexp.canvas import canvas
    my_canvas = canvas(exp)
    my_canvas.text('Patient Misdiagnosed.')
    my_canvas.show()
    self.sleep(1000)


def referral():
    global total_referrals
    total_referrals+=1
    global total
    total+=1
    from openexp.canvas import canvas
    my_canvas = canvas(exp)
    my_canvas.text('Patient Referred.')
    my_canvas.show()
    self.sleep(500)


#Low vs High Mean Selection
for i in range(num_blocks):
    global total_correct
    global total
    global total_referrals
    for j in range(trials_per_block):
        random.shuffle(general_binary)
        payoff_hi_yn=general_binary[1]
        random.shuffle(general_binary)
        process_hi_yn=general_binary[1]
        kb.flush()
        global total_correct
        global total
        global total_referrals

        #Low Mean Process
        if process_hi_yn==0:
            v=0+vv
            vv=v+1
            stim_num=vv
            global total_correct
            global total
            global total_referrals

            #Path to select .png file 
            from openexp.canvas import canvas
            my_canvas=canvas(exp)
            path=exp.get_file(u'stim_'+str(general_binary[1])+'_'+str(lo_stim[vv])+'.png')
            stim_start=self.time()
            my_canvas.image(path)
            my_canvas.prepare()
            my_canvas.show()

            #key press response time
            key, time = kb.get_key()
            response_time=time-stim_start

            #Correct/Incorrect key press (Low mean)
            if key=='z':
                global total 
                global total_correct
                correct_kp()
            elif key=='/':
                global total 
                incorrect_kp()  
            elif key=='space':
                global total
                global total_referrals 
                referral()  

            #Log info--> trial number, block number, stimulus number, high vs low mean, response, response time
            log_text=str(j+1)+','+str(i+1)+','+str(stim_num)+','+str(process_hi_yn)+','+str(key)+','+str(response_time)
            self.log(log_text)

            #Clears canvas
            my_canvas.clear()
            my_canvas.prepare()
            my_canvas.show()
            self.sleep(2000)

        #High Mean Process          
        elif process_hi_yn==1:
            w=0+ww
            ww=w+1
            stim_num=ww
            global total_correct
            global total
            global total_referrals

            #Path to select .png file
            from openexp.canvas import canvas
            my_canvas=canvas(exp)
            path=exp.get_file(u'stim_'+str(general_binary[1])+'_'+str(hi_stim[ww])+'.png')
            stim_start=self.time()
            my_canvas.image(path)
            my_canvas.prepare()
            my_canvas.show()

            #key press response time
            key, time = kb.get_key()
            response_time=time-stim_start

            #Correct/Incorrect key press (high mean)    
            if key=='z':
                global total
                incorrect_kp()
            elif key=='/':
                global total 
                global total_correct
                correct_kp()
            elif key=='space':
                global total
                global total_referrals
                referral()  

            #Log info--> trial number, block number, stimulus number, high vs low mean, response, response time
            log_text=str(j+1)+','+str(i+1)+','+str(stim_num)+','+str(process_hi_yn)+','+str(key)+','+str(response_time)
            self.log(log_text)

            #Clears canvas
            my_canvas.clear()
            my_canvas.prepare()
            my_canvas.show()
            self.sleep(2000)
#Calling percentage function    
percentage_correct()    

Comments

  • edited 1:57AM

    Hi,

    The problem is that you're using int division to determine the accuracy. int division always rounds down, so if you have some intermediate result (proportion correct in your case) that is less than 1 it will always become 0.

    Let's say that you have 5 out of 10 correct response:

    print(5/10) # Prints 0
    print((5/10)*100) # Prints 0
    

    The trick is to convert at least one number to a float, like so:

    print(float(5)/10) # Prints .5
    print((float(5)/10)*100) # Prints 50.0
    

    Cheers!
    Sebastiaan

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