-
Notifications
You must be signed in to change notification settings - Fork 0
/
att2bb.py
executable file
·66 lines (53 loc) · 1.69 KB
/
att2bb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""
Convert an iOS attendance file report to one uploadable to Blackboard.
"""
import sys # file I/O
import csv # to parse the main CSV file
import logging
import argparse
parser = argparse.ArgumentParser(description='convert attendance report to Blackboard upload')
parser.add_argument('--verbose',help='be verbose',action='store_const',const=logging.INFO,dest='debug_level',default=logging.WARNING)
parser.add_argument('--debug',help='show debugging statements',action='store_const',const=logging.DEBUG,dest='debug_level',default=logging.WARNING)
parser.add_argument('file',help='name of the CSV file')
args = parser.parse_args()
logging.basicConfig(level=args.debug_level)
records = csv.reader(open(args.file, 'r'))
# first row has course name and date
# TODO: allow for multiple dates
rec=next(records)
logging.debug("first record: %s",repr(rec))
course=rec.pop(0)
logging.debug("course=%s",course)
dates=[]
rec.pop(0) # next field is blank
for date in rec:
if(date != ''):
dates.append('Attendance %s' % date)
logging.debug("dates=%s",dates)
# second row is blank
next(records)
# rest of the rows are student records
report=[]
for row in records:
logging.debug("Processing row: %s",repr(row))
name=row.pop(0)
netid=row.pop(0)
logging.debug("NetID=%s")
reportrow=[netid]
for date in dates:
status=row.pop(0)
note=row.pop(0)
score = 1 if (status=='Present') else 0
score+= len(note)
logging.debug("score(%s)=%s",date,score)
reportrow.append("%.2f" % score)
report.append(reportrow)
# output
writer=csv.writer(sys.stdout)
headers=['Username']
headers.extend(dates)
logging.debug('headers=%s',repr(headers))
writer.writerow(headers)
for row in report:
writer.writerow(row)