def run_instance(): if stateVar.t_instance is None: stateVar.currentTime = time.time() # Create life instance global instance_id instance_id = runtime.create_instance(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION) # Init instance knowledge runtime.setInstanceKnowledge(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id, {'tz':localTz}) runtime.setInstanceKnowledge(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id, {'time':stateVar.currentTime}, 'merge') # Register webActions get_and_register_webActions() # Start update instance in a thread stateVar.t_instance = UpdateLifeThreadClass() stateVar.t_instance.start() # Create life agent with open(os.path.join(working_dir, '../knowledge/ContextualAlerts.json')) as data_file: data = json.load(data_file) data['google_userId'] = request.query['user'] stateVar.agentId = runtime.create_agent(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id,'src/decision/ContextualAlerts.bt', data) return update_data()
def _run(self): previousTickTime = stateVar.currentTime while not self.event.isSet(): try: success = runtime.update_instance(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id, instance_step) except OSError, e: print e runtime.delete_instance(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id) gevent.sleep(instance_step) currentTickTime = time.time() stateVar.currentTime = stateVar.currentTime+stateVar.speedFactor*(currentTickTime-previousTickTime) previousTickTime = currentTickTime runtime.setInstanceKnowledge(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id, {'time':stateVar.currentTime}, 'merge')
def run_instance(): if stateVar.t_instance is None: stateVar.currentTime = time.time() global instance_id instance_id = runtime.create_instance(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION) # Init instance knowledge runtime.setInstanceKnowledge(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id, {'tz': localTz}) runtime.setInstanceKnowledge(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id, {'time': stateVar.currentTime}, 'merge') # Register webActions get_and_register_webActions() # Start update instance in a thread stateVar.t_instance = UpdateLifeThreadClass() stateVar.t_instance.start() with open( os.path.join( working_dir, '../knowledge/ContextualAlerts.json')) as data_file: data = json.load(data_file) data['google_userId'] = request.query['user'] stateVar.agentId = runtime.create_agent( CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id, 'src/decision/ContextualAlerts.bt', data) return update_data()
def _run(self): previousTickTime = stateVar.currentTime while not self.event.isSet(): try: success = runtime.update_instance(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id, instance_step) except OSError, e: print e runtime.delete_instance(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id) gevent.sleep(instance_step) currentTickTime = time.time() stateVar.currentTime = stateVar.currentTime + stateVar.speedFactor * ( currentTickTime - previousTickTime) previousTickTime = currentTickTime runtime.setInstanceKnowledge(CRAFT_DEMO_SAC_USER, CRAFT_DEMO_SAC_PROJECT, CRAFT_DEMO_SAC_VERSION, instance_id, {'time': stateVar.currentTime}, 'merge')