Ejemplo n.º 1
0
def genericTranslateInListDictVict(cursor, theKey, theVal):

    res = defaultdict(dict)

    #search the position of the key and of the val in the tuple
    i = 0
    others = {}

    for row in cursor.description:
        if (row[0] == theKey):
            ikey = i
        elif (row[0] == theVal):
            ival = i
        else:
            others[i] = row[0]
        i += 1

    #start filling the res container
    key = ''
    val = ''
    counter = -1
    d = {
    }  #Dictionary of results {'SiteName':name, 'collName' : [val1, val2, ...]}
    for row in cursor.fetchall():
        if key != row[ikey]:
            if counter != -1:
                res[key] = l.copy()

            counter += 1
            key = row[ikey]
            l = {}
        l[row[ival]] = dict(
            (v, assignValue(row[k])) for k, v in others.items())

    #for the last entries, need to do that outside the loop
    if counter != -1:
        res[key] = l.copy()

    return res
Ejemplo n.º 2
0
def genericTranslateInListDictVict(cursor, theKey, theVal):
    
    res = defaultdict(dict)

    #search the position of the key and of the val in the tuple 
    i=0;
    others = {}
    
    for row in cursor.description:
        if(row[0]==theKey):
            ikey=i
        elif(row[0]==theVal):
            ival=i
        else:
            others[i]=row[0]
        i+=1

    #start filling the res container
    key=''
    val=''
    counter=-1
    d = {} #Dictionary of results {'SiteName':name, 'collName' : [val1, val2, ...]}
    for row in cursor.fetchall():
        if key != row[ikey]:
            if counter!=-1:
                res[key]=l.copy()

            counter+=1
            key=row[ikey]
            l={}
        l[row[ival]]=dict((v, assignValue(row[k])) for k, v in others.items())

    #for the last entries, need to do that outside the loop
    if counter!=-1:
        res[key]=l.copy()
        
    return res
Ejemplo n.º 3
0
def MostPopDSStat(params):

    #cursor = connection.cursor()

    if params.table == 'DataTier':
        table = "%s.%s" % (DBUSER, "MV_XRD_DS_STAT0_AGGR2")
    elif params.table == 'DS':
        table = "%s.%s" % (DBUSER, "MV_XRD_DS_STAT0_AGGR1")
    elif params.table == 'DSName':
        table = "%s.%s" % (DBUSER, "MV_XRD_DS_STAT0_AGGR4")
    elif params.table == 'UserDS':
        table = "%s.%s" % (DBUSER, "MV_XRD_DS_STAT1_AGGR1")

    #TimeFormats: timeformat acts to the displayed date, timeformatTrunc acts to the truncation of the input dates, and should be keept with the format of the aggregation

    timeformat = 'YYYY/MM/DD'

    if params.AggrFlag == 'day':
        timeformatTrunc = 'DDD'
    elif params.AggrFlag == 'week':
        timeformatTrunc = 'WW'
    elif params.AggrFlag == 'month':
        timeformatTrunc = 'MONTH'
    elif params.AggrFlag == 'quarter':
        timeformatTrunc = 'Q'
    elif params.AggrFlag == 'year':
        timeformatTrunc = 'YEAR'

    whereCondition = '''collName = \'%s\'
                      and isUserCMS = %s
                     ''' % (params.collName, params.isUserCMS)
    orderBy = "TDay "
    vtime = "trunc(TDay,'%s')" % (timeformatTrunc)

    groupBy = "group by %s, collName" % vtime
    vars = ''' %s as TDay, sum(numAccesses) as naccess, 
               round(sum(totCPU)/3600,0) as totCPU,
               sum(numUsers) as nUsers
            ''' % (vtime)

    #if params.SiteName != 'summary':
    #    whereCondition = "%s and siteName like '%s' " % (whereCondition, params.SiteName)
    #else:
    #    table += "_SUMM"

    query = "select %s from %s where %s %s " % (vars, table, whereCondition,
                                                groupBy)
    query = '''select round((
               TDay-to_date(\'19700101\',\'YYYYMMDD\')
               )*86400)*1000
               as millisecondsSinceEpoch,
               ta.%s
               from ( %s ) ta order by %s''' % (params.orderVar, query,
                                                orderBy)

    logger.info(query)
    try:
        cursor = connections[DBUSER].cursor()
        cursor.execute(query)

    except Exception as e:
        raise PopularityDBException(query, e)

    data = {
        'data': [(utility.assignValue(row[0]), utility.assignValue(row[1]))
                 for row in cursor.fetchall()],
        'name':
        params.collName
    }
    return data
Ejemplo n.º 4
0
Archivo: popDB.py Proyecto: dmwm/DDM
def MostPopDSStat(params):

    #cursor = connection.cursor()

    if params.table == 'DataTier':
        table = "%s.%s" % (DBUSER, "MV_XRD_DS_STAT0_AGGR2")
    elif params.table == 'DS':
        table = "%s.%s" % (DBUSER, "MV_XRD_DS_STAT0_AGGR1")
    elif params.table == 'DSName':
        table = "%s.%s" % (DBUSER, "MV_XRD_DS_STAT0_AGGR4")
    elif params.table == 'UserDS':
        table = "%s.%s" % (DBUSER, "MV_XRD_DS_STAT1_AGGR1")

    #TimeFormats: timeformat acts to the displayed date, timeformatTrunc acts to the truncation of the input dates, and should be keept with the format of the aggregation

    timeformat = 'YYYY/MM/DD'

    if params.AggrFlag == 'day':
        timeformatTrunc = 'DDD'
    elif params.AggrFlag == 'week':
        timeformatTrunc = 'WW'
    elif params.AggrFlag == 'month':
        timeformatTrunc = 'MONTH'
    elif params.AggrFlag == 'quarter':
        timeformatTrunc = 'Q'
    elif params.AggrFlag == 'year':
        timeformatTrunc = 'YEAR'

    whereCondition = '''collName = \'%s\'
                      and isUserCMS = %s
                     ''' % (params.collName, params.isUserCMS)
    orderBy       = "TDay " 
    vtime         = "trunc(TDay,'%s')" % (timeformatTrunc)
    
    groupBy = "group by %s, collName" % vtime
    vars  = ''' %s as TDay, sum(numAccesses) as naccess, 
               round(sum(totCPU)/3600,0) as totCPU,
               sum(numUsers) as nUsers
            ''' % (vtime)
    
    #if params.SiteName != 'summary':
    #    whereCondition = "%s and siteName like '%s' " % (whereCondition, params.SiteName)
    #else:
    #    table += "_SUMM"
        
    query = "select %s from %s where %s %s " % (vars, table, whereCondition, groupBy)
    query = '''select round((
               TDay-to_date(\'19700101\',\'YYYYMMDD\')
               )*86400)*1000
               as millisecondsSinceEpoch,
               ta.%s
               from ( %s ) ta order by %s''' % (params.orderVar, query, orderBy)

    logger.info(query)         
    try:
        cursor = connections[DBUSER].cursor()
        cursor.execute(query)

    except Exception as e:
        raise PopularityDBException(query, e)


    data = {'data': [(utility.assignValue(row[0]), utility.assignValue(row[1])) for row in cursor.fetchall() ],
            'name': params.collName}
    return data