Commits

Richard Gerkin  committed a8e4922

Fixed open

  • Participants
  • Parent commits e989cce

Comments (0)

Files changed (1)

     SESTIMER = time.clock() #SESTIMER will be used as the reference for all timing events
     OUTDATAFILE = 'sample.txt' #Where the session data is written to. Need to add a function to ask for the name, location, ect later
     
-    while True:
-        runSession()
-
-            
-
+    runSession()
 
 def runSession():
     lickCounter = 0
     while True:
         SESTIMER = time.clock()
         for event in pygame.event.get(): #event handling loop
-
             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 event.type == QUIT: #this isn't working yet
                 #save data
                 terminate()
             elif event.type == KEYDOWN: #right now, responses are simulated by pressing "r" on the keyboard. This is a placeholder for the control board response
                 if (event.key == K_r):
-                    outText = 'respTime: ' + str(SESTIMER)
+                    outText = 'respTime: %s' % SESTIMER
                     writeData(OUTDATAFILE, outText)
-                    lickCountText = 'licks: ' + str(lickCounter) + ' at ' + str(SESTIMER) + '   next reinforcer at ' + str(reinforcerIntervalEndTime)
+                    lickCountText = 'licks: %s at %s; next reinforcer at %s.' \
+                                    % (lickCounter,SESTIMER,reinforcerIntervalEndTime)
                     print(lickCountText)
                     lickCounter += 1
                     contingencyVI(bReinforceOnLick)
-
                     if bReinforceOnLick == True:  #right now there's an error with reseting the Variable interval. Needs to be tracked down
                         bReinforcerOnLick = False
-                        bViStarted = False
-                    
+                        bViStarted = False 
                 elif (event.key == K_q and event.key == K_LCTRL):  #this isn't working yet
                     print('Response Q')
-                    terminate()
-                    
-
-
-        pygame.display.update() #updates teh display
+                    terminate()          
+        pygame.display.update() #updates the display
         gSessClock.tick(FPS)
-
-
         if SESTIMER > 100: #terminate the session after 100 seconds have passed (will change later)
             terminate()
         
-
-
 def writeData(fileName = 'default.txt', inputText = ''):
     if os.path.isfile(fileName) == False:
-        with open(fileName, 'w', encoding = 'utf-8') as dataOutFile:
+        with open(fileName, 'w') as dataOutFile:
             dataOutFile.write(inputText)
     else:
-        with open(fileName, 'a', encoding = 'utf-8') as dataOutFile:
+        with open(fileName, 'a') as dataOutFile:
             dataOutFile.write('\n')
             dataOutFile.write(inputText)