Пример #1
0
def learn(var,doo,myPoints,dbc,mouse): # main function of the learning stages for returning subjects
    fc.setpath() # set up directory
   #------------participant info collecting------------------------
    setup.dataCollectGui()
    var.expInfo = setup.username()
    gc.enable()
    #-------------database setup ------------------------------------
    fN = os.path.basename(__file__)
    p_num, expD, st, expN, host_ip,p_net = fc.get_netid(var,doo,dbc,fN)
    setiddtb,var = fc.initialSetup(var,dbc)
    #--------------------data start write-----------------------------
    sql.w_before_learning(dbc,p_num, expD, st, expN, host_ip, setiddtb)
    var.sessid = sql.r_lastID(dbc)


    # go through all stages and record number of coins earned and trials done in each stage
    # 4 correct trials in a roll can pass each stage

    var = stage0.stage0(var.sessid,var,doo,myPoints,dbc,mouse)
    Points0,trials0 = fc.total_Points_trialCounter(var)
    fc.reset_Points_trialCounter(var)


    var = stage1.stage1(var.sessid,var,doo,myPoints,dbc,mouse)
    Points1,trials1 = fc.total_Points_trialCounter(var)
    fc.reset_Points_trialCounter(var)

    var = stage2.stage2(var.sessid,var,doo,myPoints,dbc,mouse)
    Points2,trials2 = fc.total_Points_trialCounter(var)
    fc.reset_Points_trialCounter(var)

    var = stage3.stage3(var.sessid,var,doo,myPoints,dbc,mouse)
    Points3,trials3 = fc.total_Points_trialCounter(var)
    fc.reset_Points_trialCounter(var)

    var = stage4.stage4(var.sessid,var,doo,myPoints,dbc,mouse) 
    Points4,trials4 = fc.total_Points_trialCounter(var)
    fc.reset_Points_trialCounter(var)

    var = stage5.stage5(var.sessid,var,doo,myPoints,dbc,mouse) 
    Points5,trials5 = fc.total_Points_trialCounter(var)
    fc.reset_Points_trialCounter(var)

    LearningStageTotalPoints = Points0+Points1+Points2+Points3+Points4+Points5
    ttrials = trials0+trials1+trials2+trials3+trials4+trials5

    fc.show_bigCoins_total(LearningStageTotalPoints,myPoints) # show the total profits to the subjects
    fc.end_instruction(doo) # give the ending instruciton to the subject
    et = datetime.datetime.now() # record end time
    sql.w_after_learningALL(dbc,var,p_num, expD, et, expN, host_ip, ttrials, LearningStageTotalPoints, setiddtb) # save data of this session in database
    return p_net
Пример #2
0
def MixNonverbal_r(var, doo, myPoints, dbc, mouse, getName=True, sub_id=None):
    var.stg = 6  # specify stage number ( assign stage #6 for mixnonverbal)
    fc.setpath()  # set up directory
    fN = os.path.basename(__file__)  # get expName of this file
    expName, extN = os.path.splitext(fN)  # get expName and extN
    expDate = datetime.datetime.now().strftime(
        "%Y-%m-%d_T%H_%M_%S")  # get stageName
    sessid, p_num, p_net, setiddtb, host_ip, var, dbc = fc.exp_setup(
        var, doo, dbc, getName, sub_id, expName,
        expDate)  # database setup and data start recording
    setupList = fc.nonverbalSetup(
        var.nonverbalTotalTrial_r, var.mag, var.shortmag
    )  # setup the reward of blocks for the whole experiment(same as in nonverbal)
    shuffledSetupList = copy.copy(setupList)  # shuffle the reward list
    random.shuffle(shuffledSetupList)  # show subjects stage name (short delay)
    for i in range(
            len(shuffledSetupList)):  # apply a reward mag for each block
        var.blockRewMag = shuffledSetupList[i][
            0]  # assign reward mag for this block
        var.blockName = i + 1  # assign blockName
        var = fc.instruction(var, doo)  # show block instruction to the subject
        while var.blockTrialCounter < shuffledSetupList[i][
                1]:  # run pre-determined number of trials in each block
            var.rewmag = var.blockRewMag  # assign reward mag
            if not var.sameInitPos:  # get a new setup if no violation made in the last trial
                fc.getInitPos(var)
                fc.getFixmag(var)
                fc.getBluePos(var)
                var = fc.symmetricYBPair(var)  # gets symmetric yellow position
                fc.getDelayTime(var)
            var, doo, myPoints = fc.draw_initCircle(
                var, doo, myPoints)  # start the first state
            while var.state != 'none':  # go through all connected states in one trial
                mouse.clickReset()
                var, doo, myPoints = fc.funcDic[var.state](var, doo, myPoints)
            fc.dataRecord_mixNon(var, dbc, sessid)  # record data
            if fc.again_or_next(var) == 'again':  # if any violations made
                var.trialCounter += 1  # plus 1 in trialCounter
                var.totalTrialCounter += 1  # not in used here
                var.mergedTrialCounter += 1  # not in used here
                var.sameInitPos = True  # next trial will use the same init position
                var.fixation_clicks = [
                ]  # reset fixation_clicks(records the clicks during fixation) list
                var.reward_clicks = [
                ]  # reset reward_clicks(records the clicks during reward) list
                var.delay_clicks = [
                ]  # reset delay_clicks(records the clicks during delay waiting time) list
                continue  # start over the same trial
            else:  # if no violation made
                var.trialCounter += 1  # plus 1 in trialCounter (total trial num)
                var.blockTrialCounter += 1  # plus 1 in blockTrialCounter (trial num in current block)
                var.fixation_clicks = []  # reset fixation_clicks record list
                var.reward_clicks = []  # reset reward_clicks record list
                var.delay_clicks = [
                ]  # reset delay_clicks(records the clicks during delay waiting time) list
        var.blockTrialCounter = 0  # reset blockTrialCounter to 0 for next block
    fc.show_bigCoins(var, myPoints)  # show the total profits to the subjects
    var.dataFile.close()  # close the data file
    fc.end_instruction_mixNon(
        doo)  # give the ending instruciton to the subject
    endt = datetime.datetime.now()  # record end time

    sql.w_after_mixNonALL(
        dbc, var, sessid, p_num, expDate, endt, expName, host_ip,
        setiddtb)  # save the data of this session to database
