Esempio n. 1
0
def main(input_file):
    # Load input as events in sorted order (Event timestamp)
    events = []
    with open(input_file) as file:
        for line in file:
            # TODO: Binary insert based off datetime instead of append
            e = Event(line)
            if (len(events) > 0):
                binary_insert(events, e)
            else:
                events.append(e)

    # Setup guards with shifts, and those shifts with events, in sorted order (Guard ID)
    guards = []
    current_guard_id = 0
    current_shift = Shift()
    for e in events:
        if e.type == 0:
            tmp_guard = Guard(e.GetGuardID())
            if len(guards) > 0:
                guards[current_guard_id].add_shift(current_shift)
                current_shift = Shift()
                
                index = binary_search(guards, tmp_guard)
                if index == -1:
                    current_guard_id = binary_insert(guards, tmp_guard)
                else:
                    current_guard_id = index
            else:
                guards.append(tmp_guard)
        current_shift.add_event(e)
    
    # Find guard who slept most
    result_index = index_of_max([sum(g.minutes_asleep) for g in guards])

    # Most slept minute
    msm = guards[result_index].get_most_slept_minute()

    # Part 1 Answer
    print("Guard #", guards[result_index].id, sep='')
    print("Slept most at minute", msm)
    print("Part 1 Answer:", guards[result_index].id * msm)

    print()

    # Part 2 Answer
    msm_count = [g.minutes_asleep[g.get_most_slept_minute()] for g in guards]
    result_index = index_of_max(msm_count)
    msm = guards[result_index].get_most_slept_minute()
    
    print("Guard #", guards[result_index].id, sep='')
    print("Slept most at minute ", msm, ', ', msm_count[result_index], ' times', sep='')
    print("Part 2 Answer:", guards[result_index].id * msm)
Esempio n. 2
0
def plan_shift(shift_name, start_time_hr, start_time_min, end_time_hr, end_time_min, rev_goal):
    global unit, user
    if (user not in shifts):
        shifts[user] = {}
    obj = Shift(user, shift_name, positions[user], shifts[user][shift_name], unit)
    for x in obj.numbers:
        write_to_box("{}: {}".format(x, obj.numbers[x]))
Esempio n. 3
0
    def __init__(self, name, address, cuisine_type, sections=None, id=DEFAULT_TEST_UUID if DEMO_MODE else None):
        super().__init__(True, id)
        self._json['name'] = name
        self._json['address'] = address
        self._json['cuisineType'] = cuisine_type

        if sections is not None:
            self._json['sections'] = sections
        elif DEMO_MODE:
            print(self.post())
            section = Section('booths', id)
            print(section.post())
            table = Table(3, 25, 25, 0, section.section_id)
            print(table.post())
            reservation = Reservation(table.table_id, id)
            print(reservation.post())
            account = Account()
            print(account.post())
            shift = Shift(None, section.id)
            print(shift.post())
            visit = Visit(shift.id, id)
            print(visit.post())
            order = Order(Status.COOK, 10, account.id,
                          'Steak was undercooked last time.', shift.id, visit.id)
            print(order.post())
            order_two = Order(Status.PREP, 30, account.id,
                              'Less pie flavor please.', shift.id, visit.id)
            print(order_two.post())
def getRandomShifts(students): 
    shifts = []
    
    for i in range(1, students + 1): 
        start, end = randomShift(shifts)
        shifts.append(Shift(i, start, end))
    
    return shifts
Esempio n. 5
0
def main():
    sender = mysocket()
    sender.connect(host='127.0.0.1', port=8085)
    encrypt = Shift()
    while 1:
        msg = input('enter msg: ')
        if 'exit' in msg:
            break

        encrypted_msg = encrypt.shift('right', msg)
        sender.send_it(encrypted_msg)
