-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopbike_func.py
More file actions
40 lines (34 loc) · 1.59 KB
/
topbike_func.py
File metadata and controls
40 lines (34 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from sqlalchemy.orm import Session
from sqlalchemy import select
from sqlalchemy import extract
import topbike_data as tbd
import topbike_sql as tbsql
def lane_available(lane, date_):
# read all Lane-records from the database, where bane.dato == date_
# if zero records were found return True
# else check if lane is the same on both dates if not return True else False
# print(lane)
# print(date_)
with Session(tbsql.engine) as session:
# records = session.scalars(select(tbd.Lane).where(tbd.Lane.id == lane.id).where(extract("day", tbd.Booking.date) == date_.day).where(extract("month", tbd.Booking.date) == date_.month).where(extract("year", tbd.Booking.date) == date_.year))
records = session.scalars(select(tbd.Lane).where(extract("day", tbd.Booking.date) == date_.day).where(extract("month", tbd.Booking.date) == date_.month).where(extract("year", tbd.Booking.date) == date_.year))
for record in records:
# print("record = ", record)
# print("lane = ", lane)
if record.id == lane.id:
return False
elif record.id != lane.id:
# print("record.id is not equal to lane.id", record.id, lane.id)
return True
# else:
# print("no conditions met!", record) # unnecessary precaution
# print("No records found!")
return True
def capacity_ok(lane, team):
# checks if capacity is okay returns bool
# print(lane)
# print(team)
result = lane.max_capacity - team.team_size
if result < 0:
return False
return True