-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattendance_models.py
85 lines (64 loc) · 1.95 KB
/
attendance_models.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from parse_rest.datatypes import Object
from parse_rest.connection import register
from datetime import datetime, date, time
import config
import seeds
register(config.application_id, config.client_key)
class Event(Object):
pass
class Attendance(Object):
pass
class AttendanceMatrix(Object):
pass
"""pull data from parse"""
def event_dict():
return dict((x.eid, x) for x in all_events())
def event_name_dict():
return dict((x.name, x) for x in all_events())
def all_events():
return Event.Query.all().limit(100000)
def pull_attendance_matrix():
return np.asarray(AttendanceMatrix.Query.all()[0].attendance_matrix)
def save_attendance_matrix(attendance_matrix):
am = AttendanceMatrix.Query.all()[0]
am.attendance_matrix = np.asarray(attendance_matrix)
am.save()
def reset_attendance_matrix():
am = get_attendance_matrix()
save_attendance_matrix(am)
def update_attendance_matrix(i, j, value, attendance_matrix):
""" updates attendance matrix, setting mat[i,j] = value
push result to parse and update cache?
"""
print 'updating attendance_matrix'
attendance_matrix[i][j] = value
save_attendance_matrix(attendance_matrix)
"""test of numpy operations"""
import numpy as np
def get_attendance_matrix(member_dict):
edict = event_dict()
mdict = member_dict
max_eid = max(edict.keys())+1
max_mid = max(mdict.keys())+1
attendance_matrix = np.zeros((max_mid, max_eid))
for eid in edict:
eslice = edict[eid].attendance
attendance_matrix[eslice, eid] = 2 # dont account for 1s
return attendance_matrix
if __name__=='__main__':
# print seeds.all_members()
from werkzeug.contrib.cache import SimpleCache
cache = SimpleCache()
member_dict = seeds.member_dict(cache)
am = get_attendance_matrix(member_dict)
save_attendance_matrix(am)
print 'updated am'
# reset_attendance_matrix()
# print member.name
# try:
# member.cid = inv_c[member.committee]
# member.save()
# except:
# member.cid = 100
# member.save()
# generate_sample_attendance()