本文整理汇总了Python中trace.Trace.squash_df方法的典型用法代码示例。如果您正苦于以下问题:Python Trace.squash_df方法的具体用法?Python Trace.squash_df怎么用?Python Trace.squash_df使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trace.Trace
的用法示例。
在下文中一共展示了Trace.squash_df方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trim_lat_df
# 需要导入模块: from trace import Trace [as 别名]
# 或者: from trace.Trace import squash_df [as 别名]
def trim_lat_df(self, start, lat_df):
if lat_df.empty:
return lat_df
lat_df = Trace.squash_df(lat_df, start, lat_df.index[-1], "t_delta")
# squash_df only updates t_delta, remove t_start to make sure it's not used
return lat_df.drop('t_start', 1)
示例2: max_idle_time
# 需要导入模块: from trace import Trace [as 别名]
# 或者: from trace.Trace import squash_df [as 别名]
def max_idle_time(self, trace, start, end, cpus):
"""
:returns: The maximum idle time of 'cpus' in the [start, end] interval
"""
idle_df = pd.DataFrame()
max_time = 0
max_cpu = 0
for cpu in cpus:
busy_df = self.get_active_df(trace, cpu)
busy_df = Trace.squash_df(busy_df, start, end)
busy_df = busy_df[busy_df.state == 0]
if busy_df.empty:
continue
local_max = busy_df.delta.max()
if local_max > max_time:
max_time = local_max
max_cpu = cpu
return max_time, max_cpu
示例3: test_squash_df
# 需要导入模块: from trace import Trace [as 别名]
# 或者: from trace.Trace import squash_df [as 别名]
def test_squash_df(self):
"""
TestTrace: squash_df() behaves as expected
"""
index = [float(i) for i in range(15, 20)]
data = [(1, i % 2) for i in range(15, 20)]
df = pd.DataFrame(index=index, data=data, columns=['delta', 'state'])
## Test "standard" slice:
# The df here should be:
# Time delta state
# 16.5 .5 0
# 17 .5 1
df1 = Trace.squash_df(df, 16.5, 17.5,)
head = df1.head(1)
tail = df1.tail(1)
self.assertEquals(len(df1.index), 2)
self.assertEquals(df1.index.tolist(), [16.5, 17])
self.assertAlmostEqual(head['delta'].values[0], 0.5, places=self.FLOAT_PLACES)
self.assertAlmostEqual(tail['delta'].values[0], 0.5, places=self.FLOAT_PLACES)
self.assertEquals(head['state'].values[0], 0)
self.assertEquals(tail['state'].values[0], 1)
## Test slice where no event exists in the interval
# The df here should be:
# Time delta state
# 16.2 .6 0
df2 = Trace.squash_df(df, 16.2, 16.8)
self.assertEquals(len(df2.index), 1)
self.assertEquals(df2.index[0], 16.2)
self.assertAlmostEqual(df2['delta'].values[0], 0.6, places=self.FLOAT_PLACES)
self.assertEquals(df2['state'].values[0], 0)
## Test slice that matches an event's index
# The df here should be:
# Time delta state
# 16 1 0
df3 = Trace.squash_df(df, 16, 17)
self.assertEquals(len(df3.index), 1)
self.assertEquals(df3.index[0], 16)
self.assertAlmostEqual(df3['delta'].values[0], 1, places=self.FLOAT_PLACES)
self.assertEquals(df3['state'].values[0], 0)
## Test slice past last event
# The df here should be:
# Time delta state
# 19.5 .5 1
df4 = Trace.squash_df(df, 19.5, 22)
self.assertEquals(len(df4.index), 1)
self.assertEquals(df4.index[0], 19.5)
self.assertAlmostEqual(df4['delta'].values[0], 0.5, places=self.FLOAT_PLACES)
self.assertEquals(df4['state'].values[0], 1)
## Test slice where there's no past event
df5 = Trace.squash_df(df, 10, 30)
self.assertEquals(len(df5.index), 5)
## Test slice where that should contain nothing
df6 = Trace.squash_df(df, 8, 9)
self.assertEquals(len(df6.index), 0)