Esempio n. 6
0
def create_shift(chief, department, start, end, workers, requirements):
    new_shift = Shift(start=start, end=end).save()

    for person_id in workers.split(ID_DELIMITER):
        add_worker(new_shift.ident, person_id)

    for requirement_id in requirements.split(ID_DELIMITER):
        add_shift_requirement(new_shift.ident, requirement_id)

    set_chief(new_shift.ident, chief)
    set_shift_department(new_shift.ident, department)

    return new_shift
Esempio n. 7
0
def main():
	serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	serversocket.bind(('localhost', 8085))
	serversocket.listen()
	
	conn, addr = serversocket.accept()
	with conn:
		print('connected by', addr)
		decrypt = Shift()
		while 1:
			data = conn.recv(1024)
			if not data or str.encode('exit') in data:
				break
			decrypted_msg = decrypt.shift('left', data.decode('utf-8'))
			print(decrypted_msg)
def readStudents(students):
    shifts = []

    for i in range(1, students + 1):
        while(1):
            start = int(input("Insira o tempo inicial do estudante {}:".format(i)))

            end = int(input("Insira o tempo final do estudante {} :".format(i)))

            if((start < 0 or start > 23) or (end < 1 or end > 24)):
                print("Digite valores entre 0 e 23 para o início e 1 e 24 para o final")
            else:
                shifts.append(Shift(i, start, end))
                break     

    return shifts
Esempio n. 9
0
                         ELEANOR=("JOHNSON", "SERVICE", "Eleanor"),
                         JENNIE=("SONG", "SERVICE", ""),
                         HEIDI=("HEIDI", "SERVICE", "Heidi"),
                         CHRIS=("THOMPSON", "SERVICE", "Chris"),
                         MARLEY=("BARTLETT", "SERVICE", "Marley"),
                         ADAM=("O'BRIEN", "SUPPORT", "Adam O'Brien"),
                         REBECCA=("MOGCK", "SUPPORT", "Rebecca M"))

    return [
        Employee(emp, employee_dict[emp][0], employee_dict[emp][1])
        for emp in employee_dict
    ]


employees = instantiate_employees()
shift = Shift(employees, denominations)

db_ctr = db_mgr.DbController(int(os.getenv('VOL_DB_PORT')),
                             os.getenv('VOL_DB_HOST'))
db_ctr.connect_db()


def redirect_url(default='front_page'):
    return request.args.get('next') or request.referrer or url_for(default)


def validate_cash_inputs(denomination_list, request_form):
    denoms = denomination_list
    rf = request_form

    for denom in denoms:
Esempio n. 10
0
def assemble_shift(circuit, output_wire, a, shift_type, b):
    part_a = assemble_input(circuit, a)
    part_b = assemble_input(circuit, b)

    shift = Shift(shift_type, part_a, part_b, output_wire)
    output_wire.set_input(shift)
Esempio n. 11
0
        #finds all shifts per day and adds to a Shift object
        for index in enumerate(times):
            this_shift = shifts[index[0]]
            this_time = times[index[0]]

            if (shift_info['Name'] == '' and this_shift != ''
                    and this_shift != 'a'):  #start a new shift
                shift_info['Name'] = this_shift
                shift_info['Start'] = this_time

            if (shift_info['Name'] != this_shift
                    and this_shift != 'a'):  #the shift ended
                shift_info['End'] = this_time
                shift_block = Shift(
                    shift_info['Name'], shift_info['Start'],
                    shift_info['End'])  #create a new shift object & append
                shift_list.append(shift_block)
                shift_info['Name'] = this_shift
                shift_info['Start'] = this_time

        #cleans up the last shift
        if (this_time == '5:00'
                and shift_info['Name'] != this_shift):  #if ends at 5
            shift_info['End'] = '5:00'
            shift_block = Shift(
                shift_info['Name'], shift_info['Start'],
                shift_info['End'])  #create a new shift object & append
            shift_list.append(shift_block)
        elif (this_time == '5:00' and this_shift != ''
              and this_shift != 'a'):  #if ends at 5:30