本文整理汇总了Python中DIRAC.AccountingSystem.Client.ReportsClient.ReportsClient类的典型用法代码示例。如果您正苦于以下问题:Python ReportsClient类的具体用法?Python ReportsClient怎么用?Python ReportsClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReportsClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getPlotData
def getPlotData( self ):
retVal = self.__parseFormParams()
if not retVal[ 'OK' ]:
c.error = retVal[ 'Message' ]
return render( "/error.mako" )
params = retVal[ 'Value' ]
repClient = ReportsClient( rpcClient = getRPCClient( "Accounting/ReportGenerator" ) )
retVal = repClient.getReport( *params )
if not retVal[ 'OK' ]:
c.error = retVal[ 'Message' ]
return render( "/error.mako" )
rawData = retVal[ 'Value' ]
groupKeys = rawData[ 'data' ].keys()
groupKeys.sort()
if 'granularity' in rawData:
granularity = rawData[ 'granularity' ]
data = rawData['data']
tS = int( Time.toEpoch( params[2] ) )
timeStart = tS - tS % granularity
strData = "epoch,%s\n" % ",".join( groupKeys )
for timeSlot in range( timeStart, int( Time.toEpoch( params[3] ) ), granularity ):
lineData = [ str( timeSlot ) ]
for key in groupKeys:
if timeSlot in data[ key ]:
lineData.append( str( data[ key ][ timeSlot ] ) )
else:
lineData.append( "" )
strData += "%s\n" % ",".join( lineData )
else:
strData = "%s\n" % ",".join( groupKeys )
strData += ",".join( [ str( rawData[ 'data' ][ k ] ) for k in groupKeys ] )
response.headers['Content-type'] = 'text/csv'
response.headers['Content-Disposition'] = 'attachment; filename="%s.csv"' % md5( str( params ) ).hexdigest()
response.headers['Content-Length'] = len( strData )
return strData
示例2: test_addAndRemove
def test_addAndRemove():
# just inserting one record
record = createAccountingRecord()
record.setStartTime()
record.setEndTime()
res = gDataStoreClient.addRegister(record)
assert res['OK']
res = gDataStoreClient.commit()
assert res['OK']
rc = ReportsClient()
res = rc.listReports('DataOperation')
assert res['OK']
res = rc.listUniqueKeyValues('DataOperation')
assert res['OK']
res = rc.getReport('DataOperation', 'Successful transfers',
datetime.datetime.utcnow(), datetime.datetime.utcnow(),
{}, 'Destination')
assert res['OK']
# now removing that record
res = gDataStoreClient.remove(record)
assert res['OK']
示例3: __queryForPlot
def __queryForPlot(self):
retVal = self.__parseFormParams()
if not retVal['OK']:
return retVal
params = retVal['Value']
repClient = ReportsClient(rpcClient=RPCClient("Accounting/ReportGenerator"))
retVal = repClient.generateDelayedPlot(*params)
return retVal
示例4: doCommand
def doCommand(self, sites = None):
"""
Returns running and runned jobs, querying the WMSHistory
for the last self.args[0] hours
:params:
:attr:`sites`: list of sites (when not given, take every sites)
:returns:
"""
if sites is None:
from DIRAC.Core.DISET.RPCClient import RPCClient
RPC_RSS = RPCClient("ResourceStatus/ResourceStatus")
sites = RPC_RSS.getSitesList()
if not sites['OK']:
raise RSSException, where(self, self.doCommand) + " " + sites['Message']
else:
sites = sites['Value']
if self.RPC is None:
from DIRAC.Core.DISET.RPCClient import RPCClient
self.RPC = RPCClient("Accounting/ReportGenerator", timeout = self.timeout)
if self.client is None:
from DIRAC.AccountingSystem.Client.ReportsClient import ReportsClient
self.client = ReportsClient(rpcClient = self.RPC)
fromD = datetime.datetime.utcnow()-datetime.timedelta(hours = self.args[0])
toD = datetime.datetime.utcnow()
try:
run_jobs = self.client.getReport('WMSHistory', 'NumberOfJobs', fromD, toD,
{}, 'Site')
if not run_jobs['OK']:
raise RSSException, where(self, self.doCommand) + " " + run_jobs['Message']
else:
run_jobs = run_jobs['Value']
except:
gLogger.exception("Exception when calling RunningJobsBySiteSplitted_Command")
return {}
listOfSites = run_jobs['data'].keys()
plotGran = run_jobs['granularity']
singlePlots = {}
for site in listOfSites:
if site in sites:
plot = {}
plot['data'] = {site: run_jobs['data'][site]}
plot['granularity'] = plotGran
singlePlots[site] = plot
resToReturn = {'WMSHistory': singlePlots}
return resToReturn
示例5: web_getPlotData
def web_getPlotData(self):
callback = {}
retVal = self.__parseFormParams()
if not retVal[ 'OK' ]:
callback = {"success":"false", "error":retVal[ 'Message' ]}
self.finish( callback )
params = retVal[ 'Value' ]
'''self.finish({'success' : 'true', 'result' : params})'''
repClient = ReportsClient( rpcClient = RPCClient( "Accounting/ReportGenerator" ) )
retVal = repClient.getReport(*params)
if not retVal[ 'OK' ]:
callback = {"success":"false", "error":retVal[ 'Message' ]}
self.finish( callback )
rawData = retVal[ 'Value' ]
groupKeys = rawData[ 'data' ].keys()
self.finish({'success' : 'true', 'result' : groupKeys})
示例6: initialize
def initialize( self ):
self.__log = gLogger.getSubLogger( "WMSHistoryCorrector" )
self.__reportsClient = ReportsClient()
self.__usageHistory = {}
self.__slices = {}
self.__lastHistoryUpdate = 0
self.__globalCorrectionFactor = 5
self._fillSlices()
return S_OK()
示例7: __init__
def __init__( self, baseCSPath, group ):
self.__log = gLogger.getSubLogger( "WMSHistoryCorrector" )
self.__baseCSPath = baseCSPath
self.__group = group
self.__reportsClient = ReportsClient()
self.__usageHistory = {}
self.__slices = {}
self.__lastHistoryUpdate = 0
self.__globalCorrectionFactor = 5
self._fillSlices()
示例8: web_generatePlot
def web_generatePlot(self):
callback = {}
retVal = self.__parseFormParams()
if not retVal[ 'OK' ]:
callback = {"success":"false", "error":retVal[ 'Message' ]}
self.finish( callback )
params = retVal[ 'Value' ]
repClient = ReportsClient( rpcClient = RPCClient( "Accounting/ReportGenerator" ) )
retVal = repClient.generateDelayedPlot( *params )
if not retVal[ 'OK' ]:
callback = {"success":"false", "error":retVal[ 'Message' ]}
self.finish( callback )
rawData = retVal[ 'Value' ]
'''groupKeys = rawData[ 'data' ].keys()'''
self.log.always("11111111111111111111111111111111111111111111111111111111111")
self.log.always(retVal[ 'Value' ][ 'plot' ])
self.log.always("22222222222222222222222222222222222222222222222222222222222")
self.finish({'success' : 'true', 'result' : rawData['plot']})
示例9: __showPlotPage
def __showPlotPage( self, typeName, templateFile ):
#Get unique key values
retVal = self.__getUniqueKeyValues( typeName )
if not retVal[ 'OK' ]:
c.error = retVal[ 'Message' ]
return render ( "/error.mako" )
c.selectionValues = simplejson.dumps( retVal[ 'Value' ] )
#Cache for plotsList?
data = AcctController.__keysCache.get( "reportsList:%s" % typeName )
if not data:
repClient = ReportsClient( rpcClient = getRPCClient( "Accounting/ReportGenerator" ) )
retVal = repClient.listReports( typeName )
if not retVal[ 'OK' ]:
c.error = retVal[ 'Message' ]
return render ( "/error.mako" )
data = simplejson.dumps( retVal[ 'Value' ] )
AcctController.__keysCache.add( "reportsList:%s" % typeName, 300, data )
c.plotsList = data
return render ( templateFile )
示例10: generateAccountingPlot
def generateAccountingPlot( self ):
try:
site = str( request.params[ 'site' ] )
plotName = str( request.params[ 'plotName' ] )
plotTime = str( request.params[ 'plotTime' ] )
height = int( request.params[ 'height' ] )
width = int( request.params[ 'width' ] )
except:
S_ERROR( "Oops, Invalid parameters!" )
extraParams = { 'height' : height, 'width' : width }
if plotName == 'CPU Used':
typeName = "Job"
reportName = "CPUUsed"
grouping = "FinalMajorStatus"
condDict = { 'Site' : [ site ] }
extraParams[ 'plotTitle' ] = "CPU used for site %s" % site
elif plotName == "Running jobs":
typeName = "WMSHistory"
reportName = "NumberOfJobs"
grouping = "JobGroup"
condDict = { 'Site' : [ site ], 'Status' : [ 'Running' ] }
extraParams[ 'plotTitle' ] = "Jobs running for site %s" % site
else:
return S_ERROR( "Oops, invalid plot name!" )
if plotTime == "Last day":
extraParams[ 'lastSeconds' ] = 86400
elif plotTime == "Last week":
extraParams[ 'lastSeconds' ] = 604800
elif plotTime == "Last month":
extraParams[ 'lastSeconds' ] = 2592000
else:
return S_ERROR( "Oops, invalid time!" )
end = datetime.datetime.utcnow()
start = end - datetime.timedelta( seconds = extraParams[ 'lastSeconds' ] )
repClient = ReportsClient( rpcClient = getRPCClient( "Accounting/ReportGenerator" ) )
result = repClient.generateDelayedPlot( typeName, reportName, start, end, condDict, grouping, extraParams )
if not result[ 'OK' ]:
return S_ERROR( result[ 'Message' ] )
return S_OK( result[ 'Value' ][ 'plot' ] )
示例11: getJobsHistory
def getJobsHistory():
result = gOAManager.authorize()
if not result[ 'OK' ]:
bottle.abort( 401, result[ 'Message' ] )
condDict = {}
if 'allOwners' not in bottle.request.params:
condDict[ 'User' ] = gOAData.userName
timeSpan = 86400
if 'timeSpan' in bottle.request.params:
try:
timeSpan = max( 86400, int( bottle.request.params[ 'timeSpan' ] ) )
except ValueError:
bottle.abort( 400, "timeSpan has to be an integer!" )
print "[DEBUG] condDict is %s" % condDict
rpg = ReportsClient( rpcClient = getRPCClient("Accounting/ReportGenerator"), transferClient = getTransferClient("Accounting/ReportGenerator") )
end = datetime.datetime.utcnow()
start = end - datetime.timedelta( seconds = timeSpan )
result = rpg.getReport( "WMSHistory", "NumberOfJobs", start, end, condDict, 'Status' )
if not result[ 'OK' ]:
bottle.abort( 500, "Server Error: %s" % result[ 'Message' ] )
return result[ 'Value' ]
示例12: web_getSelectionData
def web_getSelectionData(self):
callback = {}
typeName = self.request.arguments["type"][0]
#Get unique key values
retVal = self.__getUniqueKeyValues( typeName )
if not retVal[ 'OK' ]:
self.write(json.dumps({"success":"false", "result":"", "error":retVal[ 'Message' ]}))
return
callback["selectionValues"] = simplejson.dumps( retVal[ 'Value' ] )
#Cache for plotsList?
data = AccountingPlotHandler.__keysCache.get( "reportsList:%s" % typeName )
if not data:
repClient = ReportsClient( rpcClient = RPCClient( "Accounting/ReportGenerator" ) )
retVal = repClient.listReports( typeName )
if not retVal[ 'OK' ]:
self.write(json.dumps({"success":"false", "result":"", "error":retVal[ 'Message' ]}))
return
data = simplejson.dumps( retVal[ 'Value' ] )
AccountingPlotHandler.__keysCache.add( "reportsList:%s" % typeName, 300, data )
callback["plotsList"] = data
self.write(json.dumps({"success":"true", "result":callback}))
示例13: _getHistoryData
def _getHistoryData(self, timeSpan, groupToUse):
""" Get history data from Accounting WMSHistory database
:param int timeSpan: time span
:param str groupToUse: requested user group
:return: dictionary with history data
"""
reportsClient = ReportsClient()
reportCondition = {'Status': ['Running']}
if not groupToUse:
reportGrouping = 'UserGroup'
else:
reportGrouping = 'User'
reportCondition = {'UserGroup': groupToUse}
now = Time.dateTime()
result = reportsClient.getReport('WMSHistory', 'AverageNumberOfJobs',
now - datetime.timedelta(seconds=timeSpan), now,
reportCondition, reportGrouping,
{'lastSeconds': timeSpan})
return result
示例14: do_plotView
def do_plotView( self, args ):
"""
Gets a summary
Usage : getSummary <Summary name> <startdate YYYYMMDDHHMM> <enddate YYYYMMDDHHMM> <destLocation> (<field name> <field value>)*
"""
try:
argList = List.fromChar( args, " " )
if len( argList ) < 4:
gLogger.error( "Missing arguments!" )
return
startDT = self.__getDatetimeFromArg( argList[1] )
if not startDT:
gLogger.error( "Start time has invalid format" )
endDT = self.__getDatetimeFromArg( argList[2] )
if not endDT:
gLogger.error( "End time has invalid format" )
gLogger.info( "Start time is %s" % startDT )
gLogger.info( "End time is %s" % endDT )
sumArgs = {}
for iP in range( 4, len( argList ), 2 ):
key = argList[ iP ]
if key in sumArgs:
sumArgs[ key ].append( argList[ iP + 1 ] )
else:
sumArgs[ key ] = [ argList[ iP + 1 ] ]
repClient = ReportsClient()
retVal = repClient.plotView( argList[ 0 ], startDT, endDT, sumArgs )
if not retVal[ 'OK' ]:
gLogger.error( "Error: %s" % retVal[ 'Message' ] )
return
destDir = argList[3]
plotImg = retVal[ 'Value' ]
print "Downloading %s plot to %s.." % ( plotImg, destDir )
retVal = repClient.getPlotToDirectory( plotImg, destDir )
if not retVal[ 'OK' ]:
print " Error: %s" % retVal[ 'Message' ]
else:
print " done (%s/%s)!" % ( destDir, plotImg )
except:
self.showTraceback()
示例15: __init__
def __init__(self, args=None, clients=None):
super(DIRACAccountingCommand, self).__init__(args, clients)
if "ReportGenerator" in self.apis:
self.rgClient = self.apis["ReportGenerator"]
else:
self.rgClient = RPCClient("Accounting/ReportGenerator")
if "ReportsClient" in self.apis:
self.rClient = self.apis["ReportsClient"]
else:
self.rClient = ReportsClient()
self.rClient.rpcClient = self.rgClient