Commits

Richard Gerkin committed 461335c Merge

Preparing for QT

  • Participants
  • Parent commits 4cdb30c, 487528e

Comments (0)

Files changed (1)

 # Stage 1
 # By Ryan Brackney
 
+#Todo: Make ITI interval end check function, make sure it works. Adjust wrappers
+
 import pygame, os.path, sys, time, random
 from pygame.locals import *
 
 def runSession():
     lickCounter = 0
     lickFont = BASICFONT
-    bViStarted = False
+    bItiElapsed = False
     bReinforceOnLick = False
         
     while True:
         SESTIMER = time.clock()
         for event in pygame.event.get(): #event handling loop
+<<<<<<< local
             if bViStarted == False: #Determine if a the interval for the next reward delivery has been selected yet
                 intervalStartTime = SESTIMER
                 reinforcerIntervalEndTime = sampleFromVI(intervalStartTime)    #determine the next interval                       
                 bViStarted = True
             elif bViStarted == True and SESTIMER >= reinforcerIntervalEndTime:  #when that interval has elapsed, allow reinforcement
                 bReinforceOnLick = True
+=======
+
+##            if bViStarted == False: #Determine if a the interval for the next reward delivery has been selected yet
+##                intervalStartTime = SESTIMER
+##                reinforcerIntervalEndTime = sampleFromVI(intervalStartTime)    #determine the next interval                       
+##                bViStarted = True
+##            elif bViStarted == True and SESTIMER >= reinforcerIntervalEndTime:  #when that interval has elapsed, allow reinforcement
+##                bReinforceOnLick = True
+
+
+
+
+            if bItiElapsed == False
+                #just record responses
+                
+            elif bItiElapsed == True
+                #check to se if responses complete            
+                #reinforce, deliver 
+
+>>>>>>> other
             if event.type == QUIT: #this isn't working yet
                 #save data
                 terminate()
                                     % (lickCounter,SESTIMER,reinforcerIntervalEndTime)
                     print(lickCountText)
                     lickCounter += 1
+<<<<<<< local
                     contingencyVI(bReinforceOnLick)
+=======
+                    lickContingencyManagement(requiredLickInterval)
+
+                                        
+
+>>>>>>> other
                     if bReinforceOnLick == True:  #right now there's an error with reseting the Variable interval. Needs to be tracked down
                         bReinforcerOnLick = False
                         bViStarted = False 
                 elif (event.key == K_q and event.key == K_LCTRL):  #this isn't working yet
                     print('Response Q')
+<<<<<<< local
                     terminate()          
+=======
+                    terminate()
+                    
+
+
+>>>>>>> other
         pygame.display.update() #updates the display
         gSessClock.tick(FPS)
         if SESTIMER > 100: #terminate the session after 100 seconds have passed (will change later)
             terminate()
         
+<<<<<<< local
+=======
+
+
+
+
+
+>>>>>>> other
 def writeData(fileName = 'default.txt', inputText = ''):
     if os.path.isfile(fileName) == False:
         with open(fileName, 'w') as dataOutFile:
         pygame.display.update()
         gSessClock.tick(FPS)      
 
-def sampleFromVI(intervalStartTime): 
-    intervalList = [1,5,10,15,20,25,30] #placeholder interval list
-    intervalTime = random.sample(intervalList,1)
-    intervalEndTime = intervalStartTime + intervalTime[0]
-    return intervalEndTime
+##def sampleFromVI(intervalStartTime): 
+##    intervalList = [1,5,10,15,20,25,30] #placeholder interval list
+##    intervalTime = random.sample(intervalList,1)
+##    intervalEndTime = intervalStartTime + intervalTime[0]
+##    return intervalEndTime
 
-def contingencyVI(bReinforceOnLick):
-    if bReinforceOnLick == True:
-        print('water delivery!')
-        outText = 'reinfTime: ' + str(SESTIMER)
-        writeData(OUTDATAFILE, outText)
-        #code for water delivery here
+##def contingencyVI(bReinforceOnLick):
+##    if bReinforceOnLick == True:
+##        print('water delivery!')
+##        outText = 'reinfTime: ' + str(SESTIMER)
+##        writeData(OUTDATAFILE, outText)
+##        #code for water delivery here
+
+def deliverSr(): #deliver reinforcer stimulus (sr)
+    #placeholder for controller card activation
+    print('water delivery!')
+    outText = 'reinfTime: ' + str(SESTIMER)
+    writeData(OUTDATAFILE, outText)
+
+
+def getITI(stage)
+    #as with the BBC code, creates an ITI which advances in length as stage 1 training progresses
+    minIti = 1
+    #need code in here for a variable ITI type depending on part of stage 1 training we're in
+    listIti1 = [0,0.5, 1, 1.5, 2]
+    intervalTime = random.sample(intervalList,1) + minIti
+
+    return intervalTime
+
+
+
+
+def lickContingencyManagement(requiredLickInterval = 2) #requiredLickInterval is the number of seconds of straight licking required
+    withinLicks = 0 #number of licks emitted while in this loop
+    binCount = requiredLickInterval / 2 * 10 - 1 #space the bins by 0.2 s
+    startTime = time.clock() #or whatever function we need here for clock time
+    responseInBin = [0]*(binCount + 1);
+    responseInBin[0] = 1
+    bCompletedInterval = False
+    
+    while True
+        curTime = time.clock()
+        curBin = int((curTime - startTime) / 2 * 10)
+        if curBin > 0
+            if responseInBin[curBin - 1] == 0
+                break
+        if curBin > binCount:
+            bCompletedInterval = True
+            break
+        if event.type == KEYDOWN and event.key == K_r :
+            #right now, responses are simulated by pressing "r" on the keyboard. This is a placeholder for the control board response
+                responseInBin[curBin] = 1
+                
+        
+    withinLicks = sum(responseInBin)    
+    return withinLicks, bCompletedInterval 
+    
 
 def terminate():
     pygame.quit()