1
1
"""
2
- It used to create several plots
2
+ It is used to create several plots
3
3
"""
4
4
import time
5
5
import copy
@@ -107,7 +107,7 @@ def __init__(self, db, setup, extraArgs=None):
107
107
108
108
def generate (self , reportRequest ):
109
109
"""
110
- It retrives the data from the database and create the plot
110
+ It retrives the data from the database and creates the plot
111
111
112
112
:param dict reportRequest: contains the plot attributes
113
113
"""
@@ -347,7 +347,7 @@ def __checkThumbnailMetadata(self, metadata):
347
347
return False
348
348
349
349
def __plotData (self , filename , dataDict , metadata , funcToPlot ):
350
- """It create the plot.
350
+ """It creates the plot.
351
351
352
352
:param str filename: the name of the file which contains the plot
353
353
:param dict dataDict: data used to crate the plot
@@ -379,7 +379,7 @@ def _generateTimedStackedBarPlot(self, filename, dataDict, metadata):
379
379
380
380
def _generateQualityPlot (self , filename , dataDict , metadata ):
381
381
"""
382
- it create a quality plot
382
+ it creates a quality plot
383
383
"""
384
384
return self .__plotData (filename , dataDict , metadata , generateQualityPlot )
385
385
@@ -397,7 +397,7 @@ def _generatePiePlot(self, filename, dataDict, metadata):
397
397
398
398
def _generateStackedLinePlot (self , filename , dataDict , metadata ):
399
399
"""
400
- It create a stacked lien plot
400
+ It creates a stacked lien plot
401
401
"""
402
402
return self .__plotData (filename , dataDict , metadata , generateStackedLinePlot )
403
403
@@ -413,3 +413,28 @@ def _fillWithZero(self, granularity, startEpoch, endEpoch, dataDict):
413
413
if timeEpoch not in currentDict :
414
414
currentDict [timeEpoch ] = 0
415
415
return dataDict
416
+
417
+ def _calculateEfficiencyDict (self , totDataDict , dataDict ):
418
+ """
419
+ It returns a dict with efficiency calculated from each key in totDataDict and dataDict
420
+ """
421
+ for item , val in dataDict .items ():
422
+ totVal = totDataDict .get (item , {})
423
+ try :
424
+ dataDict [item ] = {key : (float (val [key ]) / float (totVal [key ])) * 100 for key in val if key in totVal }
425
+ except (ZeroDivisionError , TypeError ):
426
+ gLogger .warn ("Error in " , val )
427
+ gLogger .warn ("Dividing by zero or using None type field. Skipping the key of this dict item..." )
428
+ return dataDict
429
+
430
+ def _sumDictValues (self , dataDict ):
431
+ """
432
+ Sums the values of each item in `dataDict`.
433
+ Returns the dictionary with the same keys and the values replaced by their sum.
434
+ """
435
+ for key , values in dataDict .items ():
436
+ sum = 0
437
+ for val in values .values ():
438
+ sum += val
439
+ dataDict [key ] = sum
440
+ return dataDict
0 commit comments