def process(): # pulls the form information from the post query form = request.form user = User.load_from_db_by_student_id(form["student_id"]) # if the user doesn't exist in the database already, then creates a new user # users are classified by student id if not user: user = User(form["first_name"], form["last_name"], form["student_id"], None) user.save_to_db() user = User.load_from_db_by_student_id(form["student_id"]) # compiles a list of the seats chosen in the form from the post query seats = "" seat_list = form.getlist('seats') for seat in seat_list: seats += seat + " " new_seat = Seat(seat, form["screening"], None) new_seat.save_to_db() # updates attending in the screening database, then creates a new order in the database. all the fields that are # passed as None are filled by the database itself. Screening.update_attending(len(seat_list), form["screening"]) new_order = Order(None, user.id, seats, form["screening"], None, None) new_order.save_to_db() new_order = Order.load_from_db_by_user_id(user.id) screening = Screening.load_from_db_by_screening_id(new_order.screening_id) movie = Movie.load_from_db_by_id(screening.movie_id) order_date = new_order.order_date.strftime("%B %d, %Y %I:%M %p") screening_date = screening.date.strftime("%B %d, %Y %I:%M %p") return render_template('orderdetails.html', user=user, order=new_order, movie=movie, screening=screening, order_date=order_date, screening_date=screening_date)
def create_seat(self): try: cr_s = dialog1() cr_s.exec_() a = cr_s.LIST if not a: return if not a[0][0]: n = [ str(x) for x in range(1, (int(a[1][1]) * int(a[1][0]) + 1) * 2) ] else: n = a[0] QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) n = iter(n) y = self.size().height() / (int(a[1][1]) + 1) X = self.size().width() / (int(a[1][0]) + 1) if cr_s.checkBox.isChecked(): t = [[ Seat(name=next(n), geom=(X * (j + 1) - 20, y * (i + 1) + 1), parent=self, seat=self.seat), Seat(name=next(n), geom=(X * (j + 1) + 20, y * (i + 1) + 1), parent=self, seat=self.seat) ] for i in range(int(a[1][0])) for j in range(int(a[1][1]))] t = list(chain.from_iterable(t)) else: t = [ Seat(name=next(n), geom=(X * (j + 1), y * (i + 1) + 1), parent=self, seat=self.seat) for i in range(int(a[1][1])) for j in range(int(a[1][0])) ] if cr_s.checkBox_2.isChecked(): for x, y in enumerate(t): y.Gender = 'boy' if x % 2 == 0 else 'girl' self.seat.extend(t) del t except OverflowError: self.del_seat() finally: QApplication.restoreOverrideCursor()
def __allocate_spectator(self, spectator: Spectator, seat: Seat): result = False if seat.check_availability(): seat.occupy_seat(spectator) self.__allocated_spectators.append(spectator) self.__allocated_seats = self.__allocated_seats + 1 result = True return result
def __init__(self, film: Film, rows: int, cols: int): self.__film = film self.__allocated_seats = 0 self.__allocated_spectators = [] self.__max_seats = int(rows * cols) self.__room = [[Seat(row + 1, col + 1) for col in range(cols)] for row in range(rows)]
def generate_by_seat_assignment(plane, overall_alternate, letter_alternate, row_alternation): # overall alternate = True /False: GO A... B... C... or A... F... B... # letter alternate = True / False GO AAAAAA ..... or AFAFAF ..... # row alternation integer row_alternation += 1 seats = np.empty(plane.rows*(plane.seatsRight + plane.seatsLeft), dtype = Seat) index = 0 for i in range(0, row_alternation): for j in range(0, plane.seatsLeft + plane.seatsRight): if overall_alternate: if j % 2 == 1: j = plane.seatsRight+plane.seatsLeft -1 - int(j/2) else: j = int(j/2) for k in range(0, ceil((plane.rows - i)/row_alternation)): row = plane.rows-1-i-k*row_alternation if letter_alternate: if k % 2 == 0: col = j else: col = plane.seatsRight+plane.seatsLeft -1 - j else: col = j seats[index] = Seat(row,col) index += 1 return seats
def generate_by_half_row_assignment(plane, row_alternation, alternate_sides): row_alternation += 1 seats = np.empty(plane.rows*(plane.seatsRight + plane.seatsLeft), dtype = Seat) index = 0 seats_on_side = plane.seatsLeft for h in range(0, 2): for i in range(0, row_alternation): for j in range(0, ceil((plane.rows - i)/row_alternation)): if alternate_sides: h_temp = (h+j)%2 else: h_temp = h if h_temp == 0: seats_on_side = plane.seatsLeft else: seats_on_side = plane.seatsRight half_row = np.empty(seats_on_side, dtype = int) for k in range(0, seats_on_side): half_row[k] = k+h_temp*plane.seatsLeft np.random.shuffle(half_row) for k in range(0, seats_on_side): seats[index] = Seat(plane.rows-1 - (i+j*row_alternation),half_row[k]) index += 1 return seats
def generate_random_assignment(plane): seats = np.empty(plane.rows * (plane.seatsRight + plane.seatsLeft), dtype=Seat) for i in range(0, plane.rows): for j in range(0, plane.seatsRight + plane.seatsLeft): seats[i * (plane.seatsRight + plane.seatsLeft) + j] = Seat(i, j) np.random.shuffle(seats) return seats
def load(self, file, fname): self.couple_ov_op, self.seat_ov_op, self.gender_set = file[-1] del file[-1] self.ch_couple = None print(len(self.seat)) self.del_seat() self.seat.extend([ Seat(x[0], x[1], x[2], self, (self.width() * x[3][0], self.height() * x[3][1]), x[4], x[5], x[6]) for x in file ]) for x in self.seat: try: x.couple = self.seat[x.couple] except TypeError: pass t, _ = splitext(basename(fname)) self.setWindowTitle(t)
def solve_one(boarding_passes): highest_seat_id = 0 for boarding_pass in boarding_passes: seat = Seat(boarding_pass) highest_seat_id = max(seat.id, highest_seat_id) logging.info(f'Highest Seat ID: {highest_seat_id}') return highest_seat_id
def choose_seats(self, hall_map, tickets_count): result = [] while tickets_count > 0: seat_choice_string = tuple(input("Choose a seat (e.g '(1, 2)') > ")) seat_choice = Seat.string_to_seat_tuple(seat_choice_string) if Seat.isOutOfRange(seat_choice[0], seat_choice[1], self.LENGTH, self.WIDTH) is True: print("Seat is out of boundries") elif hall_map[seat_choice[0] - 1][seat_choice[1] - 1] == Seat.SEAT_TAKEN: print("Seat is already taken") else: result.append(seat_choice) tickets_count -= 1 return result
def generateMap(self, _input) -> [Seat]: _map = [] for x, line in enumerate(_input): for y, state in enumerate(line): seat = Seat(x, y, state) if not _map.__contains__(seat): _map.append(seat) return _map
def generate_full_row_block_assignment(plane, number_of_blocks, sequence_index, alternation): seats = np.empty(plane.rows * (plane.seatsRight + plane.seatsLeft), dtype=Seat) blocks = list() for i in range(0, number_of_blocks-1): new_block = np.empty(int(plane.rows/number_of_blocks) * (plane.seatsRight + plane.seatsLeft), dtype=Seat) for j in range(0, int(plane.rows/number_of_blocks)): for k in range(0, plane.seatsRight + plane.seatsLeft): new_block[j * (plane.seatsRight + plane.seatsLeft) + k] = \ Seat(i*int(plane.rows/number_of_blocks)+j, k) np.random.shuffle(new_block) blocks.append(new_block) new_block = np.empty((plane.rows-(number_of_blocks-1)*int(plane.rows / number_of_blocks)) * (plane.seatsRight + plane.seatsLeft), dtype=Seat) for j in range(0, (plane.rows-(number_of_blocks-1)*int(plane.rows / number_of_blocks))): for k in range(0, plane.seatsRight + plane.seatsLeft): new_block[j * (plane.seatsRight + plane.seatsLeft) + k] = \ Seat((number_of_blocks-1)*int(plane.rows / number_of_blocks) + j, k) np.random.shuffle(new_block) blocks.append(new_block) if sequence_index == 0: # blocks in decreasing order index = len(seats)-1 for i in blocks: for j in range(0, len(i)): seats[index] = i[j] index -= 1 elif sequence_index == 1: # blocks in alternating, decreasing order index = 0 for start in reversed(range(len(blocks)-1-alternation, len(blocks))): i = start while i >= 0: for k in range(0, len(blocks[i])): seats[index] = blocks[i][k] index += 1 i -= (alternation + 1) else: # blocks in random order shuffle(blocks) index = 0 for i in blocks: for k in range(0, len(i)): seats[index] = i[k] index += 1 return seats
def __init__(self, players, buy_in, min_denomination): self.seats = deque() self.min_denomination = min_denomination self.player_positions = [] self.blind_structure = Blinds(buy_in) self.player_indices = range(len(players)) for player, index in zip(players, self.player_indices): seat = Seat(player, index, buy_in) self.seats.append(seat)
def choose_seats(self, hall_map, tickets_count): result = [] while tickets_count > 0: seat_choice_string = tuple( input("Choose a seat (e.g '(1, 2)') > ")) seat_choice = Seat.string_to_seat_tuple(seat_choice_string) if Seat.isOutOfRange(seat_choice[0], seat_choice[1], self.LENGTH, self.WIDTH) is True: print("Seat is out of boundries") elif hall_map[seat_choice[0] - 1][seat_choice[1] - 1] == Seat.SEAT_TAKEN: print("Seat is already taken") else: result.append(seat_choice) tickets_count -= 1 return result
def solve_two(boarding_passes): seat_map = np.zeros((128, 8)) for boarding_pass in boarding_passes: seat = Seat(boarding_pass) seat_map[seat.row, seat.column] = seat.id neighbors = seat_map.flatten() neighbors = np.where(neighbors > 0) seat_id = np.sum(range(np.min(neighbors), np.max(neighbors) + 1)) - np.sum(neighbors) logging.info(f'Seat ID: {seat_id}') return seat_id
def generate_steffen_assignment(plane, alternation): alternation += 1 seats = np.empty(plane.rows*(plane.seatsRight + plane.seatsLeft), dtype=Seat) index = 0 a = 0 b = plane.seatsRight + plane.seatsLeft - 1 while a < plane.seatsLeft or b >= plane.seatsLeft: for i in range(0, alternation): if b >= plane.seatsLeft: m = plane.rows - 1 - i while m >= 0: seats[index] = Seat(m, b) index += 1 m -= alternation if a < plane.seatsLeft: m = plane.rows - 1 - i while m >= 0: seats[index] = Seat(m, a) index += 1 m -= alternation b -= 1 a += 1 return seats
def test_seat(boarding_passes): properties = [ (44, 5, 357), (70, 7, 567), (14, 7, 119), (102, 4, 820), ] tests = zip(boarding_passes, properties) for code, props in tests: row, column, id = props seat = Seat(code) assert seat.row == row assert seat.column == column assert seat.id == id
def generate_tables(self, num_unseated, max_seats, min_seats): self._tables = [] while num_unseated > 0: to_seat = 0 if num_unseated % max_seats == 0: to_seat = max_seats; elif num_unseated > min_seats: to_seat = min_seats else: to_seat = num_unseated; self._tables.append(Table([Seat() for i in range(0, to_seat)])) num_unseated -= to_seat
def generate_by_row_assignment(plane, alternation): seats = np.empty(plane.rows * (plane.seatsRight + plane.seatsLeft), dtype=Seat) rows = list() for i in range(0, plane.rows): new_row = np.empty((plane.seatsRight + plane.seatsLeft), dtype=Seat) for j in range(0, plane.seatsRight + plane.seatsLeft): new_row[j] = Seat(i, j) np.random.shuffle(new_row) rows.append(new_row) index = 0 for start in reversed(range(len(rows)-1-alternation, len(rows))): i = start while i >= 0: for k in range(0, len(rows[i])): seats[index] = rows[i][k] index += 1 i -= (alternation + 1) return seats
def handle_data(self, data): if len(data.strip()) == 0: return if self.state == State.NAME: # Seats are listed as eg. 'Higgins (VIC)' p = re.compile('([a-zA-Z\-\s\']*)\s*\(([A-Za-z]*)\)') m = p.match(data.strip()) self.seats.append(Seat(m.group(1).strip(), m.group(2).upper())) if self.state == State.CANDIDATE_NAME: name = data if name.find('(') > 0: name = name[0:name.find('(')] name = name.strip() for s in SYNONYMS: if name in s: name = s[0] self.candidate_name = name if self.state == State.PRICE: self.price = float(data.strip())
def order(): query = request.args.get('q') movie_data = Movie.load_from_db_by_name(query) screenings = Screening.load_screenings_by_movie_id(movie_data.id) booked_seats = [] # compiles all the seat bookings by the screening id from the database, puts them in a list, and passes that list # into the html file for i in range(len(screenings)): seat_list = Seat.load_from_db_by_screening_id(screenings[i].id) if seat_list: booked_seats.extend(seat_list) # compiles a list of dates with a specific format for all screenings of the chosen movie date_list = [(screenings[i].date.strftime("%B %d, %Y %I:%M %p"), screenings[i].id) for i in range(len(screenings))] if screenings: return render_template('order.html', movie_data=movie_data, screenings=date_list, seat_list=booked_seats)
def main(): #blue_seat = Seat(color=BLUE) blue_seats = dict(enumerate([Seat(BLUE, 15) for i in range(TOTAL_SEATS)])) passengers = dict(enumerate([Passenger() for i in range(TOTAL_SEATS)])) #print(passengers) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() start_time = pygame.time.get_ticks() # timer example #https://stackoverflow.com/questions/30720665/countdown-timer-in-pygame if start_time: time_since_enter = pygame.time.get_ticks() - start_time message = 'Milliseconds since enter: ' + str(time_since_enter) game_display.blit(FONT.render(message, True, BLACK), (20, 20)) draw_environment([blue_seats], [passengers]) pygame.display.flip() clock.tick(60)
def generate_by_letter_assignment(plane, alternating, back_to_front): seats = np.empty(plane.rows*(plane.seatsRight + plane.seatsLeft), dtype = Seat) cols = list() for i in range(0, plane.seatsLeft + plane.seatsRight): new_col = np.empty(plane.rows, dtype = int) for j in range(0, plane.rows): new_col[plane.rows-j-1] = j if not back_to_front: np.random.shuffle(new_col) cols.append(new_col) index = 0 for j in range(0, len(cols)): if alternating: if j%2 == 0: j = int(j/2) else: j = plane.seatsLeft + plane.seatsRight - 1 - int(j/2) for i in range(0, plane.rows): seats[index] = Seat(cols[j][i], j) index += 1 return seats
def add_button(self): if sys.getsizeof(self.seat) + sys.getsizeof(Seat) > sys.maxsize: sub('리스트가 너무 큽니다.') return self.seat.append(Seat(parent=self, seat=self.seat))
from data import DATA from seat import Seat cleaned_data = DATA.splitlines() if __name__ == "__main__": seats = [Seat.from_string(data) for data in cleaned_data] max_id = max([seat.id for seat in seats]) print("PART ONE\n=======") print('Greatest passport ID: {}'.format(max_id)) sorted_ids = [seat.id for seat in sorted(seats, key=lambda seat: seat.id)] expected_id = None for id in sorted_ids: if expected_id is None: expected_id = id + 1 continue if not id == expected_id: break expected_id = id + 1 print('Missing Seat ID: {}'.format(expected_id)) print("\nPART TWO\n=======")
def __init__(self): Seat.__init__(self, (255, 145, 25), 10) self.x = 100 self.y = 260
def create_movie_hall(cls, movie_halls_schema: dict): seats = [ [Seat(index) if index else None for index in row] for row in movie_halls_schema['rows'] ] return cls(int(movie_halls_schema['number']), seats)
def __init__(self, start_x, start_y, end_x, end_y): Seat.__init__(self, (255, 145, 25), 10) self.start_x = start_x self.start_y = start_y self.end_x = end_x self.end_y = end_y
import sys from seat import Seat highest = 0 ids = [None] * 1024 with open(sys.argv[1]) as seats_input: for seat in seats_input: seat = Seat(seat.rstrip()) print(seat) if seat.id >= highest: highest = seat.id ids[seat.id] = 1 started = False for i, seat_id in enumerate(ids): if not started: if seat_id: started = True else: if not seat_id: my_seat = i break print(f'{ids}') print(f'the highest id is {highest}') print(f'my seat is {my_seat}')
def main(args): # Read in the bounding box coordinates if not os.path.isfile(args.seat_bb_csv): print("Argument seat-bb-csv is not a file: {}".format( args.seat_bb_csv)) exit() # Each seat bounding box is in the format of [x0, y0, x1, y1] seat_bounding_boxes = np.genfromtxt(args.seat_bb_csv, delimiter=',', dtype=np.int) # seat_bounding_boxes //= downsample_ratio num_seats = len(seat_bounding_boxes) - 1 # Open the video if not os.path.isfile(args.video): print("Argument video is not a file: {}".format(args.video)) exit() cap = cv2.VideoCapture(args.video) if not cap.isOpened(): raise IOError("Failed to open video: {}".format(args.video)) success, frame = cap.read() # Read the first frame if not success: print("Failed to read the first frame from : {}".format(args.video)) # Create the object detector from the frozen model obj_detector = ObjectDetector(args.pretrained_model) OBJ_DETECTION_THRESHOLD = 0.7 # Initialize Seats object seats = [] table_bb = seat_bounding_boxes[0] for seat in range(num_seats): x0, y0, x1, y1 = seat_bounding_boxes[seat + 1] seats.append( Seat(frame[y0:y1, x0:x1], seat_bounding_boxes[seat + 1], table_bb)) SEAT_OVERLAP_THRESHOLD = 0.3 TOTAL_FRAME_COUNT = cap.get(cv2.CAP_PROP_FRAME_COUNT) VIDEO_1_FRAME_COUNT = 525.0 VIDEO_2_FRAME_COUNT = TOTAL_FRAME_COUNT - VIDEO_1_FRAME_COUNT progress_bar = tqdm(range(int(TOTAL_FRAME_COUNT)), unit='frames') seat_labels = np.full((int(VIDEO_2_FRAME_COUNT), num_seats), -1, dtype=int) # JUMP_TO_FRAME = 2100 # cap.set(cv2.CAP_PROP_POS_FRAMES, JUMP_TO_FRAME) # progress_bar.update(JUMP_TO_FRAME) if args.output: frame_width, frame_height = int(cap.get(3)), int(cap.get(4)) out = cv2.VideoWriter(args.output, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), 30, (frame_width, frame_height)) # Start the seat detection # k = 0 # Skip frame counter frame_count = 0 while True: success, frame = cap.read() # Read the next frame if not success: break # No more frames progress_bar.update() # k += 1 # if k < 3: # Run every three frames # continue # k = 0 # frame = cv2.resize(frame, (frame_width, frame_height)) draw_frame = frame.copy() boxes, scores, classes, num = obj_detector.processFrame( frame) # Feed the image frame through the network # Detect humen and chairs in the frame and get the bounding boxes detected_person_bounding_boxes = [] detected_chair_bounding_boxes = [] for i, box in enumerate(boxes): # Class 1 is "person" if classes[i] == 1 and scores[i] > OBJ_DETECTION_THRESHOLD: detected_person_bounding_boxes += [(box[1], box[0], box[3], box[2])] # Visualize seat_utils.draw_box_and_text(draw_frame, "human: {:.2f}".format(scores[i]), box, CvColor.BLUE) elif classes[i] == 62 and scores[i] > OBJ_DETECTION_THRESHOLD: detected_chair_bounding_boxes += [(box[1], box[0], box[3], box[2])] # Visualize seat_utils.draw_box_and_text(draw_frame, "chair: {:.2f}".format(scores[i]), box, CvColor.YELLOW) # Store the seat status for comparison with ground truth this_frame_seat_labels = np.full(num_seats, -1, dtype=int) # Store the seat images for visualization seat_img = [None for _ in range(num_seats)] foreground_img = [None for _ in range(num_seats)] for seat_id, this_seat in enumerate(seats): this_seat_img = this_seat.get_seat_image( frame) # Crop the image to seat bounding box draw_img = this_seat.get_seat_image(draw_frame) # Calculate overlap of the seat with each person bounding box person_detected = False for person_bb in detected_person_bounding_boxes: overlap_percentage = calculate_overlap_percentage( this_seat.bb_coordinates, person_bb, this_seat.bb_area) if overlap_percentage > SEAT_OVERLAP_THRESHOLD: person_detected = True # Enough overlap, mark as person detected in the seat break # Person detected in the seat, no need to check other boxes for chair_bb in detected_chair_bounding_boxes: # overlap_area, _ = rectangle_overlap(this_seat.bb_coordinates, chair_bb) # if overlap_area > rectangle_area(chair_bb)*0.7: # # This chair is 70% within the seat bounding box # this_seat.update_chair_bb(chair_bb) relative_bb = get_overlap_rectangle(this_seat.bb_coordinates, chair_bb, relative=True) if relative_bb is not None: this_seat.update_chair_bb(relative_bb) # Update the seat status if person_detected: this_seat.person_detected() else: this_seat.no_person_detected(this_seat_img) # Put the seat status in the cropped image x0, y0, x1, y1 = this_seat.table_bb foreground = this_seat.check_leftover_obj( this_seat_img, this_seat.CONTOUR_AREA_THRESHOLD) # foreground = this_seat.ignore_chair(foreground) foreground_img[seat_id] = foreground foreground = cv2.cvtColor(foreground, cv2.COLOR_GRAY2BGR) cv2.addWeighted(foreground, 0.3, draw_img[y0:y1, x0:x1], 0.7, 0, draw_img[y0:y1, x0:x1]) seat_utils.put_seat_status_text(this_seat, draw_img) seat_img[seat_id] = draw_img # Store status for this seat this_frame_seat_labels[seat_id] = this_seat.status.value # SEE_SEAT = 1 # cv2.imshow("seat{}".format(SEE_SEAT), foreground_img[SEE_SEAT]) for seat in range(num_seats): x0, y0, x1, y1 = seat_bounding_boxes[seat + 1] draw_frame[y0:y1, x0:x1] = seat_img[seat] frame_pos = cap.get(cv2.CAP_PROP_POS_FRAMES) if frame_pos > VIDEO_1_FRAME_COUNT: seat_labels[frame_count] = this_frame_seat_labels frame_count += 1 if args.output: out.write(draw_frame) cv2.imshow("Preview", draw_frame) key = cv2.waitKey(1) if key & 0xFF == ord('q'): break cv2.imwrite("img/frame_{}.jpg".format(frame_pos), draw_frame) # Video playback ended. Clean up progress_bar.close() obj_detector.close() cap.release() if args.output: out.release() cv2.destroyAllWindows() # Store the labels for seats np.savetxt("labels.csv", seat_labels, fmt="%s", delimiter=',', header='seat0,seat1,seat2,seat3')
def _get_seat(self, coordinates: tuple[int, int]) -> "Seat": seat = self._seats.get(coordinates) if seat is None: seat = Seat(coordinates) self._seats.update({coordinates: seat}) return seat