diff options
Diffstat (limited to 'analyze.py')
-rw-r--r-- | analyze.py | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -60,15 +60,16 @@ def get_task_information(fname): def get_student_information(fname):
result = []
-
+ lineno = 1
with open(fname) as f:
for line in f:
line = line.strip()
lst = line.split('\t')
- if len(lst) != 2:
- print('File %s does not have two columns.' % (fname))
- sys.exit()
- result.append((lst[0], lst[1]))
+ if len(lst) == 2:
+ result.append((lst[0], lst[1]))
+ else:
+ print('Warning: Line %d in file %s does not have two columns. Skipped!' % (lineno, fname))
+ lineno += 1
return result
@@ -240,7 +241,7 @@ STUDENT_FILE = 'students.txt' # required file containing student numbers and st 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)'
+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)
print(banner)
@@ -274,7 +275,7 @@ if os.path.exists(EXCLUDE_FILE): if sno != '':
lst.append(sno)
for s in lst:
- print('Do not count %s' % (s))
+ print('Ignore %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))
@@ -307,7 +308,7 @@ for s in student_lst: result += '\n'
result += ' ---\n Total:%4.1f\n' % (total)
file_content += '\t%4.1f\n' % (total)
- #print(result)
+
f = open(GRADE_FILE, 'w')
f.write(file_content)
@@ -320,5 +321,9 @@ num_student = len(student_lst) for x in objective_total:
co = x[0]
value = x[1]
- percentage = 100 * course_object_cumulative_score[co]/(value * num_student)
- print('Course objective %s is %.0f%% satisfied.' % (co, percentage))
+ try:
+ 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))
+
|