Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import numpy as np 

2from .baseMetric import BaseMetric 

3 

4# Metrics for dealing with things from the SlewActivities table 

5 

6__all__ = ['SlewContributionMetric', 'AveSlewFracMetric'] 

7 

8 

9class SlewContributionMetric(BaseMetric): 

10 def __init__(self, col='actDelay', activity=None, activeCol='activity', 

11 inCritCol='inCriticalPath', **kwargs): 

12 """ 

13 Return the average time, multiplied by fraction of slew -- 

14 considering critical path activities only. 

15 """ 

16 self.col = col 

17 self.inCritCol = inCritCol 

18 col = [col, inCritCol] 

19 col.append(activeCol) 

20 self.activeCol = activeCol 

21 self.activity = activity 

22 super(SlewContributionMetric, self).__init__(col=col, **kwargs) 

23 self.comment = 'Average time for %s activity (in seconds) when in the critical path, ' %(activity) 

24 self.comment += 'multiplied by the percent of total slews in the critical path.' 

25 

26 def run(self, dataSlice, slicePoint=None): 

27 # Activities of this type, in critical path. 

28 goodInCrit = np.where((dataSlice[self.activeCol] == self.activity) & 

29 (dataSlice[self.inCritCol] == 'True'))[0] 

30 if len(goodInCrit) == 0: 

31 result = 0.0 

32 else: 

33 # All activities in critical path. 

34 inCrit = np.where((dataSlice[self.inCritCol] == 'True'))[0] 

35 # Calculate fraction of total in-critical-path slew activities that this activity represents. 

36 result = np.sum(dataSlice[self.col][goodInCrit]) / np.sum(dataSlice[self.col][inCrit]) 

37 # and multiply by the mean time required by this activity. 

38 result *= np.mean(dataSlice[self.col][goodInCrit]) 

39 return result 

40 

41 

42class AveSlewFracMetric(BaseMetric): 

43 def __init__(self, col='actDelay', activity=None, activeCol='activity', 

44 idCol='SlewHistory_slewCount', **kwargs): 

45 """ 

46 Return the average time multiplied by fraction of slews. 

47 """ 

48 self.col = col 

49 self.idCol = idCol 

50 col = [col, idCol] 

51 col.append(activeCol) 

52 self.activeCol = activeCol 

53 self.activity = activity 

54 super(AveSlewFracMetric, self).__init__(col=col, **kwargs) 

55 self.comment = 'Average time for %s activity (in seconds), multiplied by percent of total slews.' %(activity) 

56 

57 def run(self, dataSlice, slicePoint=None): 

58 good = np.where(dataSlice[self.activeCol] == self.activity)[0] 

59 if len(good) == 0: 

60 result = 0.0 

61 else: 

62 result = np.mean(dataSlice[self.col][good]) 

63 nslews = np.size(np.unique(dataSlice[self.idCol])) 

64 result = result * np.size(good)/np.float(nslews) 

65 return result