def timeadd_profile(profile, time_args): """Checks if first argument is a date. If date, inserts time into date. Else, it inserts into today. """ _date = None if "-" in time_args[0]: if h.validate_date(time_args[0]): _date = time_args[0] time_args = time_args[1:] secs = h.get_sec(time_args) if _date: profile = h.add_time(profile, secs, _date) else: profile = h.add_time(profile, secs) db.update(profile)
def get_overlaps(slots, min_gap, duration): '''gets the dict of form: {slot: [overlapping slot1, overlapping slot2, ...], etc.}''' OVERLAPS = {} for i_slot in slots: i_start_time = helpers.get_start_time(i_slot) i_end_time = helpers.add_time(i_start_time, duration) i_day = i_slot[:2] for j_slot in slots: j_start_time = helpers.get_start_time(j_slot) j_day = j_slot[:2] if (i_start_time < j_start_time) and (i_day == j_day) and ( (i_end_time != j_start_time) and (j_start_time < helpers.add_time(i_end_time, min_gap))): if j_slot not in OVERLAPS.keys(): OVERLAPS[j_slot] = [i_slot] else: OVERLAPS[j_slot].append(i_slot) return (OVERLAPS)
def schedule(self): """Takes and activities dictionary and adds start and end times Pass in the practice or individual start time, then it will increment""" start_time = self.time activities = self.activities() for activity in activities: activity.start_time = start_time activity.end_time = add_time(start_time, activity.duration) start_time = activity.end_time return activities
def stop_timer(profile, name=None): if name: profile = db.read(db.Profile, name[0]) if profile.start == True: total = time.time() - profile.begin profile = h.add_time(profile, total) profile.start = False db.update(profile) print(f"> Stopped timer for {profile.name}") else: print(f"> Profile {profile.name} has not been started.")
def schedule(self): """Takes workout activities and adds start and end times Pass in the practice or individual start time, then it will increment TODO: We could cache this or store in the DB""" start_time = self.time_suggested activities = self.activities() for activity in activities: activity.start_time = start_time activity.end_time = add_time(start_time, activity.duration) start_time = activity.end_time return activities
def get_prev_slots(df, duration): '''gets the dict of form: {slot : previous slot, ...}''' slots = get_slots(df) prev_slot = {} for i_slot in slots: i_start_time = helpers.get_start_time(i_slot) i_end_time = helpers.add_time(i_start_time, duration) i_day = i_slot[:2] for j_slot in slots: j_start_time = helpers.get_start_time(j_slot) j_day = j_slot[:2] if (i_start_time < j_start_time) and (i_day == j_day) and ( i_end_time == j_start_time): prev_slot[j_slot] = i_slot return (prev_slot)