def submit( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> List[Dict]: userid = tracker.current_state()["sender_id"] place = str(tracker.get_slot("place")) time = ast.literal_eval(str(tracker.get_slot("time"))) time_start = iso8601.parse_date(str(time['from'])) time_end = iso8601.parse_date(str(time['to'])) planner = ph.restore(self.__storage_path, userid) planner.set_home(place) planner.set_planning_times( globals.to_minutes(time_start.hour, time_start.minute), globals.to_minutes(time_end.hour, time_end.minute)) ph.store(self.__storage_path, userid, planner) dispatcher.utter_message("Thank you! I have set your home location to " + place + " and will plan your day between " + time_start.strftime("%I:%M %p") + " and " + time_end.strftime("%I:%M %p") + ".") return []
def save_specific_event(self, dispatcher: CollectingDispatcher, tracker: Tracker, userid, place, event_name, time): time = ast.literal_eval(time) time_start = iso8601.parse_date(str(time["from"])) time_end = iso8601.parse_date(str(time["to"])) planner = ph.restore(self.__storage_path, userid) try: planner.add_event( Event(event_name, Event.EventType.SPECIFIC, start=globals.to_minutes(time_start.hour, time_start.minute), end=globals.to_minutes(time_end.hour, time_end.minute), place=place), [time_start.day, time_start.month, time_start.year]) except Exception: dispatcher.utter_message( "It seems like you already planned an event at this time.") return [] ph.store(self.__storage_path, userid, planner) response = ("Alright. I'm planning the event " + event_name + " at " + place + " on " + time_start.strftime("%A") + ", " + time_start.strftime("%d.%m.%y") + " from " + time_start.strftime("%I:%M %p") + " to " + time_end.strftime("%I:%M %p") + ".") dispatcher.utter_message(response)
def __init__(self): self.__time_begin_day = globals.to_minutes(8, 0) # 8 A.M. self.__time_end_day = globals.to_minutes(20, 0) # 8 P.M. self.__days = [] self.__events = [] self.__unplanned_events = [] # list of events that need to be planned self.__home = "Berlin" # start everday at this location self.__max_events = 99 # maximum number of events per day self.__round_travel_time = 15 # arrival and departure times will be rounded to the next quarter hours
def import_ics(self, path): globals.debug("importing ics file from " + path + " ...") ics_file = open(path, 'rb') ical = icalendar.Calendar.from_ical(ics_file.read()) for ics_event in ical.walk(): if ics_event.name == "VEVENT": title = ics_event.get('summary') start = ics_event.decoded('dtstart') end = ics_event.decoded('dtend') place = ics_event.get('location') globals.debug("importing event " + title) #print(ics_event.decoded('dtstamp')) rrule = ics_event.get('rrule') if rrule: rrule_last = rrule['UNTIL'][0] curr_day = start new_event = Event( title, Event.EventType.SPECIFIC, start=globals.to_minutes(start.hour, start.minute), end=globals.to_minutes(end.hour, end.minute), place=place) while curr_day <= rrule_last: # try/except bc of colliding events -> should at least raise an error msg or sth. globals.debug("importing recurring event " + title + " on " + str(curr_day)) try: self.add_event( new_event, [curr_day.day, curr_day.month, curr_day.year]) except Exception: pass finally: if 'WEEKLY' in rrule['FREQ'][0]: curr_day = curr_day + dt.timedelta(days=7) else: break else: # try/except bc of colliding events -> should at least raise an error msg or sth. try: self.add_event(new_event, [start.day, start.month, start.year]) except: continue ics_file.close() globals.debug("finished import!")
import googledistancematrix as gdm from googledistancematrix import querent from googledistancematrix.querent import Querent import settings, globals settings.init() gdm_querent = gdm.querent.Querent( api_key=settings.GOOGLE_DISTANCE_MATRIX_API_KEY) gdm_querent.set_travel_mode(querent.TravelMode.TRANSIT) p = Planner() p.set_home("Str d Pariser Kommune 30") p.set_planning_times(globals.to_minutes(8, 0), globals.to_minutes(20, 0)) p.set_max_events(3) p.add_event( Event("Kuchenbacken", Event.EventType.SPECIFIC, start=globals.to_minutes(17, 45), end=globals.to_minutes(19, 00), place="Str d Pariser Kommune 30"), [30, 6, 2019]) p.add_event( Event("Buch lesen", Event.EventType.SPECIFIC, start=globals.to_minutes(13, 20), end=globals.to_minutes(14, 00), place="Erwin Schrödinger Zentrum"), [29, 6, 2019])
import settings, globals, logging settings.init() unpickle = True gdm_querent = gdm.querent.Querent( api_key=settings.GOOGLE_DISTANCE_MATRIX_API_KEY) gdm_querent.set_travel_mode(querent.TravelMode.TRANSIT) if not unpickle: # create new planner object and pickle it p = Planner() p.set_home("Str d Pariser Kommune 30") p.set_planning_times(globals.to_minutes(8, 0), globals.to_minutes(20, 0)) p.set_max_events(8) p.import_ics("marc_uni.ics") pickle.dump(p, open("planner_pickle.pkl", "wb"), protocol=pickle.HIGHEST_PROTOCOL) else: # try to load an existing pickled planner object try: p = pickle.load(open("planner_pickle.pkl", "rb")) except FileNotFoundError: logging.error("Test Planner Pickle: Restore File or Folder not found.") exit()
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: userid = str(tracker.current_state()["sender_id"]) try: old_place = place place = self.__querent.get_place_address(tracker.get_slot('place')) except Exception: dispatcher.utter_message( "Uh oh, I probably made at mistake processing the location you entered, but you may try again :)" ) return [] try: time = json.loads(tracker.get_slot('time').replace("'", '"')) if time['additional_info']['type'] == 'interval': time_start = dt.strptime( str(time['additional_info']['from']['value']), '%Y-%m-%dT%H:%M:%S.000+02:00') time_end = dt.strptime( str(time['additional_info']['to']['value']), '%Y-%m-%dT%H:%M:%S.000+02:00') - datetime.timedelta( hours=1) else: dispatcher.utter_message( "For planning events using an exact time frame I need a start and an end time." ) except Exception: dispatcher.utter_message( "Uh oh, I probably made at mistake processing the time you entered, but you may try again :)" ) return [] #event_name = tracker.latest_message['text'] event_name = tracker.get_slot('event_name') if place: planner = ph.restore(self.__storage_path, userid) try: planner.add_event( Event(event_name, Event.EventType.SPECIFIC, start=globals.to_minutes(time_start.hour, time_start.minute), end=globals.to_minutes(time_end.hour, time_end.minute), place=place), [time_start.day, time_start.month, time_start.year]) except Exception: dispatcher.utter_message( "It seems like you already planned an event at this time.") return [] ph.store(self.__storage_path, userid, planner) response = ("Alright. I'm planning the event " + event_name + " at " + place + " on " + time_start.strftime("%A") + ", " + time_start.strftime("%d.%m.%y") + " from " + time_start.strftime("%I:%M %p") + " to " + time_end.strftime("%I:%M %p") + ".") dispatcher.utter_message(response) else: dispatcher.utter_message("I'm sorry but I couldn't find \"" + old_place + "\" :(") return []
from planner.plannertoimage import PlannerToImage from planner.planner import Planner import globals from datetime import datetime as dt if __name__ == "__main__": planner = Planner() planner.set_home("Str d Pariser Kommune 30") planner.set_planning_times( globals.to_minutes(8, 0), globals.to_minutes(20, 0) ) planner.set_max_events(8) planner.import_ics('import_planner_draw.ics') #planner.import_ics('exported_calendar.ics') print(planner) PlannerToImage(planner, dt.today()).draw_image('test_image.png') #PlannerToImage(planner, dt(2019,4,11)).draw_image('test_image.png')