Ejemplo n.º 1
0
  def get(self,names,t1=None,t2=None,step=None,scale=None,debug=False,types=(float,float),method='DS',verbose=True):
    """Query the CERN measurement database and return QueryData
    names:  name of the variables in the database: comma separated or list
    t1,t2:  start and end time as string in the %Y-%m-%d %H:%M:%S.SSS format
            or unix time
    step:   For multiple file request '<n> <size>'
    scale:  For scaling algoritm '<n> <size> <alg>'
    types:  type to convert timestamp and data. If None, no concatenation is performed

    where:
      <n> is an integer number
      <size> is one of SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
      <alg> one of AVG, MIN, MAX, REPEAT, INTERPOLATE, SUM, COUNT
    """
    if t2 is None:
      t2=time.time()
    if t1 is None:
      t1=t2-1
      print t1,t2
      method='LD'
    t1=dumpdate(parsedate(t1))
    t2=dumpdate(parsedate(t2))
    names=self._parsenames(names)
    if verbose:
      print "CernLogDB: querying\n  %s"%'\n  '.join(names)
      print "CernLogDB: '%s' <--> '%s'"% (t1,t2)
      print "CernLogDB: options %s %s"% (step,scale)
    #query cern measurement database
    res=dbget(names,t1,t2,step=step,scale=scale,
               exe=self.exe_path,conf=None,
               client_name=self.client_name,
               app_name=self.app_name,
               datasource=self.datasource,
               timezone=self.timezone,
               method=method,
               types=types,debug=debug)
#    log='\n'.join(res['log'])
#    if debug:
#      print log
    if method=='LD':
      res=parse_ld(log,types)
    data={}
    bad=[]
    for k in names:
      if k in res:
        data[k]=res[k]
      else:
        bad.append(k)
    if len(bad)>0:
      print log
      raise IOError, "CernLogDB %s not retrieved" %','.join(bad)
    #save data in better datastructure
    dq=DataQuery(self,names,parsedate(t1),parsedate(t2),data,step=step,scale=scale)
    if method=='LD':
      dq.trim()
    return dq
Ejemplo n.º 2
0
 def lhc_fillnumber(self, t1=None, t2=None):
     if t2 is None:
         t2 = time.time()
     if t1 is None:
         t1 = t2 - 365 * 24 * 3600
     data = self.get('HX:FILLN', t1, t2)
     duration = np.diff(np.r_[data.a0, t2])
     fmt = "%6d '%s' %8.2f h"
     for fillnu, beg, duration in zip(data.a1, data.a0, duration):
         dumpdate(beg)
         print fmt % (fillnu, dumpdate(beg), duration / 3600.)
Ejemplo n.º 3
0
 def __repr__(self):
   out=[]
   out.append("DataQuery %s"%str(self.source))
   out.append("  '%s' <--> '%s'" % (dumpdate(self.t1),dumpdate(self.t2)))
   for i,name in enumerate(self.names):
     idx,val=self.data[name]
     typ="  %s: %s%s"%(int2keyword(i),name,val.shape)
     if len(idx)>0:
       typ+=" <%gs|%gs>"%(idx[0]-self.t1,self.t2-idx[-1])
     out.append(typ)
   return '\n'.join(out)
Ejemplo n.º 4
0
 def lhc_fillnumber(self,t1=None,t2=None):
   if t2 is None:
     t2=time.time()
   if t1 is None:
     t1=t2-365*24*3600
   data=self.get('HX:FILLN',t1,t2)
   duration=np.diff(np.r_[data.a0,t2])
   fmt="%6d '%s' %8.2f h"
   for fillnu,beg,duration in zip(data.a1,data.a0,duration):
     dumpdate(beg)
     print fmt%(fillnu,dumpdate(beg),duration/3600.)
Ejemplo n.º 5
0
 def __repr__(self):
     out = []
     out.append("DataQuery %s" % str(self.source))
     out.append("  '%s' <--> '%s'" % (dumpdate(self.t1), dumpdate(self.t2)))
     for i, name in enumerate(self.names):
         idx, val = self.data[name]
         typ = "  %s: %s%s" % (int2keyword(i), name, val.shape)
         if len(idx) > 0:
             typ += " <%gs|%gs>" % (idx[0] - self.t1, self.t2 - idx[-1])
         out.append(typ)
     return '\n'.join(out)
Ejemplo n.º 6
0
    def get(self,
            names,
            t1=None,
            t2=None,
            step=None,
            scale=None,
            debug=False,
            types=(float, float),
            method='DS',
            verbose=True):
        """Query the CERN measurement database and return QueryData
    names:  name of the variables in the database: comma separated or list
    t1,t2:  start and end time as string in the %Y-%m-%d %H:%M:%S.SSS format
            or unix time
    step:   For multiple file request '<n> <size>'
    scale:  For scaling algoritm '<n> <size> <alg>'
    types:  type to convert timestamp and data. If None, no concatenation is performed

    where:
      <n> is an integer number
      <size> is one of SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
      <alg> one of AVG, MIN, MAX, REPEAT, INTERPOLATE, SUM, COUNT
    """
        if t2 is None:
            t2 = time.time()
        if t1 is None:
            t1 = t2 - 1
            print t1, t2
            method = 'LD'
        t1 = dumpdate(parsedate(t1))
        t2 = dumpdate(parsedate(t2))
        names = self._parsenames(names)
        if verbose:
            print "CernLogDB: querying\n  %s" % '\n  '.join(names)
            print "CernLogDB: '%s' <--> '%s'" % (t1, t2)
            print "CernLogDB: options %s %s" % (step, scale)
        #query cern measurement database
        res = dbget(names,
                    t1,
                    t2,
                    step=step,
                    scale=scale,
                    exe=self.exe_path,
                    conf=None,
                    client_name=self.client_name,
                    app_name=self.app_name,
                    datasource=self.datasource,
                    timezone=self.timezone,
                    method=method,
                    types=types,
                    debug=debug)
        #    log='\n'.join(res['log'])
        #    if debug:
        #      print log
        if method == 'LD':
            res = parse_ld(log, types)
        data = {}
        bad = []
        for k in names:
            if k in res:
                data[k] = res[k]
            else:
                bad.append(k)
        if len(bad) > 0:
            print log
            raise IOError, "CernLogDB %s not retrieved" % ','.join(bad)
        #save data in better datastructure
        dq = DataQuery(self,
                       names,
                       parsedate(t1),
                       parsedate(t2),
                       data,
                       step=step,
                       scale=scale)
        if method == 'LD':
            dq.trim()
        return dq
Ejemplo n.º 7
0
def get_xlim_date():
  xa,xb=pl.xlim()
  return dumpdate(xa),dumpdate(xb)
Ejemplo n.º 8
0
 def __call__(self,x,pos=None):
   return dumpdate(x,fmt='%Y-%m-%d\n%H:%M:%S.SSS')
Ejemplo n.º 9
0
def get_xlim_date():
    xa, xb = pl.xlim()
    return dumpdate(xa), dumpdate(xb)
Ejemplo n.º 10
0
 def __call__(self, x, pos=None):
     return dumpdate(x, fmt='%Y-%m-%d\n%H:%M:%S.SSS')