script to get student statistics from cms
parent
ebe7480738
commit
8e9150055c
|
@ -0,0 +1,43 @@
|
|||
import os
|
||||
import cakecms
|
||||
|
||||
HOST = 'https://cms.cispa.saarland'
|
||||
TOKEN = os.environ['CMS_TOKEN']
|
||||
|
||||
cms = cakecms.CakeCMS(HOST, TOKEN)
|
||||
# [optional] log queries to console
|
||||
#cms.debug = True
|
||||
# get a course list (dictionary)
|
||||
courses = cms.courses_index()
|
||||
|
||||
# filter
|
||||
courses = [course for course in courses if course['Course']['course_type'] == 'Advanced Lecture']
|
||||
courses.sort(key=lambda c: c['Course']['name'])
|
||||
|
||||
# get subjects
|
||||
summary = {}
|
||||
for course in courses:
|
||||
coursename = course['Course']['name'] + ' ' + course['Course']['term']
|
||||
if course['Course']['term'] == 'SS':
|
||||
coursename += ' ' + str(course['Course']['term_year'])
|
||||
else:
|
||||
coursename += ' ' + str(course['Course']['term_year'])[2:] + '/' + str(course['Course']['term_year']+1)[2:]
|
||||
students = cms.students_index(course['Course']['shortname'], ['Sm', 'Ss'])
|
||||
if len(students['students']) == 0:
|
||||
continue
|
||||
subjects = {}
|
||||
for student in students['students']:
|
||||
subject = student['Student']['subject']
|
||||
subjects[subject] = subjects.get(subject, 0) + 1
|
||||
totalcount = sum(subjects.values())
|
||||
print(f'=== {coursename} ({course["Course"]["course_type"]}) ===')
|
||||
for subject, count in sorted(subjects.items(), key=lambda kv: -kv[1]):
|
||||
print(f'- {count:3d} ({count*100.0/totalcount:5.1f}%) {subject}')
|
||||
print('\n')
|
||||
summary[coursename] = (subjects.get('Cybersicherheit', 0) + subjects.get('Entrepreneurial Cybersecurity', 0), totalcount)
|
||||
#break
|
||||
|
||||
|
||||
print('=== Summary ===')
|
||||
for coursename, (cysec, count) in sorted(summary.items(), key=lambda x: x[0]):
|
||||
print(f'{cysec:3d} / {count:3d} ({cysec*100.0 / count:5.1f}%) {coursename}')
|
Loading…
Reference in New Issue