diff options
Diffstat (limited to 'analyze.py')
-rw-r--r-- | analyze.py | 49 |
1 files changed, 48 insertions, 1 deletions
@@ -12,6 +12,11 @@ # - tasks.json: a plain text file in JSON format specifying the course objectives and tasks in this course.
# Each task is associated to at least one course objective (co). Each co in a task has an associated weight.
# Make sure that all weights across tasks sum to 100.
+# Optional files:
+#
+# - exclude.txt: a plain text file specifying a list of student numbers (one per line) which we do not want to include
+# while computing the course objective fulfillment percentage.
+#
#
#
# Limitations:
@@ -35,7 +40,7 @@ # could break down the task into several sub-tasks such that each
# sub-task corresponds to only one course objective.
#
-# Copyright (C) 2019, 2020 Hui Lan
+# Copyright (C) 2019, 2020, 2021 Hui Lan
#
# Contact the author if you encounter any problems: Hui Lan <lanhui@zjnu.edu.cn>
@@ -204,12 +209,36 @@ def check_availability(fname): sys.exit()
+def remove_a_student(student_lst, s):
+ ''' student_lst is a list of tuples, each tuple in the form like (student_no, student_name).
+ s is a student number. Effect: student_lst shortened.
+ '''
+ index = 0
+ for x in student_lst:
+ sno = x[0]
+ if sno == s:
+ student_lst.pop(index)
+ return None
+ index += 1
+
+
+def all_gone(student_lst, lst):
+ ''' Return True iff none of the student number in lst is in student_lst'''
+ for x in student_lst:
+ sno = x[0]
+ if sno in lst:
+ return False
+ return True
+
+
+
# main
GRADE_DIR = 'grade'
TASK_FILE = 'tasks.json' # required file containing course objectives and tasks.
check_availability(TASK_FILE)
STUDENT_FILE = 'students.txt' # required file containing student numbers and student names.
check_availability(STUDENT_FILE)
+EXCLUDE_FILE = 'exclude.txt'
GRADE_FILE = 'grade_file.xls' # output
software_information = 'Course Objective Fulfillment Calculator\nCopyright (C) 2019 Hui Lan (lanhui@zjnu.edu.cn)'
n = max([len(s) for s in software_information.split('\n')])
@@ -219,6 +248,7 @@ print(banner) task_dict = get_task_information(TASK_FILE)
student_lst = get_student_information(STUDENT_FILE)
make_individual_grade_files(GRADE_DIR, task_dict, student_lst)
+print('Seen %d students.' % (len(student_lst)))
# output results to terminal and file
head_lst = ['student.no', 'student.name']
@@ -233,6 +263,23 @@ course_object_cumulative_score = {} for co in task_dict['course.objectives']:
course_object_cumulative_score[co] = 0
+# Exclude some students from student list student_lst. The excluded students are specified in a file called exclude.txt.
+if os.path.exists(EXCLUDE_FILE):
+ lst = []
+ print('Read excluded students from %s.' % (EXCLUDE_FILE))
+ with open(EXCLUDE_FILE) as f:
+ for line in f:
+ line = line.strip()
+ if line != '':
+ lst.append(line)
+ for s in lst:
+ print('Do not count %s' % (s))
+ remove_a_student(student_lst, s)
+ assert all_gone(student_lst, lst) == True
+ print('Still have %d students after excluding the undesired students specified in %s.' % (len(student_lst), EXCLUDE_FILE))
+
+
+# Do statistics
for s in student_lst:
sno = s[0]
sname = s[1]
|