Ejemplo n.º 1
0
def selectMetricFromPeriod(intent_request):
    query = DataQuery(intent_request['currentIntent']['slots'])
    metric = DataMetric(intent_request['currentIntent']['slots'],
                        query.query_from)

    logger.warn(query.toJson())

    return process_query(intent_request, query, metric)
Ejemplo n.º 2
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.º 3
0
def SelectResultFromPeriod(intent_request):
    if intent_request['currentIntent']['slots'][
            'from'] is None and not intent_request['currentIntent']['slots'][
                'resultSet'] is None:
        intent_request['currentIntent']['slots']['from'] = intent_request[
            'currentIntent']['slots']['resultSet']

    query = DataQuery(intent_request['currentIntent']['slots'])
    metric = DataMetric({'metric': 'resultset'}, query.query_from)

    return process_query(intent_request, query, metric)
    def get_query(self):
        if self.item == False:
            item = self._get_item(self.session_id)
        else:
            item = self.item

        if item == False:
            return False

        return DataQuery.fromJson(
            item['session_query']) if 'session_query' in item else False
Ejemplo n.º 5
0
 def get(self, names, t1, t2):
     """Query local database are return QueryData
 names:  name od tables, 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
 nmax    max number of records
 """
     t1 = parsedate(t1)
     t2 = parsedate(t2)
     #t1=rdts(mkts(t1),tz=False,millisec=True,tsep='T')
     #t2=rdts(mkts(t2),tz=False,millisec=True,tsep='T')
     names = self._parsenames(names)
     data = {}
     for name in names:
         db = self.tables[name]
         data[name] = db.get(t1, t2)
     dq = DataQuery(self, names, t1, t2, data)
     return dq
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 SelectBooleanFromPeriod(intent_request):
    query = DataQuery(intent_request['currentIntent']['slots'])
    metric = DataMetric({'metric': 'exists'}, query.query_from)

    return process_query(intent_request, query, metric)
Ejemplo n.º 8
0
import sys
from PyQt5.QtWidgets import QApplication
from dataquery import DataQuery

if __name__ == '__main__':
    app = QApplication(sys.argv)
    dq = DataQuery()
    dq.show()
    sys.exit(app.exec_())