]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF29150] : Ease manipulation of data
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 9 Feb 2024 13:09:54 +0000 (14:09 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 9 Feb 2024 13:09:54 +0000 (14:09 +0100)
src/Container/SALOME_ContainerHelper.py

index 23dd6a5166f1040e59a233aea127b578d50d2a2d..9e7e3db1d6a9289d6d2a1b506df3c327246e5222 100644 (file)
@@ -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<ScriptExecInfoDeco> ) : 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<ScriptExecInfoDeco> ) : 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