本文整理汇总了Python中util.now函数的典型用法代码示例。如果您正苦于以下问题:Python now函数的具体用法?Python now怎么用?Python now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了now函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get
def get(self, cursor=None, user_id=None, venue_id=None, getall=None,
level=None, from_time=None, until_time=None, **kwargs):
red = {'select': 'COUNT(id)',
'table': 'promotion_redemptions',
'where': 'promotion_id = promotions.id'}
promo_qry = {'select': ['id', 'title', 'description',
'passcode', 'start', '[end]', 'maximum',
'creator', 'level',
'(' + util.query(**red) + ') AS redemptions'],
'table': 'promotions',
'where': ['venue_id = ?', 'hidden != 1'],
'order_by': 'id DESC'}
if from_time and until_time:
own_red = {'select': 'COUNT(id)',
'table': 'promotion_redemptions',
'where': ('promotion_id = promotions.id', 'time >= ' + from_time, 'time < ' + until_time, 'user_id = ' + str(user_id))}
promo_qry['select'].append('(' + util.query(**own_red) + ') AS own_redemptions')
if not util.to_bool(getall):
promo_qry['limit'] = 1
promo_qry['where'].append(str(util.now()) + ' >= start')
promo_qry['where'].append('([end] = 0 OR [end] > ' + str(util.now()) + ')')
promo_qry['where'].append('(maximum = 0 OR (' + util.query(**red) + ') < maximum)')
promo_qry['where'].append(level + ' >= level')
promo_qry['order_by'] = 'level DESC, id DESC'
cursor.execute(util.query(**promo_qry), (venue_id,))
row = cursor.fetchone()
if row:
return {t[0]: val for t, val in zip(cursor.description, row)}
else:
return None
cursor.execute(util.query(**promo_qry), (venue_id,))
return [util.row_to_dict(cursor, row) for row in cursor.fetchall()]
开发者ID:ernestoluisrojas,项目名称:ShnergleServer,代码行数:32,代码来源:main.py
示例2: run
def run(self):
try:
self.acquire_mask()
self.session_on = now()
self.on = True
self.ar.begin_saving()
self.cam.begin_saving()
self.cam.set_flush(True)
self.start_acq()
# main loop
threading.Thread(target=self.deliver_trial).start()
threading.Thread(target=self.update_eyelid).start()
while True:
if self.trial_on or self.paused:
continue
if self.session_kill:
break
moving = self.determine_motion()
eyelid = self.determine_eyelid()
if self.deliver_override or ((now()-self.trial_off>self.min_iti) and (not moving) and (eyelid)):
self.trial_flag = True
self.deliver_override = False
self.end()
except:
logging.error('Session has encountered an error!')
raise
开发者ID:bensondaled,项目名称:eyeblink,代码行数:33,代码来源:session.py
示例3: run_ica
def run_ica():
log('loading data')
start = util.now()
voxels, xdim, ydim, zdim = load_data()
log(' elapsed: {}'.format(util.elapsed(start)))
log('running independent component analysis')
start = util.now()
ica = decomposition.FastICA(n_components=64, max_iter=200)
sources = ica.fit_transform(voxels)
sources = to_dataframe(sources, load_subject_ids(), ['X{}'.format(i) for i in range(64)])
log(' elapsed: {}'.format(util.elapsed(start)))
log('calculating correlations between voxel and component time courses')
start = util.now()
correlations = []
for voxel in voxels.columns[:32]:
voxel = voxels[voxel]
max_correlation = 0
for source in sources.columns:
source = sources[source]
correlation = np.corrcoef(voxel, source)
if correlation > max_correlation:
max_correlation = correlation
correlations.append(max_correlation)
log(' elapsed: {}'.format(util.elapsed(start)))
开发者ID:rbrecheisen,项目名称:scripts,代码行数:27,代码来源:run_ica.py
示例4: get
def get(self):
hour = util.now().hour
if hour < 12 or hour > 22:
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Delayed.')
return
emails = [x for x in model.Email.all().fetch(1000) if x.confirmed]
phones = [x for x in model.Phone.all().fetch(1000) if x.confirmed]
count = 0 # количество поставленных в очередь событий
now = util.now()
# Отправка уведомлений за неделю
d1 = now + datetime.timedelta(config.FAR_LIMIT)
for event in model.Event.gql('WHERE far_sent = :1 AND date < :2 AND date > :3', False, d1, now).fetch(10):
count += self.notify(event, emails, phones, True)
event.far_sent = True
event.put()
# Отправка уведомлений за сутки
d1 = now + datetime.timedelta(config.SOON_LIMIT)
for event in model.Event.gql('WHERE soon_sent = :1 AND date < :2 AND date > :3', False, d1, now).fetch(10):
count += self.notify(event, emails, phones, False)
event.soon_sent = True
event.far_sent = True
event.put()
if count:
logging.info('Queued %u notifications.' % count)
开发者ID:umonkey,项目名称:gae-event-announcer,代码行数:29,代码来源:handlers.py
示例5: to_phase
def to_phase(self, ph):
self.phase_times[self.current_phase][1] = now()
self.phase_times[ph][0] = now()
self.current_phase = ph
self.phase_start = now()
self.hinted = False
if ph == self.PHASE_END:
# sanity check. should have been rewarded only if solely licked on correct side
if (
self.lick_rule_side
and self.lick_rule_phase
and (not self.licked_early)
and (not self.multiple_decisions)
and self.use_trials
):
assert bool(self.rewarded) == (
any(self.lick_phase_licks[self.trial["correct"]])
and (not any(self.lick_phase_licks[-self.trial["correct"] + 1]))
)
if not self.rewarded:
if self.use_trials:
self.trial_corrects.append(self.trial["correct"])
else:
self.trial_corrects.append(self.X)
# determine trial outcome
if not self.use_trials:
if any(self.lick_phase_licks):
outcome = self.COR
else:
outcome = self.INCOR
elif self.use_trials:
if self.rewarded and self.lick_rule_side and not self.multiple_decisions:
outcome = self.COR
elif self.rewarded and ((not self.lick_rule_side) or self.multiple_decisions):
lpl_min = np.array([min(i) if len(i) else -1 for i in self.lickph_andon_licks])
if np.all(lpl_min == -1):
outcome = self.NULL
else:
lpl_min[lpl_min == -1] = now()
if np.argmin(lpl_min) == self.trial["correct"]:
outcome = self.COR
else:
outcome = self.INCOR
elif self.trial_kill:
outcome = self.KILLED
elif self.licked_early:
outcome = self.EARLY
# this BOTH logic no longer works bc i include reward phase licks in lickphaselicks. both will never show up, though it still can *rarely* be a cause for trial failure
# elif (any(self.lick_phase_licks[self.L]) and any(self.lick_phase_licks[self.R])):
# outcome = self.BOTH
elif any(self.lick_phase_licks[-self.trial["correct"] + 1]):
outcome = self.INCOR
elif not any(self.lick_phase_licks):
outcome = self.NULL
self.trial_outcomes.append(outcome)
开发者ID:bensondaled,项目名称:puffs,代码行数:58,代码来源:session.py
示例6: _finish_render
def _finish_render(self, state, tsrender):
# finish by adding the current state as the reading
now = util.now()
state = self.translate_state(state)
if self.autoadd:
self.add(now, state)
tsrender = dict(tsrender)
tsrender['Readings'] = [(util.now() * 1000, state)]
return tsrender
开发者ID:Alwnikrotikz,项目名称:smap-data,代码行数:11,代码来源:actuate.py
示例7: hold_open
def hold_open(self, side, dur):
if self.is_open[side]:
if self.force_next:
self._close(side)
elif not self.force_next:
return
self._open(side)
start = now()
while now()-start < dur:
pass
self._close(side)
开发者ID:bensondaled,项目名称:puffs,代码行数:11,代码来源:valve.py
示例8: set
def set(self, cursor=None, user_id=None, staff_user_id=None, venue_id=None,
manager=None, promo_perm=None, delete=None, **kwargs):
if util.to_bool(delete):
qry = {'delete': 'venue_staff',
'where': ('user_id = ?', 'venue_id = ?')}
cursor.execute(util.query(**qry), (staff_user_id, venue_id))
qry = {'delete': 'venue_managers',
'where': ('user_id = ?', 'venue_id = ?')}
cursor.execute(util.query(**qry), (staff_user_id, venue_id))
elif util.to_bool(manager):
qry = {'select': 'id',
'table': 'venue_managers',
'where': ('user_id = ?', 'venue_id = ?'),
'order_by': 'id',
'limit': 1}
cursor.execute(util.query(**qry), (staff_user_id, venue_id))
res = cursor.fetchone()
if not res:
qry = {'delete': 'venue_staff',
'where': ('user_id = ?', 'venue_id = ?')}
cursor.execute(util.query(**qry), (staff_user_id, venue_id))
qry = {'insert_into': 'venue_managers',
'columns': ('user_id', 'venue_id', 'time')}
cursor.execute(util.query(**qry), (staff_user_id, venue_id,
util.now()))
else:
qry = {'select': 'id',
'table': 'venue_staff',
'where': ('user_id = ?', 'venue_id = ?'),
'order_by': 'id',
'limit': 1}
cursor.execute(util.query(**qry), (staff_user_id, venue_id))
res = cursor.fetchone()
if not res:
qry = {'delete': 'venue_managers',
'where': ('user_id = ?', 'venue_id = ?')}
cursor.execute(util.query(**qry), (staff_user_id, venue_id))
qry = {'insert_into': 'venue_staff',
'columns': ('user_id', 'venue_id', 'time',
'promo_perm')}
cursor.execute(util.query(**qry), (staff_user_id, venue_id,
util.now(),
1 if util.to_bool(promo_perm) else 0))
else:
qry = {'update': 'venue_staff',
'set_values': ('promo_perm'),
'where': ('user_id = ?', 'venue_id = ?')}
cursor.execute(util.query(**qry), (1 if util.to_bool(promo_perm) else 0,
staff_user_id, venue_id))
return True
开发者ID:ernestoluisrojas,项目名称:ShnergleServer,代码行数:50,代码来源:main.py
示例9: run
def run(self):
now()
lib = "CLEyeMulticam.dll"
dll = ctypes.cdll.LoadLibrary(lib)
dll.CLEyeGetCameraUUID.restype = GUID
dll.CLEyeCameraGetFrame.argtypes = [c_void_p, c_char_p, c_int]
dll.CLEyeCreateCamera.argtypes = [GUID, c_int, c_int, c_float]
self.vc = Ps3Eye(self.idx, self.color_mode, self.resolution_code, self.frame_rate, dll=dll)
settings = [ (CLEYE_AUTO_GAIN, self.auto_gain),
(CLEYE_AUTO_EXPOSURE, self.auto_exposure),
(CLEYE_AUTO_WHITEBALANCE,self.auto_wbal),
(CLEYE_GAIN, self.gain),
(CLEYE_EXPOSURE, self.exposure),
(CLEYE_WHITEBALANCE_RED,self.wbal_red),
(CLEYE_WHITEBALANCE_BLUE,self.wbal_blue),
(CLEYE_WHITEBALANCE_GREEN,self.wbal_green),
(CLEYE_VFLIP, self.vflip),
(CLEYE_HFLIP, self.hflip),
]
self.vc.configure(settings)
self.vc.start()
if self.save_name != None:
self.vid_name = self.save_name+'.avi'
self.vidts_name = self.save_name+'.tstmp'
self.vw = cv2.VideoWriter(self.vid_name,0,self.frame_rate,frameSize=self.resolution,isColor=False)
self.vidts_file_temp = open(self.vidts_name, 'a')
self.offset.value = self.clock_sync_obj.value-now()
self.vidts_file_temp.write('%0.20f\n'%self.offset.value)
if not self.vw.isOpened():
logging.error('Video writer failed to open')
raise Exception('Video writer failed to open')
# begin true run
time.sleep(0.1)
while self.READING.value:
val = False
val,fr = self.vc.get_frame()
if val:
self.ts.value = now()#(time.time(),time.clock(), now())
self.cS[:] = np.fromstring(fr, np.uint8)
if self.SAVING.value and self.save_name:
self.vw.write(mp2np(self.cS).reshape(self.read_dims))
self.vidts_file_temp.write('%0.20f,'%self.ts.value)
if self.save_name:
self.vw.release()
self.vidts_file_temp.close()
self.thread_complete.value = 1
开发者ID:bensondaled,项目名称:puffs,代码行数:50,代码来源:cameras.py
示例10: simu
def simu(options):
itera = 0
#################################
# Begin simu
if(options.reset):
if(not prims.initDb()):
raise util.SimuException("Market is not opened")
begin = util.getAvct(None)
with util.DbConn(const) as dbcon:
with util.DbCursor(dbcon) as cursor:
util.writeMaxOptions(cursor,options)
for user in util.nameUsers():
prims.createUser(cursor,user)
if(options.CHECKQUALITYOWNERSHIP):
util.setQualityOwnership(cursor,True)
##################################
if((not scenarii.threadAllowed(options.scenario)) and options.threads>1):
raise Exception("This scenario cannot be run in thread")
_begin = util.now()
if(options.threads==1):
user = util.nameUser(0)
scenarii.simuInt((options,user))
else:
# run in theads
ts = []
for i in range(options.threads):
user = util.nameUser(i)
t = threa.ThreadWithArgs(func=scenarii.simuInt,args=(options,user),name=user)
t.start()
ts.append(t)
for t in ts:
t.join()
itera = options.iteration * options.threads
duree = util.duree(_begin,util.now())
##################################
# Terminate simu
terminate(begin,duree,itera,options)
return
开发者ID:olivierch,项目名称:openBarter,代码行数:48,代码来源:simu.py
示例11: subscribe
def subscribe(self, onReceive, onTimeout,
timeFrom = 0, timeTo = sys.maxint,
minId = 0, timeoutSec = 0):
""" subscribe messages within a specific time span.
@params onReceive: if the interested messages are
retrieved, onReceive will be invoked to notify
the subscribers.
@params onTimeout: if subscriber waits for more than
`timeoutSec` seconds, onTimeout will be invoked.
@params timeFrom: only retrieve messages after timestamp
`timeFrom`; time is represented in unix time.
@params timeTo: only retrieve messages before timestamp
`timeTo`; time is represented in unix time.
@params minId: this is HACK...
"""
messages = self._flatten(self.messageQueue[timeFrom: timeTo], minId)
messages = list(messages)
if len(messages) != 0 or timeoutSec == 0:
onReceive(messages)
return
waitUntil = now() + timeoutSec
subscription = (timeFrom, timeTo, onReceive, onTimeout)
self.subscribers.setdefault(waitUntil, []).append(subscription)
开发者ID:SpeedoProject,项目名称:Speedo,代码行数:26,代码来源:pubsub.py
示例12: worker_main
def worker_main(anime, shared):
try:
timeline = shared['timeline']
# pre-processing
anchor = create_title_link(generate_uri(anime.search_title))
filtered = filter_tuple(anchor)
latest_episode = episodes(filtered)[0]
logstate(anime, filtered, latest_episode)
if anime.latest_episode == -1 or latest_episode > anime.latest_episode:
# update latest episode information
anime.latest_episode = latest_episode
# remove all occurrence of this animation from timeline then update shared dictionary
for index in range(len(timeline)-1, -1, -1):
if timeline[index][0].title == anime.title:
timeline.pop(index)
shared['timeline'] = timeline
# send an email for subscriber
with io.StringIO() as strbuf:
print('Transmission DateTime: %s' % nowstr(), file=strbuf)
print('Anime: %s' % anime.title, file=strbuf)
print('Latest episode: %s' % latest_episode, file=strbuf)
print(filtered, file=strbuf)
print('', file=strbuf)
sendmail(settings.recipients, anime, strbuf)
# may fail when nyaa torrent suffering DDOS
except Exception:
with open('{startup}_{filename}'.format(
startup=now().strftime('%Y%m%d_%H%M%S'), filename='fatal.txt'), 'a') as fatal_log:
traceback.print_exc(file=fatal_log)
开发者ID:makerj,项目名称:nyaa-notifier,代码行数:32,代码来源:nyaa-notifier.py
示例13: run
def run(self):
logger.info("Starting matlab engine")
self.eng = matlab.engine.start_matlab()
self.eng.workspace['xtmp_codepath'] = str(self.sim.cd_path)
self.future = Future()
self.eval("cd(xtmp_codepath);", nargout=0)
self.sim.t_started = now()
#TODO security
self.future = Future()
self.feval(self.sim.entry_point, self.sim.init_params, nargout=0, prefix='%s = ' % str(self.sim.handle_name))
while True:
#t, (action, args, future, persist) = self.sim.q.get()
data, self.future = self.sim.q.get()
print "Popped "+repr(data)+" from Q"
if len(data) == 2:
statement, nargout = data
self.eval(statement, nargout=nargout)
elif len(data) == 3:
fn_lhs, args, nargout = data
self.feval(fn_lhs, args, nargout=nargout)
else:
assert False
self.sim.q.task_done()
开发者ID:ksikka,项目名称:matlab-simserver,代码行数:29,代码来源:simwrapper.py
示例14: make_wish
def make_wish(self,wish=None):
try:
data = {
'title' : xhtml_escape(self.get_argument('title',default='')),
'content' : xhtml_escape(self.get_argument('content',default='')),
'is_public' : 1 if self.get_argument('is_public',default=None)== 'on' else 0,
'is_anonymous' :1 if self.get_argument('is_anonymous',default=None)=='on' else 0,
'has_cometrue' :0,
'is_share' : 1 if self.get_argument('is_share',default=None)=='on' else 0,
'poster' : self.get_argument('poster',default=None),
'ctime' : util.now(),
'stat' : self.get_argument('stat',default='active'),
'uid' : self.current_user.uid
}
validate(data,self.schema);
if not wish : wish = models.Wish()
for item in data :
setattr(wish,item,data[item])
self.session.add(wish)
self.session.commit()
is_active = data['stat'] == 'active'
self.update_tag(wish,is_active)
self.update_friends(wish,is_active)
return wish
except ValueError,e:
self.write(e.message)#TODO for debug
self.json_write(code='000')
开发者ID:filod,项目名称:vixi,代码行数:29,代码来源:handlers.py
示例15: _flush
def _flush(self, force=False):
"""Send out json-packed report objects to registered listeners.
:param boolean force: if True, ignore ``MinPeriod``/``MaxPeriod``
and force the reporting metadata to disk
:rtype: a :py:class:`twisted.internet.task.DeferredList`
instance which will fire when deliver to all subscribers has
finished, or errBack when any fail
"""
deferList, deleteList = [], []
for sub in self.subscribers:
now = util.now()
if sub.get('ExpireTime', now) < now:
# remove expired reports
deleteList.append(sub['uuid'])
# either we've gone too long without trying and so need to
# deliver a report or else we have new data and have
# waited for at least MinPeriod since the last report.
elif force or sub.deliverable():
d = defer.maybeDeferred(sub.attempt)
# we don't need an errBack for this case since we want
# to propagate the error and don't need to do any
# cleanup
deferList.append(d)
map(self.del_report, deleteList)
d = defer.DeferredList(deferList, fireOnOneErrback=True, consumeErrors=True)
if force: d.addBoth(self.save_reports)
return d
开发者ID:ahaas,项目名称:smap,代码行数:30,代码来源:reporting.py
示例16: preview
def preview(self, completed, planned, tags):
assert cherrypy.request.method.upper() == 'POST'
today = util.today().toordinal()
now = util.now()
post = Post(('<preview>', today, now, completed.decode("utf-8"), planned.decode("utf-8"), tags.decode("utf-8")))
return render('preview.xhtml', post=post)
开发者ID:clopez,项目名称:mozilla-weekly-updates,代码行数:7,代码来源:main.py
示例17: css_class
def css_class(self):
classes = ''
if self.soon_sent:
classes += ' soon'
if self.date < util.now():
classes += ' past'
return classes.strip()
开发者ID:umonkey,项目名称:gae-event-announcer,代码行数:7,代码来源:model.py
示例18: callback
def callback(self, *args):
""" register the callback function when the job is finished """
stat = 'Success' if args[0] == 0 else 'Fail'
job = args[2]
dic = {'status': stat, 'stop_time': now()}
db.update_runtime(dic, {'job_name': job.name})
logger.info('finish job %s with status %s' % (job.name, stat))
开发者ID:zaviichen,项目名称:scheduler,代码行数:7,代码来源:schedule.py
示例19: EveryNCallback
def EveryNCallback(self):
self.last_ts = now()
with self._data_lock:
#self.read_data[:] = 0
self.ReadAnalogF64(self.read_buffer_size, self.timeout, pydaq.DAQmx_Val_GroupByChannel, self.read_data, self.effective_buffer_size, pydaq.byref(self.read), None)
self._newdata_event.set()
return 0
开发者ID:bensondaled,项目名称:puffs,代码行数:7,代码来源:daq.py
示例20: to_dict
def to_dict(self):
return { 'id' : self.id,
'cd_path': self.cd_path,
'username': self.username,
'entry_point': self.entry_point,
'init_params': self.init_params,
't_started' : self.t_started,
't_elapsed' : now() - self.t_started }
开发者ID:ksikka,项目名称:matlab-simserver,代码行数:8,代码来源:simwrapper.py
注:本文中的util.now函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论