Пример #3
0
def LongVerbal(var,
               doo,
               myPoints,
               dbc,
               mouse,
               getName=True,
               sub_id=None,
               pre_points=0,
               gettrialn=0,
               pre_trials=0):
    var.trialCounter = pre_trials
    var.rewardGot = gettrialn
    var.points = pre_points  # if it's the second long verbal session in the experiment, points are accumulated from the first long verbal session
    var.longVerbal = True  # specify long verbal for specific functions
    fc.setpath()  # set up directory
    fN = os.path.basename(__file__)  # get expName of this file
    expName, extN = os.path.splitext(fN)  # get expName and extN
    stageName = expName[:-7]  # get stageName
    expDate = datetime.datetime.now().strftime(
        "%Y-%m-%dT%H_%M_%S")  # get expDate
    sessid, p_num, p_net, setiddtb, host_ip, var, dbc = fc.exp_setup(
        var, doo, dbc, getName, sub_id, expName,
        expDate)  # database setup and data start recording
    var.pay = fc.paymentSelection(
        var.verbalTotalTrial
    ) + gettrialn  # select one trial(number) to actually pay the subject
    setupList = fc.verbalSetup(
        var.verbalTotalTrial, var.mag,
        var.shortmag)  # setup the reward of blocks for the whole experiment
    shuffledSetupList = copy.copy(setupList)  # shuffle the reward list
    random.shuffle(shuffledSetupList)
    fc.stage_instruction(stageName, var,
                         doo)  # show subjects stage name (long delay)
    for i in range(
            len(shuffledSetupList)):  # apply a reward mag for each block
        var.blockRewMag = shuffledSetupList[i][
            0]  # assign reward mag for this block
        var.blockName = i + 1  # assign blockName
        var.rewmag = var.blockRewMag  # assign reward mag
        fc.block_instruction(var, doo)  # show block instruction to the subject
        while var.blockTrialCounter < shuffledSetupList[i][
                1]:  # run pre-determined number of trials in each block
            #if not var.sameInitPos: # get a new setup if no violation made in the last trial
            var = fc.new_trial_setup(var)
            var, doo, myPoints = fc.draw_init(
                var, doo, myPoints)  # start the first state
            while var.state != 'none':  # go through all connected states in one trial
                #mouse.clickReset()
                var, doo, myPoints = fc.funcDic[var.state](var, doo, myPoints)
            if fc.again_or_next(var) == 'again':  # if any violations made
                var.trialCounter += 1  # plus 1 in trialCounter
                var.sameInitPos = True  # next trial will use the same init position
                var.reward_clicks = [
                ]  # reset reward_clicks(records the clicks during reward) list
                var.delay_clicks = [
                ]  # reset delay_clicks(records the clicks during delay waiting time) list
                again = True
            else:  # if no violation made
                var.rewardGot += 1  # plus 1 in rewardGot
                var.trialCounter += 1  # plus 1 in trialCounter (total trial num)
                var.blockTrialCounter += 1  # plus 1 in blockTrialCounter (trial num in current block)
                var.pairNum += 1  # proceed to next pair
                var.reward_clicks = []  # reset reward_clicks record list
                var.delay_clicks = [
                ]  # reset delay_clicks(records the clicks during delay waiting time) list
                again = False
            if var.rewardGot == var.pay and again == False:  # assign pay_delay and pay_num if the current trial is the one picked to be actually paid
                if var.choice != 'b':
                    var.pay_delay = var.delaymag
                else:
                    var.pay_delay = var.shortdelay
                var.pay_num = var.rewmag
            fc.dataRecord_longVerbal(var, dbc,
                                     sessid)  # record data for this trial
            fc.resetVar(var, again)
        var.blockTrialCounter = 0  # reset blockTrialCounter
    var.dataFile.close()  # close the data file
    var.longVerbal = False  # reset longVerbal boolean to be False
    endt = datetime.datetime.now()  # record end time
    sql.w_after_Verbal(dbc, var, sessid, p_num, expDate, endt, expName,
                       host_ip,
                       setiddtb)  # save data of this session in database
    return p_net, var.pay, var.pay_delay, var.pay_num, var.trialCounter, var.points,
