本文整理汇总了Python中models.Experiment.current_trial方法的典型用法代码示例。如果您正苦于以下问题:Python Experiment.current_trial方法的具体用法?Python Experiment.current_trial怎么用?Python Experiment.current_trial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Experiment
的用法示例。
在下文中一共展示了Experiment.current_trial方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Dictator
# 需要导入模块: from models import Experiment [as 别名]
# 或者: from models.Experiment import current_trial [as 别名]
class Dictator(object):
executioner = None
experiment = None
eventObjects = None
def __init__(self,protocol,nickname):
dt = datetime.now()
self.experiment = Experiment(name=nickname,protocol=protocol,time_start=dt)
self.experiment.save()
self.executioner = Executioner()
libarian.init_db_cache(self.experiment)
# self.lock = Lock()
def current_trial(self):
return poke_cache(str(self.experiment.id)+'.trial_current',self.experiment.current_trial(),secs=60)
def start(self):
self.executioner.start()
def complete(self):
current_trial = self.experiment.current_trial()
if current_trial!=None:
current_trial.duration = libarian.time_since_trial(self.experiment.id)
current_trial.save()
self.experiment.total_duration = libarian.time_since_exp(self.experiment.id)
self.experiment.set_trials_completed()
self.experiment.time_complete = datetime.now()
self.experiment.save()
# libarian.clear_db_cache()
def new_trial(self):
total_time = libarian.time_since_exp(self.experiment.id)
trial_time = libarian.time_since_trial(self.experiment.id)
new_trial = Trial(experiment=self.experiment, duration=Decimal(0.0),completed=False,time_start=datetime.now())
new_trial.save()
old_trial = libarian.get_trial_current(self.experiment.id)
if old_trial!=None:
w.NextTrialThread(old_trial,new_trial,trial_time,total_time,self.experiment).start()
else:
w.NewHappening('TRL','New Trial',total_time,self.experiment).start()
libarian.set_trial_current(new_trial,self.experiment.id)
self.executioner.interval_pointer = 0
self.executioner.is_new_trial = True
libarian.set_interval_start(datetime.now(),self.experiment.id)
def check_emulate_action(self,action_type):
if em.Action.objects.filter(type=action_type).count()==1:
act = em.Action.objects.filter(type=action_type)[0]
try:
ea = EmulateAction.objects.filter(experiment=self.experiment, action=act).latest('id')
self.action_happen('%s'%(action_type),action_type,ea.time_occurred)
ea.delete()
return True
except ObjectDoesNotExist:
return False
else:
return False
def run_simulate_events(self):
event_ids = SimEvent.objects.filter(experiment=self.experiment)
for se in event_ids:
self.eventObjects[se.eventid].perform(time=se.time_occurred)
event_ids.delete()
def action_happen(self,description,keyname,given_time=None):
if given_time==None:
time = libarian.time_since_exp(self.experiment.id)
else:
time = given_time
thready = w.NewHappening('ACT',keyname,description,time,self.experiment)
thready.start()
def event_happen(self,description,keyname,given_time=None):
if given_time==None:
time = libarian.time_since_exp(self.experiment.id)
else:
time = given_time
thready = w.NewHappening('EVT',keyname,description,time,self.experiment)
thready.start()
def interval_happen(self,description,keyname):
time = libarian.time_since_exp(self.experiment.id)
thready = w.NewHappening('ITL',keyname,description,time,self.experiment)
thready.start()