def on_define(tmr): definition = grab_instance(DefineEvent, tmr).definition.filler define = fr.kblookup('DefineEvent')[0] base = define.base.filler if definition.at_least(Location): global current_location definition.longitude = base.longitude definition.latitude = base.latitude definition.stay = base.stay current_location = definition # need to remove because we already remember this location under a different concept fr.forget(define.base.filler) if definition.at_least(Activity): global current_activity definition.location = base.location current_activity = definition fr.store(definition) fr.forget(define) DefineEvent.definition.filler_class = Concept #DefineEvent.base.filler_class = Concept refresh()
def on_move(tmr): global clock global current_location global current_activity if current_activity: current_activity.time.filler.end = clock.quarters current_activity = None current_location = grab_instance(MoveEvent, tmr).to.filler refresh() clock.tick() print 'Moved to {0}'.format(current_location) loc_matches = filter(lambda loc: loc.longitude == current_location.longitude and loc.latitude == current_location.latitude, fr.kblookup('Location')) if loc_matches: current_location = loc_matches[0] if not current_location.__class__ is Location: print 'Aha! Checking-in at {0}'.format(current_location) else: fr.store(current_location)
def ask_define(what): global current_location global current_activity global clock if not fr.kblookup('DefineEvent'): define = DefineEvent() define.base.filler = what DefineEvent.definition.filler_class = what.__class__ fr.store(define, True) if what.__class__ == Location: print 'What is this place called?' elif what.__class__ == Activity: print 'What is that you are doing, %username%?'
def observe(tmr): global clock global current_location global current_activity wake = grab_instance(AgentWakeEvent, tmr) if wake: current_location = wake.where.filler fr.store(current_location) else: current_location.stay += 1 refresh() clock.tick() print 'Staying at {0} for {1} quarters'.format(current_location, current_location.stay) acts = fr.kblookup('Activity') if acts: a = sorted(acts, key=lambda a: abs(a.time.filler.start - clock.quarters))[0] if abs(a.time.filler.start - clock.quarters) < 5: print 'Hurry, %username%, {0} is starting at {1} in less than an hour!'.format(a.__class__.__name__, a.location.filler) return # if idle at an unknown loc if current_location.stay > 3 and current_location.__class__ == Location: print 'You seem to hang out here a lot.' ask_define(current_location) return # if idle with no known activity if current_location.stay > 7 and not current_activity: init_activity() print 'I see you\'re doing something.' ask_define(current_activity) return # if idle with a known activity for too long if current_location.stay > 96 and current_activity: print 'Wow, you seem really into it. Are you still doing {0}, %username%?'.format(current_activity) return