def _eventStats(self): """ Query a database and return the fractions of normal events, events with warnings, events with errors and total events. """ import random normalEvents = len( query( self.analysisDB, "select AbsEventStart from metadata where ProcessingStatus='normal' order by AbsEventStart ASC" )) warnEvents = len( query( self.analysisDB, "select AbsEventStart from metadata where ProcessingStatus like 'w%' order by AbsEventStart ASC" )) errorEvents = len( query( self.analysisDB, "select AbsEventStart from metadata where ProcessingStatus like 'e%' order by AbsEventStart ASC" )) totalEvents = len( query(self.analysisDB, "select ProcessingStatus from metadata")) return round(normalEvents / float(totalEvents), 3), round(warnEvents / float(totalEvents), 3), round(errorEvents / float(totalEvents), 3), totalEvents
def _timePerEvent(self): q=query( self.analysisDB, "select ProcessTime from metadata where ProcessingStatus='normal'" ) return round(np.mean(np.hstack(q)),1), round(np.std(np.hstack(q)), 1)
def _openChanCurrent(self): q=query( self.analysisDB, "select OpenChCurrent from metadata where ProcessingStatus='normal'" ) return round(np.mean(np.hstack(q)),1), round(np.std(np.hstack(q)), 1)
def _openChanCurrent(self): q = query( self.analysisDB, "select OpenChCurrent from metadata where ProcessingStatus='normal'" ) return round(np.mean(np.hstack(q)), 1), round(np.std(np.hstack(q)), 1)
def _timeseriesSaved(self): try: q=query( self.analysisDB, "select TimeSeries from metadata" ) return len(q[0][0]) > 0 except: return False
def _hist(self): q=query( self.AnalysisDBFile, self.queryString ) x=np.hstack( np.hstack( np.array( q ) ) ) # xmin=np.max([0, np.min(x)]) xmin=np.min(x) xmax=np.max(x) return np.array(np.histogram(x, bins=self.numBins, density=self.density))
def _caprate(self): q = np.hstack( query( self.analysisDB, "select AbsEventStart from metadata where ProcessingStatus='normal' order by AbsEventStart ASC" )) # save the start time of the latest event self.lastEventStartTimeSec = q[-1] / 1000 c = caprate(q) return round(c[0], 1), round(c[1], 1)
def _caprate(self): q=np.hstack( query( self.analysisDB, "select AbsEventStart from metadata where ProcessingStatus='normal' order by AbsEventStart ASC" ) ) # save the start time of the latest event self.lastEventStartTimeSec=q[-1]/1000; c=caprate(q) return round(c[0], 1), round(c[1], 1)
def _eventStats(self): """ Query a database and return the fractions of normal events, events with warnings, events with errors and total events. """ import random normalEvents=len(query( self.analysisDB, "select AbsEventStart from metadata where ProcessingStatus='normal' order by AbsEventStart ASC" )) warnEvents=len(query( self.analysisDB, "select AbsEventStart from metadata where ProcessingStatus like 'w%' order by AbsEventStart ASC" )) errorEvents=len(query( self.analysisDB, "select AbsEventStart from metadata where ProcessingStatus like 'e%' order by AbsEventStart ASC" )) totalEvents=len(query( self.analysisDB, "select ProcessingStatus from metadata" )) return round(normalEvents/float(totalEvents), 3), round(warnEvents/float(totalEvents), 3), round(errorEvents/float(totalEvents), 3), totalEvents
def timeSeries(self): try: q=query(self.analysisDB, self.qstr)[0] decimate=self._calculateDecimation(len(q[1])) dt=(1./self.FsHz)*decimate ydat=np.array(q[1]) polarity=float(np.sign(np.mean(ydat))) ydat=polarity*ydat[::decimate] xdat=np.arange(0, dt*len(ydat), dt) dat={} if q[0]=='normal': if self.fitFuncHnd: # xfit=np.arange(0,float((len(q[1]))/self.FsHz), float(1/(100*self.FsHz))) xfit=np.arange(0, dt*len(ydat), dt) yfit=self.fitFuncHnd( *eval(self.fitFuncArgs) ) if self.stepFuncHnd: # xstep=np.arange(0,float((len(q[1]))/self.FsHz), float(1/(100*self.FsHz))) xstep=np.arange(0, dt*len(ydat), dt) ystep=self.stepFuncHnd( *eval(self.stepFuncArgs) ) dat['data'] = [ plotlyWrapper.plotlyTrace(list(xdat), list(ydat), "NormalEvent"), plotlyWrapper.plotlyTrace(list(xfit), list(yfit), "NormalEventFit"), plotlyWrapper.plotlyTrace(list(xstep), list(ystep), "NormalEventStep") ] elif q[0].startswith('w'): dat['data'] = [ plotlyWrapper.plotlyTrace(list(xdat), list(ydat), "WarnEvent") ] self.returnMessageJSON['errorText']="WARNING: "+self.errTextObject[q[0]] else: dat['data'] = [ plotlyWrapper.plotlyTrace(list(xdat), list(ydat), "ErrorEvent") ] self.returnMessageJSON['errorText']="ERROR: "+self.errTextObject[q[0]] dat['layout']=plotlyWrapper.plotlyLayout("EventViewLayout") dat['options']=plotlyWrapper.plotlyOptions() self.returnMessageJSON['eventViewPlot']=dat self.returnMessageJSON['parameterTable']=self._paramTable(*eval(self.paramTableFuncArgs)) return self.returnMessageJSON except IndexError: raise EndOfDataError
def _hist2d(self): try: q = query(self.AnalysisDBFile, self.queryString) y, x = np.transpose(np.array(q)) Y = np.hstack(y) X = np.hstack(x) xmin = np.max([0, 0.9 * np.min(X)]) xmax = 1.1 * np.max(X) ymin = np.max([0, 0.9 * np.min(Y)]) ymax = np.min([1, 1.1 * np.max(Y)]) return np.histogram2d(X, Y, bins=(self.numBins, self.numBins), range=[[xmin, xmax], [ymin, ymax]]) except ValueError: raise QuerySyntaxError("")
def _hist2d(self): try: q=query( self.AnalysisDBFile, self.queryString ) y,x=np.transpose(np.array(q)) Y=np.hstack(y) X=np.hstack(x) xmin=np.max([0, 0.9*np.min(X)]) xmax=1.1*np.max(X) ymin=np.max([0, 0.9*np.min(Y)]) ymax=np.min([1, 1.1*np.max(Y)]) return np.histogram2d(X, Y, bins=(self.numBins, self.numBins), range=[[xmin, xmax], [ymin, ymax]]) except ValueError: raise QuerySyntaxError("")
def _timePerEvent(self): q = query( self.analysisDB, "select ProcessTime from metadata where ProcessingStatus='normal'") return round(np.mean(np.hstack(q)), 1), round(np.std(np.hstack(q)), 1)
def _timeseriesSaved(self): try: q = query(self.analysisDB, "select TimeSeries from metadata") return len(q[0][0]) > 0 except: return False