Implement extra (non-IB) subject support, update README.md and TODO.md

This commit is contained in:
Abdulkadir Furkan Şanlı 2019-01-06 10:04:44 +01:00
parent e8f51079d7
commit 1a309834af
No known key found for this signature in database
GPG Key ID: 7823BD18E6F95D73
3 changed files with 77 additions and 51 deletions

View File

@ -1,6 +1,6 @@
# ib-clearance
ib-clearance is a program which helps schools manage the entrance and exiting of their IB students. Due to the unique nature of IB students' timetables, the program helps check individual timetables and give clearance to students who have finished for the day.
ib-clearance is a program which helps schools manage the entrance and exiting of their IBDP students. Due to the unique nature of IB students' timetables, the program helps check individual timetables and give clearance to students who have finished for the day.
## Building
@ -10,44 +10,42 @@ I recommend building executables with `pyinstaller` with `pyinstaller --onefile
## Database specification
The program requires SQLite databases for each IB class.
The program requires a SQLite database `database.db` in the working directory, containing info for all classes.
Each database must contain:
`database.db` must contain:
| Table | Description |
| ----------- | ---------------------------------------------------------- |
| `students` | Contains students' names, ID numbers and class preferences |
| `timetable` | Timetable information for class |
| Table | Description |
| ----------- | ------------------------------------------------------------ |
| `students` | Contains students' names, ID numbers and subject preferences |
| `timetable` | Timetable information (lessons) |
### `students`
| Column | Data type | Description |
| ------ | --------- | --------------------------------- |
| `id` | `INTEGER` | Student ID number used in program |
| `g1` | `TEXT` | Group 1 subject ID |
| `g2` | `TEXT` | Group 2 subject ID |
| `g3` | `TEXT` | Group 3 subject ID |
| `g4` | `TEXT` | Group 4 subject ID |
| `g5` | `TEXT` | Group 5 subject ID |
| `g6` | `TEXT` | Group 6 subject ID |
| `name` | `TEXT` | Full name of student |
| Column | Data type | Description |
| --------------- | --------- | ----------------------------------------------- |
| `id` | `INTEGER` | Student ID number used in program |
| `student_class` | `INTEGER` | IB class number (e.g. `1`, `2`) |
| `name` | `TEXT` | Full name of student |
| `g1` | `TEXT` | Group 1 subject ID |
| `g2` | `TEXT` | Group 2 subject ID |
| `g3` | `TEXT` | Group 3 subject ID |
| `g4` | `TEXT` | Group 4 subject ID |
| `g5` | `TEXT` | Group 5 subject ID |
| `g6` | `TEXT` | Group 6 subject ID |
| `other` | `TEXT` | ID(s) of other class(es) taken, space seperated |
### `timetable`
| Column | Data type | Description |
| ----------- | --------- | --------------------------------------------- |
| `day` | `TEXT` | Day of the week (e.g. `monday`) |
| `end_time` | `TEXT` | Ending time of lesson (e.g. `09:55`, `13:05`) |
| `lesson_id` | `TEXT` | Subject ID of the lesson (e.g. `tok`) |
| Column | Data type | Description |
| -------------- | --------- | --------------------------------------------- |
| `lesson_class` | `INTEGER` | IB class which takes lesson (e.g. `1`) |
| `day` | `TEXT` | Day of the week (e.g. `monday`) |
| `end_time` | `TEXT` | Ending time of lesson (e.g. `09:55`, `13:05`) |
| `lesson_id` | `TEXT` | Subject ID of the lesson (e.g. `tok`) |
#### Subject IDs
Subject IDs may be anything, as long as consistency is maintained throughout the tables. There are two hard-coded IDs that are always taken by every student:
| Subject | ID |
| ------------------- | ----- |
| Theory of Knowledge | `tok` |
| Guidance | `gu` |
Subject IDs may be anything, as long as consistency is maintained throughout the tables.
## License

View File

@ -4,7 +4,7 @@ To-Do List
## v0.2
- [x] Error handling (when entering invalid data types)
- [x] Make database contain data for all classes
- [ ] Flexible mandatory subjects
- [x] Flexible mandatory subjects
## v0.3
- [x] make script functional (sorta)

View File

@ -31,34 +31,36 @@ def connect_database(file):
def get_data(conn):
"""
Requests student ID and returns integer tuple (id, class) with valid
student id and corresponding class no.
student id, corresponding class no. (1 or 2) and extra subject IDs.
:param conn: Connection object
"""
try:
id = int(input("Please enter student ID: "))
cur = conn.cursor()
cur.execute("SELECT id, student_class FROM students")
cur.execute("SELECT id, student_class, other FROM students")
ids = cur.fetchall()
for x in ids:
# ids is list with single value tuples
if id == x[0]:
# return tuple x with valid id and corresponding class no.
return x
for tup in ids:
# ids is list of tuples
if id == tup[0]:
# return tuple x with valid id, class and extra class IDs
lis = list(tup)
lis[2] = lis[2].split()
return lis
else:
raise ValueError
except ValueError:
print("Incorrect ID, try again.")
print("Invalid ID, try again.")
return get_data(conn)
def select_final_time(conn, day, stud):
def select_final_time(conn, day, stuple):
"""
Returns ending time of final lesson student must attend, or None.
:param conn: Connection object
:param day: current weekday, lowercase str
:param stud: tuple with student ID no. and class no., int
:param stuple: tuple with student ID no. and class no., int
"""
cur = conn.cursor()
cur.execute("""
@ -70,19 +72,45 @@ def select_final_time(conn, day, stud):
OR g4 = lesson_id
OR g5 = lesson_id
OR g6 = lesson_id
OR lesson_id = 'gu'
OR lesson_id = 'tok'
WHERE id = ?
AND day = ?
AND lesson_class = ?
ORDER BY end_time DESC
LIMIT 1
""", (stud[0], day, stud[1]))
finish = cur.fetchone()
if str(type(finish)) == "<class 'tuple'>":
return finish[0]
""", (stuple[0], day, stuple[1]))
ib_finish = cur.fetchone()
if ib_finish != None:
ib_finish = parse_time_string(ib_finish[0])
others = []
for sub in stuple[2]:
cur.execute("""
SELECT end_time
FROM timetable
INNER JOIN students ON ? = lesson_id
WHERE id = ?
AND day = ?
AND lesson_class = ?
ORDER BY end_time DESC
LIMIT 1
""", (sub, stuple[0], day, stuple[1]))
other_final = cur.fetchone()
if other_final != None:
others.append(parse_time_string(other_final[0]))
if not others:
other_finish = None
else:
return finish
other_finish = max(others)
if ib_finish != None and other_finish != None:
if ib_finish > other_finish:
finish = ib_finish
else:
finish = other_finish
else:
finish = None
return finish
def parse_time_string(timestring):
@ -101,19 +129,19 @@ def main():
conn = connect_database("database.db")
while True:
id = get_data(conn)
student_data = get_data(conn)
day = time.strftime("%A").lower()
finish_time = select_final_time(conn, day, id)
current_time = time.strftime("%H:%M")
finish_time = select_final_time(conn, day, student_data)
current_time = parse_time_string(time.strftime("%H:%M"))
if finish_time == None:
print("Student has no lessons today, clear to leave.")
elif parse_time_string(finish_time) < parse_time_string(current_time):
elif finish_time < current_time:
print("Student has finished for today, clear to leave.")
else:
print("Student still has lessons, clearance not granted.")
if input("Enter y to run again.") != "y":
if input("Enter y to run again.") not in ["y", "Y"]:
break