本文整理汇总了Python中trappy.stats.grammar.Parser类的典型用法代码示例。如果您正苦于以下问题:Python Parser类的具体用法?Python Parser怎么用?Python Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_filtered_parse
def test_filtered_parse(self):
"""The Parser can filter a trace"""
trace = trappy.FTrace()
prs = Parser(trace, filters={"cdev_state": 3})
dfr_res = prs.solve("devfreq_out_power:freq")
self.assertEquals(len(dfr_res), 1)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:7,代码来源:test_stats_grammar.py
示例2: test_exp_ops
def test_exp_ops(self):
"""Test exponentiation: Numeric"""
parser = Parser(trappy.BareTrace())
eqn = "3**3 * 2**4"
self.assertEquals(parser.solve(eqn), 432)
eqn = "3**(4/2)"
self.assertEquals(parser.solve(eqn), 9)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:7,代码来源:test_stats_grammar.py
示例3: test_mul_ops
def test_mul_ops(self):
"""Test Mult and Division: Numeric"""
parser = Parser(trappy.Run())
eqn = "(10 * 2 / 10)"
self.assertEquals(parser.solve(eqn), 2)
eqn = "-2 * 2 + 2 * 10 / 10"
self.assertEquals(parser.solve(eqn), -2)
开发者ID:phil-chen,项目名称:trappy,代码行数:8,代码来源:test_stats_grammar.py
示例4: test_var_forward
def test_var_forward(self):
"""Test Forwarding: Variable"""
thermal_zone_id = 0
pvars = {}
pvars["control_temp"] = 78000
parser = Parser(trappy.FTrace(), pvars=pvars)
eqn = "numpy.mean(trappy.thermal.Thermal:temp) < control_temp"
self.assertTrue(parser.solve(eqn)[thermal_zone_id])
开发者ID:mdigiorgio,项目名称:trappy,代码行数:9,代码来源:test_stats_grammar.py
示例5: test_single_func_call
def test_single_func_call(self):
"""Test Single Function Call"""
thermal_zone_id = 0
parser = Parser(trappy.FTrace())
eqn = "numpy.mean(trappy.thermal.Thermal:temp)"
self.assertEquals(
parser.solve(eqn)[thermal_zone_id],
np.mean(
parser.data.thermal.data_frame["temp"]))
开发者ID:mdigiorgio,项目名称:trappy,代码行数:10,代码来源:test_stats_grammar.py
示例6: test_bool_ops_scalar
def test_bool_ops_scalar(self):
"""Test Logical Operations: Vector"""
thermal_zone_id=0
parser = Parser(trappy.FTrace())
# The equation returns a boolean scalar
eqn = "(numpy.mean(trappy.thermal.Thermal:temp) > 65000) && (numpy.mean(trappy.cpu_power.CpuOutPower) > 500)"
self.assertTrue(parser.solve(eqn)[thermal_zone_id])
eqn = "(numpy.mean(trappy.thermal.Thermal:temp) > 65000) || (numpy.mean(trappy.cpu_power.CpuOutPower) < 500)"
self.assertTrue(parser.solve(eqn)[thermal_zone_id])
开发者ID:mdigiorgio,项目名称:trappy,代码行数:10,代码来源:test_stats_grammar.py
示例7: test_bool_ops_vector
def test_bool_ops_vector(self):
"""Test Logical Operations: Vector"""
thermal_zone_id = 0
# The equation returns a vector mask
parser = Parser(trappy.FTrace())
eqn = "(trappy.thermal.ThermalGovernor:current_temperature > 77000)\
& (trappy.pid_controller.PIDController:output > 2500)"
mask = parser.solve(eqn)
self.assertEquals(len(parser.ref(mask.dropna()[0])), 0)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:10,代码来源:test_stats_grammar.py
示例8: test_funcparams_mul
def test_funcparams_mul(self):
"""Test Mult and Division: Data"""
thermal_zone_id = 0
parser = Parser(trappy.FTrace())
eqn = "trappy.thermal.Thermal:temp * 10.0"
series = parser.data.thermal.data_frame["temp"]
assert_series_equal(parser.solve(eqn)[thermal_zone_id], series * 10.0, check_names=False)
eqn = "trappy.thermal.Thermal:temp / trappy.thermal.Thermal:temp * 10"
assert_series_equal(parser.solve(eqn)[thermal_zone_id], series / series * 10, check_names=False)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:10,代码来源:test_stats_grammar.py
示例9: test_func_forward
def test_func_forward(self):
"""Test Forwarding: Mixed"""
thermal_zone_id = 0
pvars = {}
pvars["mean"] = np.mean
pvars["control_temp"] = 78000
parser = Parser(trappy.FTrace(), pvars=pvars)
eqn = "mean(trappy.thermal.Thermal:temp) < control_temp"
self.assertTrue(parser.solve(eqn)[thermal_zone_id])
开发者ID:mdigiorgio,项目名称:trappy,代码行数:10,代码来源:test_stats_grammar.py
示例10: test_sum_operator
def test_sum_operator(self):
"""Test Addition And Subtraction: Numeric"""
parser = Parser(trappy.BareTrace())
# Simple equation
eqn = "10 + 2 - 3"
self.assertEquals(parser.solve(eqn), 9)
# Equation with bracket and unary ops
eqn = "(10 + 2) - (-3 + 2)"
self.assertEquals(parser.solve(eqn), 13)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:10,代码来源:test_stats_grammar.py
示例11: test_parser_with_name
def test_parser_with_name(self):
"""Test equation using event name"""
thermal_zone_id = 0
parser = Parser(trappy.FTrace())
# Equation with functions as parameters (Mixed)
eqn = "numpy.mean(thermal:temp) + 1000"
self.assertEquals(
parser.solve(eqn)[thermal_zone_id],
np.mean(
parser.data.thermal.data_frame["temp"]) + 1000)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:11,代码来源:test_stats_grammar.py
示例12: test_super_indexing
def test_super_indexing(self):
"Test if super-indexing works correctly"""
trace = trappy.FTrace()
parser = Parser(trace)
# The first event has less index values
sol1 = parser.solve("trappy.thermal.Thermal:temp")
# The second index has more index values
sol2 = parser.solve("trappy.pid_controller.PIDController:output")
# Super Indexing should result in len(sol2) > len(sol1)
self.assertGreater(len(sol2), len(sol1))
开发者ID:mdigiorgio,项目名称:trappy,代码行数:11,代码来源:test_stats_grammar.py
示例13: test_for_parsed_event
def test_for_parsed_event(self):
"""Test if an added parsed event can be accessed"""
trace = trappy.FTrace(scope="custom")
dfr = pandas.DataFrame({"l1_misses": [24, 535, 41],
"l2_misses": [155, 11, 200],
"cpu": [ 0, 1, 0]},
index=pandas.Series([1.020, 1.342, 1.451], name="Time"))
trace.add_parsed_event("pmu_counters", dfr)
p = Parser(trace)
self.assertTrue(len(p.solve("pmu_counters:cpu")), 3)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:12,代码来源:test_stats_grammar.py
示例14: Analyzer
class Analyzer(object):
"""
:param data: TRAPpy Run Object
:type data: :mod:`trappy.run.Run`
:param config: A dictionary of variables, classes
and functions that can be used in the statements
:type config: dict
"""
def __init__(self, data, config, topology=None):
self._parser = Parser(data, config, topology)
def assertStatement(self, statement, select=None):
"""Solve the statement for a boolean result
:param statement: A string representing a valid
:mod:`trappy.stats.grammar` statement
:type statement: str
:param select: If the result represents a boolean
mask and the data was derived from a TRAPpy event
with a pivot value. The :code:`select` can be
used to select a particular pivot value
:type select: :mod:`pandas.DataFrame` column
"""
result = self.getStatement(statement, select=select)
# pylint: disable=no-member
if not (isinstance(result, bool) or isinstance(result, np.bool_)):
warnings.warn(
"solution of {} is not an instance of bool".format(statement))
return result
# pylint: enable=no-member
def getStatement(self, statement, reference=False, select=None):
"""Evaluate the statement"""
result = self._parser.solve(statement)
# pylint: disable=no-member
if np.isscalar(result):
return result
# pylint: enable=no-member
if select is not None and len(result):
result = result[select]
if reference:
result = self._parser.ref(result)
return result
开发者ID:jrjang,项目名称:bart,代码行数:53,代码来源:Analyzer.py
示例15: test_accessors_sum
def test_accessors_sum(self):
"""Test Addition And Subtraction: Data"""
thermal_zone_id = 0
parser = Parser(trappy.FTrace())
# Equation with dataframe accessors
eqn = "trappy.thermal.Thermal:temp + \
trappy.thermal.Thermal:temp"
assert_series_equal(
parser.solve(eqn)[thermal_zone_id],
2 *
parser.data.thermal.data_frame["temp"], check_names=False)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:13,代码来源:test_stats_grammar.py
示例16: test_cls_forward
def test_cls_forward(self):
"""Test Forwarding: Classes"""
cls = trappy.thermal.Thermal
pvars = {}
pvars["mean"] = np.mean
pvars["control_temp"] = 78000
pvars["therm"] = cls
thermal_zone_id = 0
parser = Parser(trappy.FTrace(), pvars=pvars)
eqn = "mean(therm:temp) < control_temp"
self.assertTrue(parser.solve(eqn)[thermal_zone_id])
开发者ID:mdigiorgio,项目名称:trappy,代码行数:13,代码来源:test_stats_grammar.py
示例17: test_funcparams_sum
def test_funcparams_sum(self):
"""Test Addition And Subtraction: Functions"""
thermal_zone_id = 0
parser = Parser(trappy.FTrace())
# Equation with functions as parameters (Mixed)
eqn = "numpy.mean(trappy.thermal.Thermal:temp) + 1000"
self.assertEquals(
parser.solve(eqn)[thermal_zone_id],
np.mean(
parser.data.thermal.data_frame["temp"]) +
1000)
# Multiple func params
eqn = "numpy.mean(trappy.thermal.Thermal:temp) + numpy.mean(trappy.thermal.Thermal:temp)"
self.assertEquals(
parser.solve(eqn)[thermal_zone_id],
np.mean(
parser.data.thermal.data_frame["temp"]) *
2)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:19,代码来源:test_stats_grammar.py
示例18: Analyzer
class Analyzer(object):
"""
Args:
data (trappy.Run): A trappy.Run instance
config (dict): A dictionary of variables, classes
and functions that can be used in the statements
"""
def __init__(self, data, config, topology=None):
self._parser = Parser(data, config, topology)
def assertStatement(self, statement, select=None):
"""Solve the statement for a boolean result"""
result = self.getStatement(statement, select=select)
# pylint: disable=no-member
if not (isinstance(result, bool) or isinstance(result, np.bool_)):
warnings.warn(
"solution of {} is not an instance of bool".format(statement))
return result
# pylint: enable=no-member
def getStatement(self, statement, reference=False, select=None):
"""Evaluate the statement"""
result = self._parser.solve(statement)
# pylint: disable=no-member
if np.isscalar(result):
return result
# pylint: enable=no-member
if select is not None and len(result):
result = result[select]
if reference:
result = self._parser.ref(result)
return result
开发者ID:sinkap,项目名称:bart,代码行数:40,代码来源:Analyzer.py
示例19: __init__
def __init__(self, data, sig_a, sig_b, **kwargs):
self._parser = Parser(
data,
config=kwargs.pop(
"config",
None),
**kwargs)
self._a = sig_a
self._b = sig_b
self._pivot_vals, self._pivot = self._get_signal_pivots()
# Concatenate the indices by doing any operation (say add)
self._a_data = self._parser.solve(sig_a)
self._b_data = self._parser.solve(sig_b)
开发者ID:mdigiorgio,项目名称:bart,代码行数:15,代码来源:signal.py
示例20: test_windowed_parse
def test_windowed_parse(self):
"""Test that the parser can operate on a window of the trace"""
trace = trappy.FTrace()
prs = Parser(trace, window=(2, 3))
dfr_res = prs.solve("thermal:temp")
self.assertGreater(dfr_res.index[0], 2)
self.assertLess(dfr_res.index[-1], 3)
prs = Parser(trace, window=(4, None))
dfr_res = prs.solve("thermal:temp")
self.assertGreater(dfr_res.index[0], 4)
self.assertEquals(dfr_res.index[-1], trace.thermal.data_frame.index[-1])
prs = Parser(trace, window=(0, 1))
dfr_res = prs.solve("thermal:temp")
self.assertEquals(dfr_res.index[0], trace.thermal.data_frame.index[0])
self.assertLess(dfr_res.index[-1], 1)
开发者ID:mdigiorgio,项目名称:trappy,代码行数:21,代码来源:test_stats_grammar.py
注:本文中的trappy.stats.grammar.Parser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论