def books_by_author(author: str) -> List[Book]: session = session_factory.create_session() books = session.query(Book).order_by(Book.title).\ filter(Book.author == author).all() return list(books)
def find_roll(name: str) -> Optional['Roll']: session = session_factory.create_session() roll = session.query(Roll).filter(Roll.name == name).first() session.close() return roll
def __import_employee(): session = session_factory.create_session() if session.query(Employee).count() > 0: return employee_id = [ 'Hover-1 1st edition', 'Hover-1 Sport 1st edition', 'Hover-1 Touring 1st edition', 'Hover-1 2nd edition', 'Hover-1 Sport 2nd edition', 'Hover-1 Touring 2nd edition', 'Hover-1 3nd edition', 'Hover-1 Sport 3nd edition', 'Hover-1 Touring 3nd edition', ] vin_values = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' locations = list(session.query(Location).all()) COUNT = 21 for _ in range(0, COUNT): s = Scooter() s.model = random.choice(models) s.battery_level = 100 s.vin = ''.join((random.choice(vin_values) for _ in range(0, 18))) s.location = random.choice(locations) session.add(s) session.commit()
def __import_rentals(): session = session_factory.create_session() if session.query(Rental).count() > 0: return scooters = list(session.query(Scooter)) locations = list(session.query(Location)) user = data_service.get_default_user() user2 = session.query(User).filter( User.email == "*****@*****.**").one() for _ in range(1, 5): selected = random.choice(scooters) data_service.book_scooter( scooter=selected, user=user, start_date=datetime.datetime.now() - datetime.timedelta(days=random.randint(1, 100)), ) scooters.remove(selected) data_service.park_scooter(selected.id, random.choice(locations).id) for _ in range(1, 10): selected = random.choice(scooters) data_service.book_scooter( scooter=selected, user=user2, start_date=datetime.datetime.now() - datetime.timedelta(days=random.randint(1, 100)), ) scooters.remove(selected)
def list_of_borrowing(client_id: int) -> List[Borrowing]: session = session_factory.create_session() borrowings = session.query(Borrowing).filter( Borrowing.client_id == client_id).all() return borrowings
def __import_locations(): session = session_factory.create_session() if session.query(Location).count() > 0: return location = Location() location.street = "123 Main St." location.state = "OR" location.city = "Portland" location.max_storage = random.randint(10, 20) session.add(location) location = Location() location.street = "700 Terwilliger Blvd" location.state = "OR" location.city = "Portland" location.max_storage = random.randint(10, 20) session.add(location) location = Location() location.street = "600 Broadway" location.state = "OR" location.city = "Portland" location.max_storage = random.randint(10, 20) session.add(location) session.commit()
def save_game(idx: str, id_player: int, answer: int) -> None: game = Game(id=idx, id_player=id_player, answer=answer) session = session_factory.create_session() session.add(game) session.commit() session.close()
def __import_scooters(): session = session_factory.create_session() if session.query(Scooter).count() > 0: return models = [ "Hover-1 1st edition", "Hover-1 Sport 1st edition", "Hover-1 Touring 1st edition", "Hover-1 2nd edition", "Hover-1 Sport 2nd edition", "Hover-1 Touring 2nd edition", "Hover-1 3rd edition", "Hover-1 Sport 3rd edition", "Hover-1 Touring 3rd edition", ] vin_values = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" locations = list(session.query(Location).all()) COUNT = 21 for _ in range(0, COUNT): s = Scooter() s.model = random.choice(models) s.battery_level = 100 s.vin = "".join((random.choice(vin_values) for _ in range(0, 18))) s.location = random.choice(locations) session.add(s) session.commit()
def list_patient_by_name(): name = input('Please, insert name to seek: ') session = session_factory.create_session() query = session.query(Patient).filter(Patient.patient_name == name).first() print( f'{query.id}. {query.patient_name} {query.patient_blood_group} {query.patient_disease}' )
def import_branches(): session = session_factory.create_session() if session.query(Branch).count() > 0: return branch = Branch() branch.street = "6802 Grim Hill" branch.district = "Old Town" branch.phone_no = 652796716 session.add(branch) branch = Branch() branch.street = "094 Russell Trail" branch.district = "New City" branch.phone_no = 667139351 session.add(branch) branch = Branch() branch.street = "8 Valley Edge Court" branch.district = "Greenfield" branch.phone_no = 729844653 session.add(branch) branch = Branch() branch.street = "6 Cherokee Park" branch.district = "Black Yard" branch.phone_no = 683996375 session.add(branch) session.commit()
def __import_locations(): session = session_factory.create_session() if session.query(Location).count() > 0: return location = Location() location.street = '123 Main St.' location.state = 'NJ' location.city = 'Princeton' location.max_storage = random.randint(10, 20) session.add(location) location = Location() location.street = '700 Nassau Str' location.state = 'NJ' location.city = 'Princeton' location.max_storage = random.randint(10, 20) session.add(location) location = Location() location.street = '600 Broadway' location.state = 'NY' location.city = 'New York' location.max_storage = random.randint(10, 20) session.add(location) session.commit()
def parked_scooters() -> List[Scooter]: session = session_factory.create_session() # noinspection PyComparisonWithNone scooters = session.query(Scooter).filter(Scooter.location_id != None).all() return list(scooters)
def all_players() -> List[Player]: Session = session_factory.create_session() session = Session() players = list(session.query(Player).all()) session.close() return players
def login_client() -> Client: session = session_factory.create_session() client_id = int(input("choose client id [1 - 20] ")) client = session.query(Client).filter(Client.id == client_id).first() print(client) return client
def get_player(name: str) -> Optional[Player]: session = session_factory.create_session() player = session.query(Player).filter(Player.name == name).first() session.close() return player
def create_roll(name: str) -> 'Roll': session = session_factory.create_session() roll = Roll() roll.name = name session.add(roll) session.commit() roll = session.query(Roll).filter(Roll.id == roll.id).first() return roll
def get_win_count(player: Player) -> int: session = session_factory.create_session() wins = session.query(Move)\ .filter(Move.player_id == player.id)\ .filter(Move.is_winning_play)\ .count() session.close() return wins
def get_game_history(game_id: str) -> List[Move]: session = session_factory.create_session() query = session.query(Move)\ .filter(Move.game_id == game_id)\ .order_by(Move.roll_number)\ .all() moves = list(query) session.close() return moves
def borrowing_details(borrowing: Borrowing): session = session_factory.create_session() borrowing = borrowing client = session.query(Client).filter( Client.id == borrowing.client_id).one() book = book_by_id(borrowing.book_id) return f"Client {client.last_name} has borrowed {book.title}"
def all_rolls() -> List[Roll]: session = session_factory.create_session() query = session.query(Roll).order_by(Roll.name).all() rolls = list(query) session.close() return rolls
def list_all_patients(): session = session_factory.create_session() patients_list = session.query(Patient).all() session.close() [ print( f'{patient.id}. {patient.patient_name} {patient.patient_blood_group} {patient.patient_disease}' ) for patient in patients_list ]
def parked_scooters() -> List[Scooter]: session = session_factory.create_session() scooters = ( session.query(Scooter).filter( Scooter.location_id != None).all() # noqa: E711 ) return list(scooters)
def all_rolls() -> List[Roll]: Session = session_factory.create_session() session = Session() query = session.query(Roll).order_by(Roll.name).all() rolls = list(query) session.close() return rolls
def save_guess(guess: int, guess_nb: int, won: bool, id_game: str) -> None: guess = Guess(guess=guess, guess_number=guess_nb, is_winning_guess=won, id_game=id_game) session = session_factory.create_session() session.add(guess) session.commit() session.close()
def park_scooter(scooter_id: int, location_id: int) -> Scooter: session = session_factory.create_session() scooter = session.query(Scooter).filter(Scooter.id == scooter_id).one() scooter.location_id = location_id scooter.battery_level = 100 session.commit() return scooter
def blood_possibilities(): blood_group = input('Please, insert which blood group to seek: ') session = session_factory.create_session() query = session.query(BloodBank.blood_bank_name, BloodBank.blood_bank_address, BloodBank.blood_bank_contact_number, Donor.donor_name, Donor.donor_address, Donor.donor_contact_number) query = query.join(Donor) results = query.filter(Donor.donor_blood_group == blood_group).all() print(results)
def get_win_count(player: Player) -> int: session = session_factory.create_session() wins = session.query(Move) \ .filter(Move.player_id == player.id). \ filter(Move.is_winning_play) \ .count() session.close() return wins
def __import_users(): session = session_factory.create_session() if session.query(User).count() > 0: return data_service.get_default_user() user2 = User() user2.email = "*****@*****.**" user2.name = "user 2" session.add(user2) session.commit()
def record_roll(player, roll: 'Roll', game_id: str, is_winning_play: bool, roll_num: int): session = session_factory.create_session() move = Move() move.player_id = player.id move.roll_id = roll.id move.game_id = game_id move.is_winning_play = is_winning_play move.roll_number = roll_num session.add(move) session.commit() session.close()
def __import_users(): session = session_factory.create_session() if session.query(User).count() > 0: return data_service.get_default_user() user2 = User() user2.email = '*****@*****.**' user2.name = 'Natalia' session.add(user2) session.commit()
def find_or_create_player(name: str) -> Player: session = session_factory.create_session() player = session.query(Player).filter(Player.name == name).first() if player: session.close() return player player = Player() player.name = name session.add(player) session.commit()
def find_or_create_player(name: str) -> Player: player = get_player(name) if player: return player player = Player(name=name) session = session_factory.create_session() session.add(player) session.commit() session.close() return get_player(name)
def find_or_create_player(name: str) -> Player: session = session_factory.create_session() player = session.query(Player).filter(Player.name == name).first() if player: session.close() return player player = Player() player.name = name session.add(player) session.commit() player = session.query(Player).filter(Player.name == name).first() return player
def all_players() -> List[Player]: session = session_factory.create_session() players = list(session.query(Player).all()) session.close() return players