Commits

Anonymous committed 1e1c6f6

try again...

Comments (0)

Files changed (4)

Discrimination2.py

         #self.trialLengthByBlock = [1.2]
         self.blockCount = self.trialLengthByBlock.__len__()
               #this should start short and get longer first
+        self.trialListInBlock = [0,1,0,1,0,1]
         self.curBlockHits = 0 #met the interval threshold
         self.curBlockMisses = 0 #missed the interval threshold
         self.curBlockAbstain = 0 #made the interval but didn't lick
         self.bReinforcement = False
         self.bReinforcementAvailable = False
         self.bItiReady = True
-        self.csPlusValve = 1             
+        self.csPlusValve = 1
+        self.csMinusValve = 2
         #assert self.itiTime.__len__() == self.trialLengthByBlock.__len__()
         
         
+    
+    def determineTrialOrderWithinBlock(self):
+        '''
+        Trials here are divided into '1' and '0', where 
+        1 trials are S+
+        0 trials are S-
+        '''
+        if self.curBlock == 1:
+            trialListInBlock = 10 * [1]
+        else:
+            pass               
         
+        
+        return trialListInBlock
+    
     def update(self):
         self.updateInputs()
         
             self.endIti()
             self.curState = 1
             
+
+            
     def updateState1(self):
         #start of trial, wait for a head entry
         #print('state1 start')
             
         if self.statesStarted[self.curState] == True and self.bHeadIn == True:
             self.curState = 2
+
+
+    def updateState2(self):
+        #turn on final valve and CS valve for 1 sec
+        if self.statesStarted[self.curState] == False:
+            self.statesStarted[self.curState] = True
+            self.determineTrialType()
+            self.finalValveOn()
+            self.valveOn(self.curValve)
+            self.valveTimer = RunIntervalTimer(1)
+        if self.valveTimer.countDownComplete():
+            self.finalValveOff()
+            del self.valveTimer
+            self.curState = 3
             
+    
+    def updateState3(self):
+        #after 2.5 s, turn off the CS valve
+        if self.statesStarted[self.curState] == False:
+            self.statesStarted[self.curState] = True
+            self.valveTimer = RunIntervalTimer(2.5)
+        if self.valveTimer.countDownComplete():
+            self.valveOff(self.curValve)
+            self.curState = 4
+            
+    def updateState4(self):
+        #wait for 0.5 s, then start recording responses
+        if self.statesStarted[self.curState] == False:
+            self.statesStarted[self.curState] = True
+            self.samplingTimer = RunIntervalTimer(0.5)
+        
+        if self.samplingTimer.countDownComplete():
+            del self.samplingTimer
+            self.curState = 5
+            
+    def updateState5(self):
+        
+    
     def updateState2(self):
         #start final valve, start checking for head entries
         if self.statesStarted[self.curState] == False:
     '''
     #counts off an interval, divided into bins of a set duration.
     # If a response doesn't occur in a bin, the interval ends
-    def __init__(self,intervalLength =1.2, binDuration = 0.2):
+    def __init__(self,intervalLength =1.2, binDuration = 0.2, percentOfBins = 1):
         self.curBin = 0
         self.intervalLength = intervalLength
         self.binDuration = binDuration
         self.bReinforcementAvailable = False
         self.headEntryCount = 0 #simply looks to see if there have been head entries before
         self.bTrialFinished = False
+        self.percentOfBins = percentOfBins #the percentage of bins completed in order to report correct
         
        
     def newBin(self):
         else:
             return False
             
+            
+class BinnedIntervalCount():
+    '''
+    Whenever a new trial starts in phase 3 (or similar), this counts the number 
+    of licks over an interval. The interval is divided into bins. If there is
+    a head entry noted in every bin, the update function returns that
+    reinforcement should now be made available. The update function also
+    returns whether the trial is ongoing or finished, and the current status of
+    the trial.
+    '''
+    #counts off an interval, divided into bins of a set duration.
+    # If a response doesn't occur in a bin, the interval ends
+    def __init__(self,intervalLength =1.2, binDuration = 0.2, percentOfBins = 1):
+        self.curBin = 0
+        self.intervalLength = intervalLength
+        self.binDuration = binDuration
+        self.binCountTotal = int(round(self.intervalLength / self.binDuration))
+        print(str(self.binCountTotal)+'bincount')
+        self.binList = [0]*self.binCountTotal
+        
+        self.bResp = False
+        self.bContinue = True
+        self.lickDuration = 0
+        self.newBin()
+        self.bReinforcementAvailable = False
+        self.headEntryCount = 0 #simply looks to see if there have been head entries before
+        self.bTrialFinished = False
+        self.percentOfBins = percentOfBins #the percentage of bins completed in order to report correct
+        self.binsToReinforcement = int(round(self.percentOfBins * self.binCountTotal))
+        
+       
+    def newBin(self):
+        print('newBin')
+        self.curBin += 1
+        if self.curBin > self.binCountTotal:
+            self.bReinforcementAvailable = True
+            self.endInterval()
+#        del self.binTimer
+        self.binTimer =RunInternalTimer(self.binDuration)
+
+    def endOfBin(self, curBinResp):
+        
+        if self.binList.count(1) >= self.binsToReinforcement:
+            self.endInterval()
+            self.bReinforcementAvailable = True
+            
+        elif self.binList.count(1) < self.binsToReinforcment:
+            pass
+        if curBinResp > 0:
+            self.newBin()
+        else:
+            self.endInterval()
+        
+    def endInterval(self):
+        self.mouseHeadInDuration = self.binList.count(1) * self.binDuration
+        self.bTrialFinished = True
+        print('end interval')
+           
+    def update(self, bHeadIn):
+        bUpdate = self.addHeadEntryCount(bHeadIn)
+        if bUpdate:
+            if self.bTrialFinished == False:
+                if bHeadIn == True:
+                    self.binList[self.curBin - 1] = 1
+                if self.binTimer.countDownComplete():
+                    #curBinResp = int(self.binList[self.curBin-1])
+                    self.endOfBin(curBinResp)
+        return self.bTrialFinished, self.bReinforcementAvailable, self.binList
+        
+    def addHeadEntryCount(self,bHeadIn):
+        if bHeadIn == True:
+            self.headEntryCount += 1
+        if self.headEntryCount > 0:
+            return True
+        else:
+            return False
+            
+            
+            
 class OutputData():
     def __init__(self, fileName = 'default',subjectName = 'mouse' ,experimentName = 'experiment',techName = 'anonymous'):
         self.fileName = str(fileName) + '.txt'
         self.curSestime = self.iTime.timeSince()
         self.lcdTimeCnt.display(round(self.curSestime,2))       
         ###
-        print 'hi'
+        print 'timer running'
         
         if self.bPhase1 == True:
             self.bPhase1, self.hits, self.misses = self.curPhase.update()
 
 # Form implementation generated from reading ui file 'gui.ui'
 #
-# Created: Sat Jul 06 16:06:11 2013
+# Created: Sat Jul 06 17:27:29 2013
 #      by: PyQt4 UI code generator 4.9.6
 #
 # WARNING! All changes made in this file will be lost!
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.