Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
199 lines (161 loc) · 6.21 KB
/
Copy pathmain.py
File metadata and controls
199 lines (161 loc) · 6.21 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import typer
from rich.console import Console
from course_db.models.calendar import Calendar
from course_db.repository.google_sheets import load, save
from course_db.services.big_table import BigTable
from course_db.services.grading import components_2025, grading_2025
from course_db.services.visualization import render_table
from course_db.services.calendar import load_calendar
app = typer.Typer()
table = BigTable(components=components_2025, grading=grading_2025)
# Student CRUD
@app.command()
def add_student(
first_name: str = typer.Argument(..., help="Student's first name"),
last_name: str = typer.Argument(..., help="Student's last name"),
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
):
"""Add a new student."""
student = table.add_student(first_name, last_name, faculty_number)
typer.echo(
f"Added: {student.first_name} {student.last_name} ({student.faculty_number})"
)
@app.command()
def get_student(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
):
"""Get a student by faculty number."""
student = table.get_by_faculty_number(faculty_number)
if student is None:
typer.echo(
f"No student found with faculty number '{faculty_number}'.", err=True
)
raise typer.Exit(1)
typer.echo(
f"{student.first_name} {student.last_name} ({student.faculty_number}), bonus={student.bonus}"
)
@app.command()
def search_student(
query: str = typer.Argument(..., help="Name query to search for"),
):
"""Search students by name."""
students = table.get_by_name(query)
if not students:
typer.echo("No students found.")
return
for s in students:
typer.echo(f"{s.first_name} {s.last_name} ({s.faculty_number})")
@app.command()
def update_student(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
first_name: str = typer.Option(None, help="New first name"),
last_name: str = typer.Option(None, help="New last name"),
):
"""Update a student's name fields."""
kwargs = {}
if first_name is not None:
kwargs["first_name"] = first_name
if last_name is not None:
kwargs["last_name"] = last_name
if not kwargs:
typer.echo("No fields to update provided.", err=True)
raise typer.Exit(1)
student = table.update_student(faculty_number, **kwargs)
typer.echo(
f"Updated: {student.first_name} {student.last_name} ({student.faculty_number})"
)
@app.command()
def delete_student(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
):
"""Delete a student by faculty number."""
table.delete_student(faculty_number)
typer.echo(f"Deleted student with faculty number '{faculty_number}'.")
# Component points CRUD
@app.command()
def set_points(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
component_name: str = typer.Argument(..., help="Component name"),
points: float = typer.Argument(..., help="Points to set"),
):
"""Set points for a component."""
component = table.set_points(faculty_number, component_name, points)
typer.echo(f"Set '{component.name}' to {component.points}/{component.max_points}")
@app.command()
def get_points(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
component_name: str = typer.Argument(..., help="Component name"),
):
"""Get points for a component."""
points = table.get_points(faculty_number, component_name)
typer.echo(f"'{component_name}': {points}")
@app.command()
def clear_points(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
component_name: str = typer.Argument(..., help="Component name"),
):
"""Clear points for a component."""
component = table.clear_points(faculty_number, component_name)
typer.echo(f"Cleared '{component.name}' (was {component.points})")
# Bonus points CRUD
@app.command()
def set_bonus(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
bonus: int = typer.Argument(..., help="Bonus points to set (0-5)"),
):
"""Set bonus points for a student."""
student = table.set_bonus(faculty_number, bonus)
typer.echo(f"Bonus for {student.faculty_number} set to {student.bonus}")
@app.command()
def get_bonus(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
):
"""Get bonus points for a student."""
bonus = table.get_bonus(faculty_number)
typer.echo(f"Bonus for '{faculty_number}': {bonus}")
@app.command()
def clear_bonus(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
):
"""Clear bonus points for a student."""
student = table.clear_bonus(faculty_number)
typer.echo(f"Bonus for {student.faculty_number} cleared (now {student.bonus})")
@app.command()
def add_bonus_point(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
):
"""Add one bonus point to a student."""
student = table.add_bonus_point(faculty_number)
typer.echo(f"Bonus for {student.faculty_number} is now {student.bonus}")
# Totals and grading
@app.command()
def get_total_points(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
):
"""Get total points for a student."""
total = table.get_total_points_for_student(faculty_number)
typer.echo(f"Total points for '{faculty_number}': {total}")
@app.command()
def calculate_grade(
faculty_number: str = typer.Argument(..., help="Student's faculty number"),
):
"""Calculate the final grade for a student."""
grade = table.calculate_grade(faculty_number)
typer.echo(f"Grade for '{faculty_number}': {grade}")
@app.command()
def load_table(
summary: bool = typer.Option(
False,
"--summary/--no-summary",
help="Show summary view (name, total, grade) instead of full table.",
),
):
"""Load student data from a Google Sheets document and display it."""
loaded = load("1NTZ26M6tKWzb5g7t0B83i4J-dQrqh7O-TnlAPxd4gsw")
Console().print(render_table(loaded, summary=summary))
@app.command()
def get_calendar():
result = load_calendar()
typer.echo(result.model_dump())
if __name__ == "__main__":
app()