Skip to content

Commit 95e6793

Browse files
committed
fix: Fixes from reviews
1 parent 38c6f23 commit 95e6793

File tree

5 files changed

+66
-24
lines changed

5 files changed

+66
-24
lines changed

src/DIRAC/MonitoringSystem/Client/DataOperationSender.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
"""
66

7-
from email.mime import base
87
import DIRAC
98
from DIRAC import S_OK, gLogger
109

src/DIRAC/MonitoringSystem/private/DBUtils.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,47 @@ def _accumulate(granularity, startEpoch, endEpoch, dataDict):
176176
lastValue += currentDict[timeEpoch]
177177
currentDict[timeEpoch] = lastValue
178178
return dataDict
179+
180+
def stripDataField(self, dataDict, fieldId):
181+
"""
182+
Strip <fieldId> data and sum the rest as it was data from one key
183+
184+
:param dict dataDict: dictionary of the form::
185+
186+
{ 'key' : { <timeEpoch1>: [1, 2, 3],
187+
<timeEpoch2>: [3, 4, 5].. } }
188+
189+
The dataDict is modified in this function and the return structure is:
190+
191+
.. code-block :: python
192+
193+
dataDict : { 'key' : { <timeEpoch1>: 1,
194+
<timeEpoch2>: 3.. } }
195+
196+
:param int fieldId:
197+
198+
:returns: list of dictionaries
199+
200+
.. code-block:: python
201+
202+
[ { <timeEpoch1>: 2, <timeEpoch2>: 4... }
203+
{ <timeEpoch1>: 3, <timeEpoch2>): 5... } ]
204+
205+
:rtype: python:list
206+
207+
"""
208+
remainingData = [{}] # Hack for empty data
209+
for key in dataDict:
210+
for timestamp in dataDict[key]:
211+
for iPos in dataDict[key][timestamp]:
212+
remainingData.append({})
213+
break
214+
break
215+
for key in dataDict:
216+
for timestamp in dataDict[key]:
217+
strippedField = float(dataDict[key][timestamp].pop(fieldId))
218+
for iPos, value in enumerate(dataDict[key][timestamp]):
219+
remainingData[iPos].setdefault(timestamp, 0.0)
220+
remainingData[iPos] += float(value)
221+
dataDict[key][timestamp] = strippedField
222+
return remainingData

src/DIRAC/MonitoringSystem/private/Plotters/BasePlotter.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
It is used to creates several plots
2+
It is used to create several plots
33
"""
44
import time
55
import copy
@@ -418,21 +418,23 @@ def _calculateEfficiencyDict(self, totDataDict, dataDict):
418418
"""
419419
It returns a dict with efficiency calculated from each key in totDataDict and dataDict
420420
"""
421-
for (totItem, totVal), (item, val) in zip(totDataDict.items(), dataDict.items()):
421+
for item, val in dataDict.items():
422+
totVal = totDataDict.get(item, {})
422423
try:
423424
dataDict[item] = {key: (float(val[key]) / float(totVal[key])) * 100 for key in val if key in totVal}
424-
except ZeroDivisionError and TypeError:
425+
except (ZeroDivisionError, TypeError):
426+
gLogger.warn("Error in ", val)
425427
gLogger.warn("Dividing by zero or using None type field. Skipping the key of this dict item...")
426428
return dataDict
427429

428430
def _sumDictValues(self, dataDict):
429431
"""
430-
Sums all the values of the keys of each item in the dict.
431-
Returns a dict with item-value pair and removes the keys.
432+
Sums the values of each item in `dataDict`.
433+
Returns the dictionary with the same keys and the values replaced by their sum.
432434
"""
433-
for item, key in dataDict.items():
435+
for key, values in dataDict.items():
434436
sum = 0
435-
for val in key:
436-
sum += key[val]
437-
dataDict[item] = sum
437+
for val in values.values():
438+
sum += val
439+
dataDict[key] = sum
438440
return dataDict

