diff options
Diffstat (limited to 'analyze.py')
-rw-r--r-- | analyze.py | 41 |
1 files changed, 21 insertions, 20 deletions
@@ -20,7 +20,7 @@ #
#
# Limitations:
-#
+#
# For simplicity, I recommend associating one and only one co to each
# task, whether the task is an assignment, a quiz, a lab, or a test
# question. In the case of having more than one co's in a task, a
@@ -44,7 +44,9 @@ #
# Contact the author if you encounter any problems: Hui Lan <lanhui@zjnu.edu.cn>
-import json, os, sys
+import json
+import os
+import sys
# Solve UnicodeDecodeError - https://blog.csdn.net/blmoistawinde/article/details/87717065
import _locale
@@ -93,14 +95,14 @@ def get_student_number(fname): if s.startswith(codecs.BOM_UTF8):
print('\nERROR: The file %s contains BOM character. Remove that first.' % (fname))
sys.exit()
-
+
f = open(fname)
for line in f:
line = line.strip()
if not line.startswith('#'):
lst = line.split('\t')
sno = lst[0] # student number
- d[sno] = lst[2] # score
+ d[sno] = lst[2] # score
f.close()
return d
@@ -133,18 +135,18 @@ def make_individual_grade_files(grade_dir, task_dict, student_lst): for sno in d:
if not sno in student_numbers:
inconsistency = 1
- print('Warning: %s is in the old grade file, but is not in the new student file.' % (sno))
+ print('Warning: %s is in the old grade file, but is not in the new student file.' % (sno))
if inconsistency == 1:
print('Warning: I am keeping the available scores.')
-
+
f = open(new_file)
s = f.read()
f.close()
-
- f = open(new_file + '.old', 'w')
+
+ f = open(new_file + '.old', 'w')
f.write(s)
f.close()
-
+
f = open(new_file, 'w')
f.write('#' + task + '\n')
f.write('\t'.join(['#student.no', 'student.name', 'score']) + '\n')
@@ -153,7 +155,7 @@ def make_individual_grade_files(grade_dir, task_dict, student_lst): f.write('\t'.join([student[0], student[1], '%s' % d[student[0]]]) + '\n')
else:
f.write('\t'.join([student[0], student[1], '0']) + '\n')
- f.close()
+ f.close()
def make_score_dict(fname):
@@ -201,7 +203,7 @@ def get_objective_total(d): if check_sum != 100:
print('Objective total is not 100 (%d instead). Make sure you have divide the objective scores across tasks correctly.' % (check_sum))
sys.exit()
- return result # [(objective1, value1), (objective2, value2), ...]
+ return result # [(objective1, value1), (objective2, value2), ...]
def check_availability(fname):
@@ -232,7 +234,6 @@ def all_gone(student_lst, lst): return True
-
# main
GRADE_DIR = 'grade'
TASK_FILE = 'tasks.json' # required file containing course objectives and tasks.
@@ -240,10 +241,10 @@ 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
+GRADE_FILE = 'grade_file.xls' # output
software_information = 'Course Objective Fulfillment Calculator\nCopyright (C) 2019,2020,2022 Lan Hui (lanhui@zjnu.edu.cn)'
n = max([len(s) for s in software_information.split('\n')])
-banner = '%s\n%s\n%s' % ('-'*n, software_information, '-'*n)
+banner = '%s\n%s\n%s' % ('-' * n, software_information, '-' * n)
print(banner)
task_dict = get_task_information(TASK_FILE)
@@ -300,16 +301,16 @@ for s in student_lst: total += float(score)
for co in task_dict['course.objectives']:
if co in task_dict['tasks'][task]:
- my_share = 1.0*float(score) * task_dict['tasks'][task][co] / total_score
+ my_share = 1.0 * float(score) * task_dict['tasks'][task][co] / total_score
course_object_cumulative_score[co] += my_share
- result += ' [%4.1f] ' % ( my_share )
+ result += ' [%4.1f] ' % (my_share)
else:
result += ' [%4.1f] ' % (0)
result += '\n'
result += ' ---\n Total:%4.1f\n' % (total)
file_content += '\t%4.1f\n' % (total)
-
+
f = open(GRADE_FILE, 'w')
f.write(file_content)
f.close()
@@ -319,10 +320,10 @@ print('Check spreadsheet %s.' % (GRADE_FILE)) objective_total = get_objective_total(task_dict)
num_student = len(student_lst)
for x in objective_total:
- co = x[0] # name of the course objective
- value = x[1] # the associated total value of that course objective
+ co = x[0] # name of the course objective
+ value = x[1] # the associated total value of that course objective
try:
- percentage = 100 * course_object_cumulative_score[co]/(value * num_student)
+ percentage = 100 * course_object_cumulative_score[co] / (value * num_student)
print('Course objective %s is %.0f%% satisfied.' % (co, percentage))
except:
print('Error: value = %4.1f, num_student = %4.1f' % (value, num_student))
|