Statistics

Statistics

Module containing little helpers that extract information from the RSS databases providing information for comparisons and plots.

class DIRAC.ResourceStatusSystem.Utilities.Statistics.Statistics

Bases: object

Statistics class that provides helpers to extract information from the database more easily.

__init__()

Constructor

getElementHistory(element, elementName, statusType, oldAs=None, newAs=None)

Returns the succession of statuses and the dates since they are effective. The values are comprised in the time interval [ oldAs, newAs ]. If not specified, all values up to the present are returned.

It returns a list of tuples, of which the first element is the Status and the second one the time-stamp since it is effective. Note that the time-stamps will not necessarily match the time window.

Parameters:
element - str

element family ( either Site, Resource or Node )

elementName - str

element name

statusType - str

status type of the element <elementName> (e.g. ‘all’, ‘ReadAccess’,… )

oldAs - [ None, datetime ]

datetime with the start point for the time window. If not specified, it is used the oldest time in the history.

newAs - [ None, datetime ]

datetime with the end point for the time window. If not specified, it is used datetime.utcnow.

Returns:

S_OK( [ (StatusA, datetimeA),(StatusB,datetimeB) ] ) | S_ERROR

getElementStatusAt(element, elementName, statusType, statusTime)

Returns the status of the <element><elementName><statusType> at the given time <statusTime>. If not know, will return an empty list. If known, will return a tuple with two elements: Status and time since it is effective.

Parameters:
element - str

element family ( either Site, Resource or Node )

elementName - str

element name

statusType - str

status type of the element <elementName> (e.g. ‘all’, ‘ReadAccess’,… )

statusTime - datetime

datetime when we want to know the status of <element><elementName><statusType>

Returns:

S_OK( (StatusA, datetimeA) ) | S_ERROR

getElementStatusTotalTimes(element, elementName, statusType, oldAs=None, newAs=None)

Returns a dictionary with all the possible statuses as keys and as values the number of seconds that <element><elementName><statusType> hold it for a time window between [ oldAs, newAs ]. If oldAs is not defined, it is considered as datetime.min. If newAs is not defined, it is considered datetime.utcnow.

Parameters:
element - str

element family ( either Site, Resource or Node )

elementName - str

element name

statusType - str

status type of the element <elementName> (e.g. ‘all’, ‘ReadAccess’,… )

oldAs - [ None, datetime ]

datetime with the start point for the time window. If not specified, it is used the oldest time in the history.

newAs - [ None, datetime ]

datetime with the end point for the time window. If not specified, it is used datetime.utcnow.

Returns:

S_OK( [ { StatusA : secondsA },{ StatusB : secondsB } ] ) | S_ERROR

DIRAC.ResourceStatusSystem.Utilities.Statistics.timedelta_to_seconds(duration)

As Python does not provide a function to transform a timedelta into seconds, here we go.

Parameters:
duration - datetime.timedelta

timedelta to be transformed into seconds

Returns:

int ( seconds )