check degrees

This commit is contained in:
Coding with Peter 2023-05-22 13:35:47 -07:00
parent 484cc4235f
commit e339795c94
2 changed files with 113 additions and 38 deletions

View File

@ -1,5 +1,5 @@
from lark import Lark, Transformer, v_args
import json
import json, sys, re
@ -155,48 +155,96 @@ grammar = """
"""
def parser():
dsl = """
course CSIS1 2 units
course CSIS2 4 units
course ACCT120 3 units
course ACCT20 4 units
course BUS1 3 units
course ENGL250 3 units
course ACCT105 3 units
course ACCT121 3 units
course BOT100 3 units
course BOT105B 3 units
dsl = """
course CSIS1 2 units
course CSIS2 4 units
course ACCT120 3 units
course ACCT20 4 units
course BUS1 3 units
course ENGL250 3 units
course ACCT105 3 units
course ACCT121 3 units
course BOT100 3 units
course BOT105B 3 units
program BusinessAccountingOption
take all from CSIS1, CSIS2
take at least 6 units from ACCT120, ACCT20
take at least 3 courses from BUS1, ENGL250, ACCT120, BOT100, ACCT121, BOT105B
"""
program BusinessAccountingOption
take all from CSIS1, CSIS2
take at least 6 units from ACCT120, ACCT20
take at least 3 courses from BUS1, ENGL250, ACCT120, BOT100, ACCT121, BOT105B
"""
parser = Lark(grammar)
print(parser.parse(dsl).pretty())
parser = Lark(grammar)
print(parser.parse(dsl).pretty())
print("\n\n\n")
print("\n\n\n")
parser = Lark(grammar)
transformer = DSLTransformer()
def parse_dsl(dsl):
tree = parser.parse(dsl)
return transformer.transform(tree)
result = parse_dsl(dsl)
print(transformer.courses)
print()
print(transformer.degrees)
print()
[print(c) for c in transformer.courses]
print()
[print(d) for d in transformer.degrees]
def rule_check_units():
# Define the course units and passing grades
course_units = {
"A": 1,
"B": 2,
"C": 1,
"D": 3
}
# Define the students and their passed courses
students = {
"Peter": ["A", "B", "C"],
"Mark": ["D", "B"],
"Susan": ["A", "B"]
}
# Define the minimum units required to graduate
min_units_to_graduate = 4
calcs = {}
for student, passed_courses in students.items():
print("\n", student, passed_courses)
for c in passed_courses:
print(f"\t{c:15} {course_units[c]}")
print(f"\t{'Total':15} {sum(course_units[c] for c in passed_courses)}")
# Determine the graduating students
graduating_students = [
student for student, passed_courses in students.items()
if sum(course_units[course] for course in passed_courses) >= min_units_to_graduate
]
# Print the graduating students
if graduating_students:
print("The graduating students are:", ", ".join(graduating_students))
else:
print("No students meet the graduation requirements.")
parser = Lark(grammar)
transformer = DSLTransformer()
def parse_dsl(dsl):
tree = parser.parse(dsl)
return transformer.transform(tree)
result = parse_dsl(dsl)
print(transformer.courses)
print()
print(transformer.degrees)
print()
[print(c) for c in transformer.courses]
print()
[print(d) for d in transformer.degrees]
"""
@ -217,4 +265,30 @@ def compute_degree_progress(student_courses, degree):
progress_percent = total_units_completed / total_required_units * 100 if total_required_units > 0 else 0
return progress_percent
"""
"""
if __name__ == "__main__":
options = { 1: ['parsing example',parser] ,
2: ['rule check by units',rule_check_units] ,
}
print ('')
if len(sys.argv) > 1 and re.search(r'^\d+',sys.argv[1]):
resp = int(sys.argv[1])
print("\n\nPerforming: %s\n\n" % options[resp][0])
else:
print ('')
for key in options:
print(str(key) + '.\t' + options[key][0])
print('')
resp = input('Choose: ')
# Call the function in the options dict
options[ int(resp)][1]()

View File

@ -41,7 +41,7 @@ last_4_semesters_ids = [168, 65, 64, 62]
log_default_startdate = "2021-08-23T00:00:00-07:00"
lds_stamp = parser.parse(log_default_startdate)
recvd_date = '2021-08-23T00:00:00Z'
recvd_date = '2023-01-01T00:00:00Z'
num_threads = 25
max_log_count = 250000
@ -1789,8 +1789,9 @@ def track_user(id=0,qid=0):
url_addition = ""
if 1: # hard code dates
url_addition = "?start_time=%s&end_time=%s" % ( '2022-06-15T00:00:00-07:00', '2022-12-31T00:00:00-07:00' )
start_date = "2023-01-01T00:00:00-07:00"
end_date = "2023-08-01T00:00:00-07:00"
url_addition = f"?start_time={start_date}&end_time={end_date}"
elif 'last_days_log' in info:
print("There's existing log data for %s (%s)" % (info['name'] , info['sis_user_id']))
print("Last day logged was: %s" % info['last_days_log'])