forked from bigdata-ustc/EduCAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset.py
62 lines (50 loc) · 1.72 KB
/
dataset.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
from collections import defaultdict, deque
class Dataset(object):
def __init__(self, data, concept_map,
num_students, num_questions, num_concepts):
"""
Args:
data: list, [(sid, qid, score)]
concept_map: dict, concept map {qid: cid}
num_students: int, total student number
num_questions: int, total question number
num_concepts: int, total concept number
"""
self._raw_data = data
self._concept_map = concept_map
self.n_students = num_students
self.n_questions = num_questions
self.n_concepts = num_concepts
# reorganize datasets
self._data = {}
for sid, qid, correct in data:
self._data.setdefault(sid, {})
self._data[sid].setdefault(qid, {})
self._data[sid][qid] = correct
student_ids = set(x[0] for x in data)
question_ids = set(x[1] for x in data)
concept_ids = set(sum(concept_map.values(), []))
assert max(student_ids) < num_students, \
'Require student ids renumbered'
assert max(question_ids) < num_questions, \
'Require student ids renumbered'
assert max(concept_ids) < num_concepts, \
'Require student ids renumbered'
@property
def num_students(self):
return self.n_students
@property
def num_questions(self):
return self.n_questions
@property
def num_concepts(self):
return self.n_concepts
@property
def raw_data(self):
return self._raw_data
@property
def data(self):
return self._data
@property
def concept_map(self):
return self._concept_map