本文整理汇总了Python中clock.Clock.get方法的典型用法代码示例。如果您正苦于以下问题:Python Clock.get方法的具体用法?Python Clock.get怎么用?Python Clock.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clock.Clock
的用法示例。
在下文中一共展示了Clock.get方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_ticktock_to_next_update
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def handle_ticktock_to_next_update(force):
t = res_manager.get_next_update_time()
if t < 0:
return False
else:
if force:
while Clock.get() < t:
Clock.tick()
return handle_ticktock(1)
else:
return handle_ticktock(t - Clock.get())
示例2: run_timer
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def run_timer():
clk = Clock.get()
if clk not in timers:
return
callback_list = timers[clk]
for callback in callback_list:
callback()
示例3: get_next_update_time
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def get_next_update_time():
while len(timers) > 0:
t = min(timers)
if t < Clock.get():
timers.pop(t, None)
else:
return t
return -1
示例4: report_xml
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def report_xml(file_name="report.xml", clock=-1):
cur = Clock.get()
if clock < 0:
clock += cur
content = E.content(clock=str(clock))
for name in pool:
value = str(pool.get(name).get_value(clock))
content.insert(0, E.feature(E.name(name), E.currentValue(value)))
with open(file_name, "w") as fout:
fout.write(tostring(content, encoding='utf-8', xml_declaration=True, pretty_print=True))
示例5: get_value
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def get_value(value, v):
if utils.is_callable(value):
return value()
elif value == "$self":
return v
elif value == "$clock":
return Clock.get()
elif utils.is_string(value) and value.startswith("$"):
return res_manager.get(value[1:])
else:
return value
示例6: get_value
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def get_value(self, clock=-1):
cur = Clock.get()
if clock < 0:
clock = cur + clock
if clock > cur or clock < 0:
return None
for item in reversed(self.value):
if item[0] <= clock:
return item[1]
示例7: get_value_history
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def get_value_history(self):
values = self.value
clk = Clock.get()
ret = [None] * clk
if values is None or len(values) == 0:
return
idx = 0
pre_value = None
for time, value in values:
while idx < time:
ret[idx] = pre_value
idx += 1
pre_value = value
if time < clk:
ret[time] = value
while idx < clk:
ret[idx] = pre_value
idx += 1
return ret
示例8: get
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def get(data, return_type=None):
if type(data) is not dict or "method" not in data:
if return_type is None:
return data
elif return_type == "lambda":
return lambda: data
else:
return None
method = data["method"]
parameter = data["parameter"]
if method.startswith(MATH_PREFIX):
if method == METHOD_MATH_ADD:
a = get(parameter["a"])
b = get(parameter["b"])
method = lambda value: get_value(a, value) + get_value(b, value)
elif method == METHOD_MATH_DIVISION:
a = get(parameter["a"])
b = get(parameter["b"])
method = lambda value: get_value(a, value) / get_value(b, value)
elif method == METHOD_MATH_MINUS:
a = get(parameter["a"])
b = get(parameter["b"])
method = lambda value: get_value(a, value) - get_value(b, value)
elif method == METHOD_MATH_MULTIPLY:
a = get(parameter["a"])
b = get(parameter["b"])
method = lambda value: get_value(a, value) * get_value(b, value)
elif method == METHOD_MATH_MOD:
a = get(parameter["a"])
b = get(parameter["b"])
method = lambda value: get_value(a, value) % get_value(b, value)
elif method == METHOD_MATH_LINEAR:
a = get(parameter["a"])
b = get(parameter["b"])
x = get(parameter["x"])
method = lambda value: get_value(a, value) * get_value(x, value) + get_value(b, value)
elif method == METHOD_MATH_SIN:
a = get(parameter["a"])
b = get(parameter["b"])
x = get(parameter["x"])
method = lambda value: get_value(a, value) * math.sin(get_value(x, value)) + get_value(b, value)
elif method == METHOD_MATH_LOG:
a = get(parameter["a"])
b = get(parameter["b"])
x = get(parameter["x"])
method = lambda value: get_value(a, value) * math.log(get_value(x, value)) + get_value(b, value)
elif method == METHOD_MATH_MEAN:
terms = parameter["term"]
method = lambda value: 1.0 * sum([get_value(term, value) for term in terms]) / len(terms)
elif method == METHOD_MATH_SUM:
terms = parameter["term"]
#print terms
method = lambda value: sum([get_value(term, value) for term in terms])
else:
print "not support method:", method
elif method.startswith(PROBABILITY_PREFIX):
if method == METHOD_PROBABILITY_MARKOV_CHAIN:
state_set = parameter["state_set"]
init_state = parameter["init_state"]
trans_matrix = parameter["trans_matrix"]
method = lambda value: markov_chain(value, state_set, init_state, trans_matrix)
elif method == METHOD_PROBABILITY_NORMAL_VARIATE_RAND:
mu = get(parameter["mu"])
sigma = get(parameter["sigma"])
method = lambda value: normalvariate(get_value(mu, value), get_value(sigma, value))
elif method == METHOD_PROBABILITY_SIMPLE_RAND:
min_value = get(parameter["min"])
max_value = get(parameter["max"])
method = lambda value: randint(get_value(min_value, value), get_value(max_value, value))
else:
print "not support method:", method
else:
if method == METHOD_OTHERS_COMBINE:
sections = parameter["section"]
# print "sections:", sections
method = lambda value: dict((section, get_value(section, value)) for section in sections)
elif method == METHOD_OTHERS_DATA_LIST:
data_list = parameter["data_list"]
method = lambda value: data_list[Clock.get() % len(data_list)]
else:
print "not support method:", method
return method
示例9: set_value
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def set_value(self, value):
clk = Clock.get()
#if len(self.value) > 1 and self.value[-1][0] == clk:
self.value.append((clk, value))
示例10: update_delay
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def update_delay(name, delay, cycle, param=None):
add_timer_callback(Clock.get() + delay, lambda: update(name, cycle, param))
示例11: update
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def update(name, cycle=None, param=None):
changed_res_set.add(name)
res = get_res(name)
res.update(param)
if cycle is not None:
add_timer_callback(Clock.get() + cycle(), lambda: update(name, cycle, param))
示例12: handle_ticktock
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def handle_ticktock(time):
ts = int(time * 2)
for i in range(ts):
tick_or_tock()
return Clock.get()
示例13: report
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import get [as 别名]
def report():
print "-----------------------------------------------------"
print "CLOCK:", Clock.get()
res_manager.report()
print "+++++++++++++++++++++++++++++++++++++++++++++++++++++"