Пример #4
0
def ShortVerbal(var,
                doo,
                myPoints,
                dbc,
                mouse,
                getName=True,
                sub_id=None,
                pre_points=0,
                pre_trials=0,
                pre_trialsCorrect=0):
    var.rewardGot = pre_trialsCorrect  # if it's the second short verbal session in the experiment, rewardGot is accumulated from the first short verbal session
    var.trialCounter = pre_trials  # if it's the second short verbal session in the experiment, trialCounter is accumulated from the first short verbal session
    var.points = pre_points  # if it's the second short verbal session in the experiment, points are accumulated from the first short verbal session
    var.shortVerbal = True  # specify short verbal for specific functions
    fc.setpath()  # set up directory
    fN = os.path.basename(__file__)  # get expName of this file
    expName, extN = os.path.splitext(fN)  # get expName and extN
    stageName = expName[:-7]  # get stageName
    expDate = datetime.datetime.now().strftime(
        "%Y-%m-%d_T%H_%M_%S")  # get expDate
    sessid, p_num, p_net, setiddtb, host_ip, var, dbc = fc.exp_setup(
        var, doo, dbc, getName, sub_id, expName,
        expDate)  # database setup and data start recording
    setupList = fc.verbalSetup(
        var.verbalTotalTrial, var.mag, var.shortmag
    )  # setup the reward of blocks for the whole experiment(same as in nonverbal)
    shuffledSetupList = copy.copy(setupList)  # shuffle the reward list
    random.shuffle(shuffledSetupList)
    fc.stage_instruction(stageName, var,
                         doo)  # show subjects stage name (short delay)
    for i in range(
            len(shuffledSetupList)):  # apply a reward mag for each block
        var.blockRewMag = shuffledSetupList[i][
            0]  # assign reward mag for this block
        var.blockName = i + 1  # assign blockName
        fc.block_instruction(var, doo)  # show block instruction to the subject
        while var.blockTrialCounter < shuffledSetupList[i][
                1]:  # run pre-determined number of trials in each block
            var.rewmag = var.blockRewMag  # assign reward mag
            if not var.sameInitPos:  # get a new setup if no violation made in the last trial
                fc.getInitPos(var)
                fc.getFixmag(var)
                fc.getBluePos(var)
                var = fc.symmetricYBPair(var)
                fc.getDelayTime(var)
            var, doo, myPoints = fc.draw_initCircle(
                var, doo, myPoints)  # start the first state
            while var.state != 'none':  # go through all connected states in one trial
                mouse.clickReset()
                var, doo, myPoints = fc.funcDic[var.state](var, doo, myPoints)
            if fc.again_or_next(var) == 'again':  # if any violations made
                var.trialCounter += 1  # plus 1 in trialCounter
                var.sameInitPos = True  # next trial will use the same init position
                var.fixation_clicks = [
                ]  # reset fixation_clicks(records the clicks during fixation) list
                var.reward_clicks = [
                ]  # reset reward_clicks(records the clicks during reward) list
                var.delay_clicks = [
                ]  # reset delay_clicks(records the clicks during delay waiting time) list
                again = True
            else:  # if no violation made
                var.trialCounter += 1  # plus 1 in trialCounter (total trial num)
                var.blockTrialCounter += 1  # plus 1 in blockTrialCounter (trial num in current block)
                var.fixation_clicks = []  # reset fixation_clicks record list
                var.reward_clicks = []  # reset reward_clicks record list
                var.delay_clicks = [
                ]  # reset delay_clicks(records the clicks during delay waiting time) list
                again = False
            fc.dataRecord_shortVerbal(var, dbc,
                                      sessid)  # record the data for this trial
            fc.resetVar(var, again)
        var.blockTrialCounter = 0  # reset blockTrialCounter
    fc.show_bigCoins(var, myPoints)  # show the total profits to the subjects
    var.dataFile.close()  # close the data file
    var.shortVerbal = False  # reset shortVerbal boolean to be False
    endt = datetime.datetime.now()  # record end time
    sql.w_after_Verbal(dbc, var, sessid, p_num, expDate, endt, expName,
                       host_ip,
                       setiddtb)  # save data of this session in database
    return p_net, var.points, var.trialCounter, var.rewardGot