def get_end_var_offcampus(in_loc_duration, id): end_times = [] for idx, pair in enumerate(in_loc_duration): # don't consider last day if idx == len(in_loc_duration) - 1: continue td, td_seq = in_loc_duration[idx] tmr, tmr_seq = in_loc_duration[idx+1] td_obj = datetime.strptime(td, "%Y-%m-%d") tmr_obj = datetime.strptime(tmr, "%Y-%m-%d") weekday = td_obj.strftime("%A") if weekday in ['Saturday', 'Sunday']: continue duration = tmr_obj - td_obj # extend seq to before 4:00 am the next day seq_extend = copy.deepcopy(td_seq) if duration.days == 1: for line in tmr_seq: loc_start_time = time.strptime(line[1], "%H:%M:%S") if loc_start_time < time.strptime('04:00:00', "%H:%M:%S"): seq_extend.append(line) last_loc = seq_extend[-1] #print last_loc end_time = last_loc[2] end_times.append(end_time) #print len(start_times) #samples = random.sample(start_times, 20) samples = end_times return get_time_var(samples)
def get_start_var_offcampus(in_loc_duration, id): start_times = [] for pair in in_loc_duration: dt = pair[0] weekday = datetime.strptime(dt, "%Y-%m-%d").strftime("%A") if weekday in ['Saturday', 'Sunday']: continue seq = pair[1] #pp.pprint(seq) first_loc = seq[0] start_time = first_loc[1] #print start_time start_times.append(start_time) #print len(start_times) #samples = random.sample(start_times, 20) samples = start_times return get_time_var(samples)
def time_var(id): fp = os.path.join(dir, r'u%s.txt' % id) fr = open(fp, 'rU') to_idx = {'Breakfast':0, 'Lunch':1, 'Supper':2, 'Snack':3} times = [[], [], [], []] for line in fr.readlines(): items = line.rstrip('\n').split(",") time = items[0][11:] meal = items[2] idx = to_idx[meal] times[idx].append(time) vars = [] for meal_times in times: if meal_times: var = get_time_var(meal_times) vars.append(var) else: vars.append(0.0) print vars return vars
def get_end_var_oncampus(in_loc_duration, id): end_times = [] for idx, pair in enumerate(in_loc_duration): # don't consider last day if idx == len(in_loc_duration) - 1: continue td, td_seq = in_loc_duration[idx] tmr, tmr_seq = in_loc_duration[idx+1] td_obj = datetime.strptime(td, "%Y-%m-%d") tmr_obj = datetime.strptime(tmr, "%Y-%m-%d") weekday = td_obj.strftime("%A") if weekday in ['Saturday', 'Sunday']: continue duration = tmr_obj - td_obj # extend seq to before 4:00 am the next day seq_extend = copy.deepcopy(td_seq) if duration.days == 1: for line in tmr_seq: loc_start_time = time.strptime(line[1], "%H:%M:%S") if loc_start_time < time.strptime('04:00:00', "%H:%M:%S"): seq_extend.append(line) # check locs in reverse order, find the first non-home loc, and use the following home loc start time seq_extend_reverse = list(reversed(seq_extend)) for i, line in enumerate(seq_extend_reverse): loc = line[0][3:-1] if i > 0 and not loc in ID_HOME[id]: end_time = seq_extend_reverse[i-1][1] # items = end_time.split(':') # hour = int(items[0]) # if hour < 4: # end_time = "%02d:%s:%s" % (hour+24, items[1], items[2]) end_times.append(end_time) break samples = end_times #print len(samples) return get_time_var(samples)
def get_start_var_oncampus(in_loc_duration, id): # randomly choose 20 days start_times = [] for pair in in_loc_duration: dt = pair[0] weekday = datetime.strptime(dt, "%Y-%m-%d").strftime("%A") if weekday in ['Saturday', 'Sunday']: continue seq = pair[1] #pp.pprint(seq) for line in seq: loc = line[0][3:-1] loc_start_time = time.strptime(line[1], "%H:%M:%S") # the first loc after 4:00 am that is not home if loc_start_time > time.strptime('04:00:00', "%H:%M:%S") and not loc in ID_HOME[id]: start_times.append(line[1]) #print line[1] break #print len(start_times) #samples = random.sample(start_times, 20) samples = start_times return get_time_var(samples)