コード例 #1
0
ファイル: data_service.py プロジェクト: dev-hospa/lms
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)
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
ファイル: program.py プロジェクト: dstoltz/100daysofweb
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()
コード例 #5
0
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)
コード例 #6
0
ファイル: data_service.py プロジェクト: dev-hospa/lms
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
コード例 #7
0
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()
コード例 #8
0
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()
コード例 #9
0
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()
コード例 #10
0
ファイル: program.py プロジェクト: YauheniKr/100-Days-of-Web
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}'
    )
コード例 #11
0
ファイル: import_data.py プロジェクト: dev-hospa/lms
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()
コード例 #12
0
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()
コード例 #13
0
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)
コード例 #14
0
def all_players() -> List[Player]:
    Session = session_factory.create_session()
    session = Session()

    players = list(session.query(Player).all())
    session.close()
    return players
コード例 #15
0
ファイル: data_service.py プロジェクト: dev-hospa/lms
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
コード例 #16
0
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
コード例 #17
0
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
コード例 #18
0
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
コード例 #19
0
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
コード例 #20
0
ファイル: data_service.py プロジェクト: dev-hospa/lms
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}"
コード例 #21
0
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
コード例 #22
0
ファイル: program.py プロジェクト: YauheniKr/100-Days-of-Web
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
    ]
コード例 #23
0
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)
コード例 #24
0
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
コード例 #25
0
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
コード例 #26
0
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()
コード例 #27
0
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
コード例 #28
0
ファイル: program.py プロジェクト: YauheniKr/100-Days-of-Web
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)
コード例 #29
0
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
コード例 #30
0
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()
コード例 #31
0
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()
コード例 #32
0
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()
コード例 #33
0
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()
コード例 #34
0
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)
コード例 #35
0
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()
コード例 #36
0
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
コード例 #37
0
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
コード例 #38
0
def all_players() -> List[Player]:
    session = session_factory.create_session()

    players = list(session.query(Player).all())
    session.close()
    return players