-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
115 lines (81 loc) · 3.44 KB
/
helper.py
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
from typing import List
from rich.console import Console
from rich.table import Table
from models import ReportCard, ReportCardSubject
# helper functions
def get_choice_from_menu(menu: str, handlers: dict):
print(menu)
choice = input("Enter your Option: ")
while (choice not in handlers.keys()):
print('Invalid Option')
choice = input("Enter your Option: ")
return choice
def get_query_from_student_search_params(search_params: list):
queryList = []
for index,param in enumerate(search_params):
if len(param) == 0:
continue
if index == ReportCard.INDEX_EXAM_NAME:
queryList.append(ReportCard.exam_name.ilike(f"%{ param }%"))
# index 0 is name
if index == ReportCard.INDEX_NAME:
queryList.append(ReportCard.student_name.ilike(f"%{ param }%"))
# index 1 is admision number
if index == ReportCard.INDEX_CLASS:
queryList.append(ReportCard.student_class.ilike(f"{ param }"))
if index == ReportCard.INDEX_SECTION:
queryList.append(ReportCard.student_section.ilike(f"{ param }"))
if index == ReportCard.INDEX_ADM_NO:
queryList.append(ReportCard.student_addmission_number == param)
return queryList
def pretty_print_report_card(result: List[ReportCard] ):
console = Console()
# extract this to a helper function afterwards
table = Table(show_header=True, header_style="bold green")
table.add_column("ID")
table.add_column("Exam Name")
table.add_column("Student Name")
table.add_column("Admission Number")
table.add_column("Class - Section")
table.add_column("Percentage")
for report_card in result:
# can optimize to use a single loop
max_total_marks = sum([ subject.max_marks for subject in report_card.report_card_subjects ])
obtained_marks = sum([ subject.marks for subject in report_card.report_card_subjects ])
percentage = (obtained_marks / max_total_marks) * 100
percentage = str(round(percentage, 2)) + ' %'
table.add_row(
str(report_card.report_card_id),
report_card.exam_name,
report_card.student_name,
report_card.student_addmission_number,
f"{report_card.student_class} - {report_card.student_section}",
percentage
)
console.print(table)
def pretty_print_report_card_with_subject(result: ReportCard ):
pretty_print_report_card([result])
console = Console()
# extract this to a helper function afterwards
table = Table(show_header=True, header_style="bold green")
table.add_column("S No.")
table.add_column("Subject Name")
table.add_column("Marks Obtained")
table.add_column("Max Marks")
table.add_column("Percentage")
slno = 1
for subject in result.report_card_subjects:
# # can optimize to use a single loop
# max_total_marks = sum([ subject.max_marks for subject in subject.report_card_subjects ])
# obtained_marks = sum([ subject.marks for subject in subject.report_card_subjects ])
percentage = (subject.marks / subject.max_marks) * 100
percentage = str(round(percentage, 2)) + ' %'
table.add_row(
str(slno),
subject.subject_name,
str(subject.marks),
str(subject.max_marks),
percentage
)
slno += 1
console.print(table)