本文整理汇总了Python中timer.Timer.get方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.get方法的具体用法?Python Timer.get怎么用?Python Timer.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: one_search
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import get [as 别名]
def one_search(low, up, step, depth=0):
nonlocal best_res
nonlocal best_val
val = low
increased = False
while val <= up:
if val in results:
val += step
continue
self.set_attribute(name, 'value', val, offset)
self.write_config(self.working_ini_file)
print("Trying {} = {}...".format(name, val))
log("Trying {} = {}...".format(name, val))
res = None
for i in range(len(self.config.mzml)):
t = Timer()
t.start()
output = self.run_program(self.get_args(i), False)
print('run_program took %.2f sec' % t.get())
try:
t.start()
tmp_res = self.get_result(output, i)
print('get_result took %.2f sec' % t.get())
res = self.add_res(res, tmp_res) if res is not None else tmp_res
except Exception as e:
print("fail: {}".format(str(e)))
log("fail: {}".format(str(e)))
if res is not None:
results[val] = res
print("Result = {} with value = {}".format(res, val))
log("Result = {} with value = {}".format(res, val))
if res is not None and self.cmp_result(res, best_res):
best_res = res
best_val = val
increased = True
# if self.get_element(name, offset).getAttribute('type') != 'int' and depth < MAX_REC_DEPTH:
# print("We need to go deeper with low = {}, high = {}, step = {}"
# "".format(max(val - step * 0.8, low + step / 5),
# min(val + step * 0.8, up - step / 5), step / 5))
# log("We need to go deeper with low = {}, high = {}, step = {}"
# "".format(max(val - step * 0.8, low + step / 5),
# min(val + step * 0.8, up - step / 5), step / 5))
# one_search(max(val - step * 0.8, low + step / 5), min(val + step * 0.8, up - step / 5),
# step / 5, depth + 1)
# other_best = other
# print("Best = {} with value = {}".format(best_res, best_val))
# log("Best = {} with value = {}".format(best_res, best_val))
val += step
if increased and depth < MAX_REC_DEPTH:
print("We need to go deeper with low = {}, high = {}, step = {}"
"".format(max(best_val - step * 0.8, low + step / 5),
min(best_val + step * 0.8, up - step / 5), step / 5))
log("We need to go deeper with low = {}, high = {}, step = {}"
"".format(max(best_val - step * 0.8, low + step / 5),
min(best_val + step * 0.8, up - step / 5), step / 5))
one_search(max(best_val - step * 0.8, low + step / 5),
min(best_val + step * 0.8, up - step / 5), step / 5, depth + 1)
示例2: find_best_value
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import get [as 别名]
def find_best_value(self, name, offset):
restrictions = self.get_restrictions(name, offset)
self.write_config(self.working_ini_file)
val = float(self.get_element(name, offset).getAttribute('value'))
log("Trying with default: {} = {}...".format(name, val))
print("Trying with default: {} = {}...".format(name, val))
res = None
for i in range(len(self.config.mzml)):
t = Timer()
t.start()
output = self.run_program(self.get_args(i), False)
print('run_program took %.2f sec' % t.get())
try:
t.start()
tmp_res = self.get_result(output, i)
print('get_result took %.2f sec' % t.get())
res = self.add_res(res, tmp_res) if res is not None else tmp_res
except Exception as e:
log("fail: {}".format(str(e)))
print("fail: {}".format(str(e)))
print("Result = {} with value = {}".format(res, val))
log("Result = {} with value = {}".format(res, val))
best_val = val
best_res = res
# other_best = []
# other = []
results = dict()
results[val] = res
def one_search(low, up, step, depth=0):
nonlocal best_res
nonlocal best_val
val = low
increased = False
while val <= up:
if val in results:
val += step
continue
self.set_attribute(name, 'value', val, offset)
self.write_config(self.working_ini_file)
print("Trying {} = {}...".format(name, val))
log("Trying {} = {}...".format(name, val))
res = None
for i in range(len(self.config.mzml)):
t = Timer()
t.start()
output = self.run_program(self.get_args(i), False)
print('run_program took %.2f sec' % t.get())
try:
t.start()
tmp_res = self.get_result(output, i)
print('get_result took %.2f sec' % t.get())
res = self.add_res(res, tmp_res) if res is not None else tmp_res
except Exception as e:
print("fail: {}".format(str(e)))
log("fail: {}".format(str(e)))
if res is not None:
results[val] = res
print("Result = {} with value = {}".format(res, val))
log("Result = {} with value = {}".format(res, val))
if res is not None and self.cmp_result(res, best_res):
best_res = res
best_val = val
increased = True
# if self.get_element(name, offset).getAttribute('type') != 'int' and depth < MAX_REC_DEPTH:
# print("We need to go deeper with low = {}, high = {}, step = {}"
# "".format(max(val - step * 0.8, low + step / 5),
# min(val + step * 0.8, up - step / 5), step / 5))
# log("We need to go deeper with low = {}, high = {}, step = {}"
# "".format(max(val - step * 0.8, low + step / 5),
# min(val + step * 0.8, up - step / 5), step / 5))
# one_search(max(val - step * 0.8, low + step / 5), min(val + step * 0.8, up - step / 5),
# step / 5, depth + 1)
# other_best = other
# print("Best = {} with value = {}".format(best_res, best_val))
# log("Best = {} with value = {}".format(best_res, best_val))
val += step
if increased and depth < MAX_REC_DEPTH:
print("We need to go deeper with low = {}, high = {}, step = {}"
"".format(max(best_val - step * 0.8, low + step / 5),
min(best_val + step * 0.8, up - step / 5), step / 5))
log("We need to go deeper with low = {}, high = {}, step = {}"
"".format(max(best_val - step * 0.8, low + step / 5),
min(best_val + step * 0.8, up - step / 5), step / 5))
one_search(max(best_val - step * 0.8, low + step / 5),
min(best_val + step * 0.8, up - step / 5), step / 5, depth + 1)
#.........这里部分代码省略.........