From: Anthony Geay Date: Fri, 9 Feb 2024 13:09:54 +0000 (+0100) Subject: [EDF29150] : Ease manipulation of data X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3c34419732286b2389ef661fabd28f6c89a6e415;p=modules%2Fkernel.git [EDF29150] : Ease manipulation of data --- diff --git a/src/Container/SALOME_ContainerHelper.py b/src/Container/SALOME_ContainerHelper.py index 23dd6a516..9e7e3db1d 100644 --- a/src/Container/SALOME_ContainerHelper.py +++ b/src/Container/SALOME_ContainerHelper.py @@ -688,4 +688,92 @@ def IsExecTimeHigherThan( execInstDeco, limitDuration ): if execInstDeco.get() is not None: return execInstDeco.get().execTime > limitDuration else: - return False \ No newline at end of file + return False + +def GetMaxTimeExec( listOfFinishedExecs ): + """ + Returns the instance among listOfFinishedExecs that spends the max time to be executed + + Args: + ----- + + listOfFinishedExecs ( list ) : instance of ScriptExecInfoDeco that have finished to be executed + Typically returned by ListAllExecFinishedContainIn + + Returns + ------- + + ScriptExecInfoDeco : + """ + return listOfFinishedExecs[ max([(i,elt.execTime) for i,elt in enumerate( listOfFinishedExecs) ],key = lambda x : x[1])[0] ] + +def GetMinTimeExec( listOfFinishedExecs ): + """ + Returns the instance among listOfFinishedExecs that spends the min time to be executed + + Args: + ----- + + listOfFinishedExecs ( list ) : instance of ScriptExecInfoDeco that have finished to be executed + Typically returned by ListAllExecFinishedContainIn + + Returns + ------- + + ScriptExecInfoDeco : + """ + return listOfFinishedExecs[ min([(i,elt.execTime) for i,elt in enumerate( listOfFinishedExecs) ],key = lambda x : x[1])[0] ] + +class DistriutionClass: + def __init__(self, begin, end, listOfExecs): + self._begin = begin + self._end = end + self._list_of_execs = sorted( listOfExecs, key = lambda x : x.execTime) + def __getitem__(self, *args): + return self._list_of_execs.__getitem__( *args ) + @property + def begin(self): + return self._begin + @property + def end(self): + return self._end + @property + def listOfExecs(self): + return self._list_of_execs + @property + def size(self): + return len( self.listOfExecs ) + @property + def reprGlobal(self): + return f"[{self.begin}->{self.end}] : {self.size} execs" + +class DistributionOfExecs: + """ + Class in charge to distribute execution log instance into equi-classes + """ + def __init__(self, listOfFinishedExecs, nbOfClasses): + self._list_of_finished_execs = listOfFinishedExecs + self._nb_of_classes = nbOfClasses + self._classes = DistributionOfExecs.ComputeDistributionOfExecTime(self._list_of_finished_execs,self._nb_of_classes) + + def __getitem__(self, *args): + return self._classes.__getitem__( *args ) + def reprOfExecs(self): + import numpy as np + cs = np.cumsum( [elt.size for elt in self._classes] ) + ret = [] + for i,(elt,cum_nb) in enumerate( zip(self._classes,cs) ): + ratio = (cum_nb / cs[-1])*100.0 + ret.append( f"- For class {i} - {elt.reprGlobal} ( {ratio:.1f}% )" ) + return "\n".join( ret ) + @classmethod + def ComputeDistributionOfExecTime( cls, listOfFinishedExecs, nbOfClasses ): + maxt = GetMaxTimeExec( listOfFinishedExecs ) + mint = GetMinTimeExec( listOfFinishedExecs ) + deltaTime = ( maxt.execTime - mint.execTime ) / nbOfClasses + res = [] + for i in range( nbOfClasses ): + begin = mint.execTime + i * deltaTime + end = mint.execTime + (i+1) * deltaTime + res.append( DistriutionClass(begin,end,[elt for elt in listOfFinishedExecs if elt.execTime >=begin and elt.execTime <= end]) ) + return res