Esempio n. 1
0
length=10
values=DataReadWrite.getStatsForPrefireWeightOfSample(runID,i_positionNumber,length)
if (values==False):
   print "No stats possible"
else:
   (average,stdev,variance)=values
   print "Result: Average:",average,"Stdev:",stdev,"Variance:",variance
test += 1
if average>0:
   print "PASS"
   passed += 1
else:
   print "FAIL"
print "-------------------------------------------------------"
print "getStatsForPostFireWeightOfSample(",runID,",",i_positionNumber,",",length,")"
values=DataReadWrite.getStatsForPostFireWeightOfSample(runID,i_positionNumber,length)
if (values==False):
   print "No stats possible"
else:
   (average,stdev,variance)=values
   print "Result: Average:",average,"Stdev:",stdev,"Variance:",variance
test += 1
if average>0:
   print "PASS"
   passed += 1
else:
   print "FAIL"
print "-------------------------------------------------------"
startdate="10-10-2011"
starttime="10:10:10"
sdate=startdate.split("-",3)
Esempio n. 2
0
def weighAllSamplesPostFire(runID,duration,
      		intervalsec,numberOfSamples,startPosition,endOfFiring,
      		tempCorrection,rhCorrection,repeat,robotStatus,
      		POSITION,MCOUNT,CURRENTSTEP,STATUS,DURATION,
      		LOGGERINTERVAL,RUNID,NUMBEROFSAMPLES,TIMEREMAINING,TIMEELAPSED,REPS,CYCLE):
   ## print runID,"-",duration,"-",intervalsec,"-",numberOfSamples,"-",startPosition,"-",endOfFiring,"-",tempCorrection,"-",rhCorrection,"-",repeat
   logging.debug("weighAllSamplesPostFire( %d,%d,%d,%d,%d,%s,%f,%f,%d)" %
   				(runID,
   				duration,
      		intervalsec,
      		numberOfSamples,
      		startPosition,
      		endOfFiring,
      		tempCorrection,
      		rhCorrection,
      		repeat))
   # Find elapsed time
   #first put robot back to zero
   position=int(startPosition)

   if position=="":
      position=1

   #HomePosition()
   listOfValues=()
   STATUS.set("Initializing")
   crucibleWeight=0.0
   robotStatus.deiconify()
   preOrPost=2
   status="postfire"
   now = datetime.today()
   timeLapsedSinceFiring= now - endOfFiring
   Label(robotStatus,text="Run ID:").grid(row=0,column=0,sticky=W)
   Label(robotStatus,textvariable=RUNID).grid(row=0,column=1, sticky=W)
   Label(robotStatus,text="Current sample number:").grid(row=1,column=0,sticky=W)
   Label(robotStatus,textvariable=POSITION).grid(row=1,column=1, sticky=W) 
   Label(robotStatus,text="Cycle Number:").grid(row=3,column=0,sticky=W)
   Label(robotStatus,textvariable=CYCLE).grid(row=3,column=1,sticky=W)

   Label(robotStatus,textvariable=MCOUNT).grid(row=4,column=1,sticky=W)
   Label(robotStatus,text="Current measurement count:").grid(row=4,column=0,sticky=W)
   Label(robotStatus,text="Time elapsed since firing (min):").grid(row=5,column=0,sticky=W)
   Label(robotStatus,textvariable=TIMEELAPSED).grid(row=5,column=1,sticky=W)
   Label(robotStatus,text="Logging interval:").grid(row=6,column=0, sticky=W)
   Label(robotStatus,textvariable=LOGGERINTERVAL).grid(row=6,column=1,sticky=W)
   Label(robotStatus,text="Duration of Measurements:").grid(row=7,column=0, sticky=W)
   Label(robotStatus,textvariable=DURATION).grid(row=7,column=1,sticky=W)
   Label(robotStatus,text="Number of Samples:").grid(row=8,column=0,sticky=W)
   Label(robotStatus,textvariable=NUMBEROFSAMPLES).grid(row=8,column=1,sticky=W)
   Label(robotStatus,text="Time remaining for this sample:").grid(row=9,column=0,sticky=W)
   Label(robotStatus,textvariable=TIMEREMAINING).grid(row=9,column=1,sticky=W)
   Label(robotStatus,text="Status").grid(row=10,column=0, sticky=W)
   Label(robotStatus,textvariable=STATUS).grid(row=10,column=1,sticky=W)
   startTime=datetime.today()
   endPoint=timedelta(minutes=duration)
   endTime=startTime+endPoint
   POSITION.set(int(position))
   NUMBEROFSAMPLES.set(int(numberOfSamples))
   DURATION.set(duration)
   LOGGERINTERVAL.set(intervalsec)
   CYCLE.set(repeat)
  
   sleep(5)
   while position < numberOfSamples+1:
      
      logging.debug("Now on position: %d",int(position))
      ##goToSamplePosition(position)
      ##val=samplePickUp()
      ##if val == False:
      ##   return False
      ## zerothe balance for each sample
      ##DataReadWrite.zeroBalance()
      ##DataReadWrite.openBalanceDoor()
      ##goToOutsideBalanceFromOutside()
      ##goToInsideBalanceFromOutisde()
      ##val=putSampleOnBalance()
      ##if val == False:
      ##   return False
      ## may need to check to see if arm is clear of door.
      #goToOutsideBalanceFromInside()
      #DataReadWrite.closeBalanceDoor()
      crucibleWeight=double(DataReadWrite.getCrucibleWeight(runID,position))
      if (crucibleWeight is False):
         alertWindow("getCrucibleWeight returned an error.")
         exit(1)
      
      sampleID=int(DataReadWrite.getSampleID(runID,position))
      startTime=datetime.today()
      durationOfLogging=int(duration)
      endPoint=timedelta(minutes=durationOfLogging)
      
      endTime=startTime+endPoint
      count=0
      kcount=0
      repetition_count=0
      standard_weight=float(0.0)
      listOfValues=[]
      a=array([])
      statustext="Weighing sample # %d"% position
      STATUS.set(statustext)
      total_count=int(DataReadWrite.getMaxPostFireCount(runID,position))
      if (total_count==0 or total_count==""):
         total_count=0
      while datetime.today() < endTime:
         timeLeft=endTime-datetime.today()
         TIMEREMAINING.set(int(timeLeft.seconds/60))
         kcount=0
         standard_weight=0.0
         measurement=double(0.0)
         weight=double(0.0)
         result=[]
         (measurement,status)=DataReadWrite.readWeightFromBalance()
         weight=double(measurement)-double(crucibleWeight)
         if weight>0.0:
            a=append(a,double(weight))
            averageWeight=a.mean()
            stdevWeight=a.std()
            logger.debug( "Count: %i the average weight of sample # %i is %f with stdev of %f" % (count, position, averageWeight,stdevWeight))
            ## now update crucible position record 
            now = datetime.today()
            today = now.strftime("%m-%d-%y %H:%M:%S")
            total_count += 1
            count += 1
            repetition_count += 1
            MCOUNT.set(count)
            temperature=xyzRobot.getTemperature()
            humidity=xyzRobot.getHumidity()
            logger.debug( "TMP:  temp: %s, humidity: %s" % (temperature,humidity))
            
            standard_weight=0.0
            
            timeDiff=now - endOfFiring
            timeElapsed=int(timeDiff.seconds/60)
            TIMEELAPSED.set(timeElapsed)
            timeElapsedQuarterPower=double(pow(abs(timeElapsed),0.25))
 
            value=DataReadWrite.insertPostFireMeasurement(runID,sampleID,position,
          				weight,status,temperature,humidity,endOfFiring,
          				crucibleWeight,standard_weight,now,total_count,repeat,repetition_count,count)
            if (value is False):
               alertWindow("insertPostFireMeasurement returned with an error.")
               exit(1)
               ### check to see if enough measurements have been made. First at least 100 must have been done
            if (count > COUNTS_FOR_STATS):
               (mean,stdev,variance,tempMean,tempStdev,humidityMean,humidityStdev)=DataReadWrite.getStatsForPostFireWeightOfSample(runID,sampleID,count)
               logger.debug("TempMean: %d  TempStDev: %d HumidityMean: %d HumidityStdDev: %d" % (tempMean,tempStdev,humidityMean,humidityStdev))

               value=DataReadWrite.updateSamplePostFire(runID,sampleID,position,tempMean,tempStdev,humidityMean,humidityStdev,count,repeat,timeElapsed)

            sleep(intervalsec)
            if count==0:
               ## check to see if balance is giving anything
               (value,status)=DataReadWrite.readInstantWeightFromBalance()
               logger.debug( "Instant value from balance (unstable):  %f",float(value))
               if (value>0):
                  STATUS.set("Resetting clock")
                  logger.warning( "Since this is >0 the balance is reading but not stable")
                  logger.warning( "resetting clock. Waiting for a valid entry before storing data...")
                  startTime=datetime.today()
                  endPoint=timedelta(minutes=durationOfLogging)
                  endTime=startTime+endPoint
               else:
                  STATUS.set("Error. No output from balance. Trying again.")
                  logger.warning("There is a problem: no output from balance at all: Count: %d",int(kcount))
                  kcount += 1
                  if kcount==500:
                     STATUS.set("Tried 500 times but nothing from balance. Quitting")
                     logger.error( "There is a problem: no output for 500 counts -- quitting ")
                     ##KillMotors()
                     exit(1)
         sleep(intervalsec)
      statustext="Done! Going to retrieve sample from balance."
      STATUS.set(statustext)
      ##DataReadWrite.openBalanceDoor()
      ##goToInsideBalanceFromOutside()
      statustext="Picking up sample from balance."
      STATUS.set(statustext)
      #val=pickUpSampleFromBalance()
      #if val == False:
      #   return False
      STATUS.set("Going outside balance from inside")
      ##goToOutsideBalanceFromInside()
      statustext="Going to position %d" % int(position)
      STATUS.set(statustext)
      ##goToSamplePosition(position)
      STATUS.set("Putting sample down")
      ##val=samplePutDown()
      ##if val == False:
      ##   return False
      STATUS.set("Now going to home position.")
      #response=goHome()
      ##DataReadWrite.closeBalanceDoor()
      ##if response==False:
      ##   logger.error( "Was unable to go home. Quitting.")
      ##   return False
      position +=1
      POSITION.set(int(position))
      statustext="Now on position %d" % position
      STATUS.set(statustext)
   STATUS.set("Done!")
   #robotStatus.withdraw()
   return runID;