Example #1
0
def format_time(time):
    # Go from xx:xx:xx to xx:xx am/pm
    hour = time[: time.index(":")]
    time_of_day = " am"
    if int(hour) >= 12:
        time_of_day = " pm"
        if int(hour) > 12:
            hour = str(int(hour) - 12)
    time = time[time.index(":") + 1 :]
    return hour + ":" + time[: time.index(":")] + time_of_day
Example #2
0
def search_table(cnx, day, time, type):
	cursor = cnx.cursor()
	sets = []
	if day == 'false' and time == 'false' and type == 'false':
		query = 'SELECT id FROM events;'
		cursor.execute(query)
		result = [id for (id,) in cursor]
		return result
	if day != 'false':
		query = 'SELECT id FROM events WHERE day="%s";' % day
		cursor.execute(query)
		result = set([id for (id,) in cursor])
		if time != 'false':
			query = 'SELECT id FROM events WHERE endTime>="%s";' % time
			cursor.execute(query)
			time_result = set([id for (id,) in cursor])
			result = result.intersection(time_result)
			if int(time[:time.index(':')]) >= 19:
				query = 'SELECT id FROM events WHERE startTime >="3:00:00" AND endTime<="3:00:00" AND day="%s";' % day
				cursor.execute(query)
				new_day_result = [id for (id,) in cursor]
				result = result.union(set(new_day_result))
		sets.append(result)
	if type != 'false':
		query = 'SELECT id FROM events WHERE %s="True";' % type
		cursor.execute(query)
		result = [id for (id,) in cursor]
		sets.append(set(result))
	if len(sets) == 0:
		return sets
	result = sets[0]
	for s in sets:
		result = result.intersection(s)
	cursor.close()
	return sorted(list(result))
def time_to_float(time):
    """Takes in a string of the time in AM/PM format and returns it as a float,
    with 0 representing 12:00 AM."""
    pos1 = time.index(':')
    pos2 = time.index(' ')

    hour = time[:pos1]
    hour = int(hour)

    suffix = time[pos2 + 1:]
    if (suffix == 'PM' and hour != 12):
        hour = hour + 12
    elif (suffix == 'AM' and hour == 12):
        hour = 0

    mins = time[pos1 + 1:pos2]
    mins = int(mins)

    end = hour + mins / 60

    return (round(end, 3))
Example #4
0
days = ['Thursday', 'Friday', 'Saturday', 'Sunday']
event_types = ['featured', 'food', 'party', 'academic', 'class', 'tour', 'dorm', 'livinggroup', 'studentorg', 'parents', 'religious', 'minority', 'arts', 'athletic']

if 'day' in inputs and 'time' in inputs and 'type' in inputs:
	day = inputs['day'].value
	time = inputs['time'].value
	if day.find('/') != -1:
		m, d, y = (int(x) for x in day[:day.index(' ')].split('/'))    
		ans=datetime.date(y,m,d)
		day_index = ans.weekday()
		day = 'Thursday'
		if day_index >= 3:
			day = days[day_index-3]

		time = time[time.index(' ') + 1:]
	if 'pm' in time or 'am' in time:
		if 'pm' in time:
			hour = time[:time.index(':')]
			if int(hour) != 12:
				hour = int(hour)  + 12
			time = str(hour)+time[time.index(':'):]
		if 'am' in time:
			hour = time[:time.index(':')]
			if int(hour) == 12:
				time = time = '00' + time[time.index(':'):]
		time = time[:time.index(' ')]
		time += ':00'
	event_type = inputs['type'].value
	if event_type == 'all' or event_type not in event_types:
		event_type = 'false'
Example #5
0
def convertTime(time):
    hrs = time[0:(time.index(":"))]
    mins = time[(time.index(":") + 1):(time.index(":") + 3)]
    if ((time[len(time) - 2] == 'P') & (hrs != "12")):
        hrs = int(hrs) + 12
    return "" + str(hrs) + ":" + str(mins)
Example #6
0
        terminal = ""
        gate = ""
        # retriving terminal and gate from the data
        if len(data) > 0:
            if (len(data[0]) >= 4) & (data[0][0:4] == "Term"):
                location = data.pop(0)
                terminal = location[0:6]
                gate = location[9:len(location)]
            elif (len(data[0]) < 15) & (len(data[0]) > 0):
                data.pop(0)
        # generating a flight
        fl = flight(airline_code, airline_name, flight_number, destination,
                    status, schedule_time, update_time, terminal, gate)
        flights.add(fl)

    # using a loop to initialize the array to 0 for practice
    frequency = []
    for x in range(0, 24):
        frequency.append(0)
    # compute the volume of air traffic
    # v01 is computed in hour intervals
    # v02 computed in 15 minute blocks?
    for (i, fl) in enumerate(flights.flights):
        time = str(fl.time)
        if len(time) > 0:
            hr = int(time[0:time.index(":")])
            frequency[hr] = frequency[hr] + 1
    print("\n" + str(max(frequency)) + " flights between " +
          convertBack(frequency.index(max(frequency))) + "\n")

f.close  # closing file to prevent resource leak