本文整理汇总了Python中utils.dprint函数的典型用法代码示例。如果您正苦于以下问题:Python dprint函数的具体用法?Python dprint怎么用?Python dprint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dprint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_session_closed
def on_session_closed(self, session_path):
dprint("__Session Closed__")
#session_path = os.path.basename(session_path)
if session_path in self.Sessions:
self.Sessions[session_path].DisconnectAll()
del self.Sessions[session_path]
self.emit("session-destroyed", session_path)
示例2: distance
def distance(frames_src, frames_target):
'''
Args:
frames_src(FeaturePatch): a single FeaturePatch from the source video
frames_target(FeaturePatch): a single FeaturePatch from a target video from the database
Returns:
int: the distance between the given FeaturePatch in optical flow space
'''
if type(frames_target) == list:
utils.dprint("FOUND A LIST IN DISTANCE")
return sys.float_info.max
dist = 0
for i in range(len(frames_target.features)):
if namespace.FEATURES_ARE_VECTORS and not namespace.WEIGHTED_AVG_DIR:
# If we stored features as Optical Flow Vector
if (type(frames_src.features[i]) != list or type(frames_target.features[i])):
# Something wonky happened with features.
utils.dprint("Odd feature")
continue
# Compute distance
mag_src = math.sqrt((frames_src.features[i][0] + frames_src.features[i][1])**2)
mag_target = math.sqrt((frames_target.features[i][0] + frames_target.features[i][1])**2)
dist += abs((mag_src - mag_target))
else:
# If we stored features as magnitudes of optical flow
dist += abs((frames_src.features[i] - frames_target.features[i]))
return dist
示例3: land
def land(self):
utils.dprint("", 'Landing')
self.at(at_ref, False)
# TODO: implement check for landed
self.move(0.0, 0.0, 0.0, 0.0, False)
self.sleep_time = 1.0
self.__set_landed(True)
示例4: on_session_connected
def on_session_connected(self, session_path):
dprint("session_connected")
#session_path = os.path.basename(session_path)
if session_path in self.Sessions:
session = self.Sessions[session_path]
if not session.Connected:
session.emit("connected")
示例5: solve
def solve(points, tour, currentDist):
startTime = int(time.time())
print("points: " + str(len(tour)) + " start tour" + str(tour))
step = 0
offset = lambda x: 1 if x == 1 else 0
while True:
# The best opt and distance.
startStepTime = int(time.time())
bestDist = currentDist
bestThreeOpt = None
tries = 0
for i in range(1, len(tour) - 3):
for j in range(i + 1, len(tour) - 2):
for k in range(j + 2, len(tour) - offset(i)):
#print("i: %d, j: %d, j+1: %d, k:%d" % (i, j, j +1, k))
tries += 1
threeOpt = getBestThreeOpt(points, tour, currentDist, i, j, k)
if threeOpt.getEndDist() < bestDist:
bestDist = threeOpt.getEndDist()
bestThreeOpt = threeOpt
step += 1
utils.dprint("step: " + str(step) + ", tries: " + str(tries) + ", time: " + fpformat.fix(time.time() - startStepTime, 3))
if bestDist == currentDist:
# If no more improvement we are at a local minima and are done.
print("no more improvement")
break
# Perform the opt.
bestThreeOpt.swap();
currentDist = bestDist
if int(time.time()) - startTime > maxTimeToRun:
# Out of time, return the best we've got.
print("out of time")
break
print("end tour" + str(tour))
return 0, bestDist, tour
示例6: test_python_thread_calls_to_clr
def test_python_thread_calls_to_clr(self):
"""Test calls by Python-spawned threads into managed code."""
# This test is very likely to hang if something is wrong ;)
import System
done = []
def run_thread():
for i in range(10):
time.sleep(0.1)
dprint("thread %s %d" % (thread.get_ident(), i))
mstr = System.String("thread %s %d" % (thread.get_ident(), i))
dprint(mstr.ToString())
done.append(None)
dprint("thread %s %d done" % (thread.get_ident(), i))
def start_threads(count):
for _ in range(count):
thread_ = threading.Thread(target=run_thread)
thread_.start()
start_threads(5)
while len(done) < 50:
dprint(len(done))
time.sleep(0.1)
示例7: main
def main():
dprint("Opening DB ...")
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
dprint("Trying to read table: courses ...")
for row in c.execute('''SELECT * FROM courses'''):
print row
示例8: destroy_server
def destroy_server(self, pattern="opp"):
dprint("Destroy %s server" % pattern)
def on_stopped(server):
dprint("server stopped")
try:
server.Close()
except:
#this is a workaround for lp:735068
dprint("DBus error on ODS server.Close()")
#force close locally
server.DisconnectAll()
gobject.source_remove(timeout)
def on_closed(server):
dprint("server closed")
self.emit("server-destroyed", self.Servers[pattern].object_path)
del self.Servers[pattern]
try:
s = self.Servers[pattern]
s.GHandle("stopped", on_stopped)
s.GHandle("closed", on_closed)
try:
s.Stop()
except:
#ods probably died
gobject.idle_add(on_closed, s)
timeout = gobject.timeout_add(1000, on_stopped, s)
except KeyError:
pass
示例9: format_table_line
def format_table_line(items, hdg=False):
'''take the 13 enties in "items" and return them formatted for out table'''
dprint("*** format_table_line: items passed in (hdg=%s):" % hdg)
dprint(items)
# set up an array of heading vs regular format for each column
line_fmt = [
('{:<10s}', '{:<10s}'),
('{:^7s}', '{:^7d}'),
('{:>9s}', '{:>9.2f}'),
('{:>9s}', '{:>9.2f}'),
('{:^6s}', '{:^6d}'),
('{:^7s}', '{:^7d}'),
('{:^10s}', '{:^10d}'),
('{:^5s}', '{:^5d}'),
('{:^5s}', '{:^5d}'),
('{:^5s}', '{:^5d}'),
('{:^8s}', '{:^+8d}'),
('{:^8s}', '{:^+8d}'),
('{:>6s}', '{:>6s}')]
fmt_idx = 0 if hdg else 1
for i in range(13):
dprint("item[%d] (len %d):" % (i, len(str(items[i]))), items[i])
dprint("format for item: '%s'" % line_fmt[i][fmt_idx])
l = []
for i in range(13):
fmt_str = line_fmt[i][fmt_idx]
l.append(fmt_str.format(items[i]))
res = ''.join(l)
dprint("Returning table line: /%s/" % res)
return res
示例10: step
def step(self,seconds=0.1):
""" Step function 1) senses, 2) executes all layered resources (which tell "body"
which actions to engage, then 3) executes simulator for X seconds (defined by
'seconds' variable."""
self.age += 1
# tell the terminal how old you are
print "Step %i" % (self.age)
state_1 = [x for x in self.all_resources if x.is_on]
self.sense() # sense the world which returns perceptions,
#print "ALL resources", self.all_resources
for r in self.all_resources:
if r.is_on: print "+", r.name
self.execute_all_resources()
#self.execute_reactive_resources()
#self.execute_deliberative_resources()
#self.execute_reflective_resources()
state_2 = [x for x in self.all_resources if x.is_on]
self.turned_on = set(state_2)-set(state_1)
self.turned_off = set(state_1)-set(state_2)
for resource in self.turned_on:
dprint(x.name,"ON: ")
for resource in self.turned_off:
dprint(x.name,"OFF: ")
self.env.do('step_simulation',{'seconds':seconds, 'agent':self.name}) # simulator is paused by default, run for X seconds
time.sleep(seconds+(self.delay*2)) # make sure agent waits as long as simulator
return True
示例11: DateChanged
def DateChanged(self, e):
dprint("One of our dates has changed!", e)
if self.DateRangeValid():
self.results_button.Enable()
self.SetNormalStatus("")
else:
self.results_button.Disable()
示例12: DateRangeValid
def DateRangeValid(self):
'''Is our date range valid?'''
rd_start = self.start_rdate.GetValue()
dprint("Date Range Valid: start=", rd_start)
rd_stop = self.stop_rdate.GetValue()
dprint("Date Range Valid: stop=", rd_stop)
return rd_stop > rd_start
示例13: add_round
def add_round(rnd, rd_list):
'''Add the specified round and list of round details to the DB'''
dprint("Adding to DB:", rnd)
for rd in rd_list:
dprint(rd)
db_cmd_exec('''INSERT INTO rounds(num,
course_num,
rdate)
VALUES(%d,%d,"%s")''' % \
(rnd.num,
rnd.course_num,
rnd.rdate.strftime("%m/%d/%Y")))
for rd in rd_list:
if rnd.num != rd.round_num:
raise Exception("Internal Error: Round Number mismatch!")
db_cmd_exec('''INSERT INTO round_details(round_num, player_num,
fstrokes, bstrokes,
acnt, ecnt, aecnt,
calc_fscore_numerator,
calc_fscore_denominator,
calc_bscore_numerator,
calc_bscore_denominator,
calc_oscore_numerator,
calc_oscore_denominator)
VALUES(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)''' % \
(rd.round_num, rd.player_num,
rd.fstrokes, rd.bstrokes,
rd.acnt, rd.ecnt, rd.aecnt,
rd.calc_fscore.numerator, rd.calc_fscore.denominator,
rd.calc_bscore.numerator, rd.calc_bscore.denominator,
rd.calc_oscore.numerator, rd.calc_oscore.denominator))
示例14: get_max_round_no
def get_max_round_no():
#global RoundList
# try it an alternative way
rnd_nos = [rnd.num for rnd in RoundList.itervalues()]
max_rnd_no = max(rnd_nos)
dprint("Max Round No: %d" % max_rnd_no)
return max_rnd_no
示例15: OnCommit
def OnCommit(self, e):
dprint("OnCommit: %s Round DB requested" % \
('Update' if self.for_update else 'Commit'))
dprint("DB State: edited=%s, calc_done=%s form_up_to_date=%s, " % \
(self.is_edited, self.calc_done, self.data_from_form_up_to_date))
# save the date of our current round, since it can
# change when we get data from the frame
this_round_rdate_saved = self.this_round.rdate
if not self.GetDataFromFrameIfNeeded():
dprint("XXX need to diplay error status here: data invalid!")
return
if not self.is_edited:
raise Exception("Internal Error: Committing non-edited list?")
if self.for_update:
# XXX we should check for this round having the date of a round
# already in the database (not counting this round)
# NOT YET IMPLEMENTED
rdb.modify_round(self.this_round, self.round_details)
else:
# check for duplicate round
for rnd in rdb.RoundList.itervalues():
dprint("Looking at an existing:", rnd)
if rnd.rdate == this_round_rdate_saved:
self.SetErrorStatus("Duplicate Round Date: Change Date")
return False
rdb.add_round(self.this_round, self.round_details)
self.SetNormalStatus("")
rdb.commit_db()
dprint("Updating parent GUI ...")
pub.sendMessage("ROUND UPDATE", round_no=self.this_round)
self.is_edited = False
self.is_committed = True
self.SetCommitButtonState()