src/DIRAC/MonitoringSystem/private/Plotters/DataOperationPlotter.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
this class is used to define the plot using the plot attributes.
33
"""
44

5-
from DIRAC import S_OK
5+
from DIRAC import S_OK, S_ERROR
66
from DIRAC.MonitoringSystem.Client.Types.DataOperation import DataOperation
77
from DIRAC.MonitoringSystem.private.Plotters.BasePlotter import BasePlotter
88

@@ -33,11 +33,6 @@ def _reportFailedTransfers(self, reportRequest):
3333
return self.__reportTransfers(reportRequest, "Failed", ("Succeeded", 1))
3434

3535
def __reportTransfers(self, reportRequest, titleType, togetherFieldsToPlot):
36-
"""It is used to retrieve the data from the database.
37-
38-
:param dict reportRequest: contains attributes used to create the plot.
39-
:return: S_OK or S_ERROR {'data':value1, 'granularity':value2} value1 is a dictionary, value2 is the bucket length
40-
"""
4136
retVal = self._getTimedData(
4237
reportRequest["startTime"],
4338
reportRequest["endTime"],
@@ -48,7 +43,9 @@ def __reportTransfers(self, reportRequest, titleType, togetherFieldsToPlot):
4843
if not retVal["OK"]:
4944
return retVal
5045
dataDict, granularity = retVal["Value"]
51-
46+
strippedData = self.stripDataField(dataDict, togetherFieldsToPlot[1])
47+
if strippedData:
48+
dataDict[togetherFieldsToPlot[0]] = strippedData[0]
5249
dataDict, maxValue = self._divideByFactor(dataDict, granularity)
5350
dataDict = self._fillWithZero(granularity, reportRequest["startTime"], reportRequest["endTime"], dataDict)
5451
baseDataDict, graphDataDict, maxValue, unitName = self._findSuitableRateUnit(
@@ -105,14 +102,14 @@ def _reportQuality(self, reportRequest):
105102
dataDict, granularity = retVal["Value"]
106103
totDataDict, granularity = retTotVal["Value"]
107104
# Check that the dicts are not empty
108-
if bool(dataDict) and bool(totDataDict):
105+
if dataDict and totDataDict:
109106
# Return the efficiency in dataDict
110107
effDict = self._calculateEfficiencyDict(totDataDict, dataDict)
111-
return S_OK({"data": effDict, "granularity": granularity})
108+
return S_OK({"data": effDict, "granularity": granularity})
109+
return S_ERROR("Error in plotting the data: The dictionaries are empty!")
112110

113111
def _plotQuality(self, reportRequest, plotInfo, filename):
114-
"""
115-
Make 2 dimensional pilotSubmission efficiency plot
112+
"""Make 2 dimensional pilotSubmission efficiency plot
116113
117114
:param dict reportRequest: Condition to select data
118115
:param dict plotInfo: Data for plot.

src/DIRAC/MonitoringSystem/private/Plotters/PilotSubmissionMonitoringPlotter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PilotSubmissionMonitoringPlotter(BasePlotter):
2121
_typeName = "PilotSubmissionMonitoring"
2222
_typeKeyFields = PilotSubmissionMonitoring().keyFields
2323

24-
_reportNumberOfSubmissions = "Total Number of Submission"
24+
_reportNumberOfSubmissions = "Total Number of Submissions"
2525

2626
def _reportNumberOfSubmissions(self, reportRequest):
2727
"""It is used to retrieve the data from the database.
@@ -75,7 +75,7 @@ def _reportNumSucceeded(self, reportRequest):
7575
:param dict reportRequest: contains attributes used to create the plot.
7676
:return: S_OK or S_ERROR {'data':value1, 'granularity':value2} value1 is a dictionary, value2 is the bucket length
7777
"""
78-
# Retrieve the number of succeded submissions
78+
# Retrieve the number of succeeded submissions
7979
retVal = self._getTimedData(
8080
startTime=reportRequest["startTime"],
8181
endTime=reportRequest["endTime"],
@@ -101,7 +101,7 @@ def _reportNumSucceeded(self, reportRequest):
101101
totDataDict, granularity = retTotVal["Value"]
102102
# Check that the dicts are not empty
103103
if bool(dataDict) and bool(totDataDict):
104-
# Retrun the efficiency in dataDict
104+
# Return the efficiency in dataDict
105105
effDict = self._calculateEfficiencyDict(totDataDict, dataDict)
106106
return S_OK({"data": effDict, "granularity": granularity})
107107

0 commit comments

Comments
 (0)