| 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176 | 2×
2×
2×
2×
710×
710×
710×
394×
710×
309×
309×
591×
591×
591×
788×
788×
710×
2×
2×
119×
2×
2×
95×
95×
95×
1383×
149×
1091×
96×
96×
96×
96×
96×
15×
81×
81×
403×
40×
40×
40×
65×
2×
| var CrudConfig, Helpers, Student, Teacher, TeacherStudent, _, extendConfig, findAllSections, makeSimpleStore, ref;
ref = require('./helpers'), CrudConfig = ref.CrudConfig, makeSimpleStore = ref.makeSimpleStore, extendConfig = ref.extendConfig;
_ = require('underscore');
findAllSections = function(section) {
var child, i, j, len, len1, ref1, ref2, ref3, sections;
sections = [];
if (((ref1 = section.chapter_section) != null ? ref1.length : void 0) > 1) {
sections.push(section);
}
if (section.children) {
ref2 = section.children;
for (i = 0, len = ref2.length; i < len; i++) {
child = ref2[i];
ref3 = findAllSections(child);
for (j = 0, len1 = ref3.length; j < len1; j++) {
section = ref3[j];
sections.push(section);
}
}
}
return sections;
};
Teacher = makeSimpleStore(extendConfig({
exports: {
getChaptersForPeriod: function(courseId, periodId) {
var period;
period = _.findWhere(this._get(courseId), {
period_id: periodId
});
return (period != null ? period.children : void 0) || [];
},
getSectionsForPeriod: function(courseId, periodId) {
var period;
period = _.findWhere(this._get(courseId), {
period_id: periodId
});
return findAllSections(period);
}
}
}, new CrudConfig));
Student = makeSimpleStore(extendConfig({
exports: {
getSortedSections: function(courseId) {
var sections;
sections = findAllSections(this._get(courseId));
return _.sortBy(sections, function(s) {
return s.clue.value;
});
},
getAllSections: function(courseId) {
return findAllSections(this._get(courseId));
}
}
}, new CrudConfig));
TeacherStudent = makeSimpleStore(extendConfig({
loaded: function(obj, id, arg) {
var base, base1, roleId;
roleId = arg.roleId;
(base = this._asyncStatus)[id] || (base[id] = {});
this._asyncStatus[id][roleId] = 'LOADED';
(base1 = this._local)[id] || (base1[id] = {});
this._local[id][roleId] = obj;
return this.emitChange();
},
load: function(id, arg) {
var base, base1, roleId;
roleId = arg.roleId;
(base = this._asyncStatus)[id] || (base[id] = {});
(base1 = this._reload)[id] || (base1[id] = {});
this._reload[id][roleId] = false;
this._asyncStatus[id][roleId] = 'LOADING';
return this.emitChange();
},
exports: {
getSortedSections: function(courseId, roleId, property) {
var sections;
if (property == null) {
property = 'current_level';
}
sections = findAllSections(this._get(courseId));
return _.sortBy(sections, property);
},
get: function(courseId, arg) {
var ref1, roleId;
roleId = arg.roleId;
return (ref1 = this._local[courseId]) != null ? ref1[roleId] : void 0;
},
getChapters: function(courseId, arg) {
var guide, ref1, roleId;
roleId = arg.roleId;
guide = (ref1 = this._local[courseId]) != null ? ref1[roleId] : void 0;
return (guide != null ? guide.children : void 0) || [];
},
getAllSections: function(courseId, arg) {
var ref1, roleId;
roleId = arg.roleId;
return findAllSections(((ref1 = this._local[courseId]) != null ? ref1[roleId] : void 0) || {});
},
reload: function(id, arg) {
var ref1, roleId;
roleId = arg.roleId;
return (ref1 = this._reload[id]) != null ? ref1[roleId] : void 0;
},
isLoading: function(id, arg) {
var ref1, roleId;
roleId = arg.roleId;
return ((ref1 = this._asyncStatus[id]) != null ? ref1[roleId] : void 0) === 'LOADING';
},
isLoaded: function(id, arg) {
var ref1, roleId;
roleId = arg.roleId;
return ((ref1 = this._asyncStatus[id]) != null ? ref1[roleId] : void 0) === 'LOADED';
}
}
}, new CrudConfig));
Helpers = {
recentSections: function(sections, limit) {
Eif (limit == null) {
limit = 4;
}
return _.last(sections, limit);
},
canDisplayForecast: function(clue, sampleSizeThreshold) {
return clue.sample_size >= sampleSizeThreshold || clue.sample_size_interpretation !== 'below';
},
filterForecastedSections: function(sections, sampleSizeThreshold) {
return _.filter(sections, function(s) {
return Helpers.canDisplayForecast(s.clue, sampleSizeThreshold);
});
},
weakestSections: function(sections, sampleSizeThreshold, displayCount) {
var validSections;
Eif (displayCount == null) {
displayCount = 4;
}
validSections = this.filterForecastedSections(sections, sampleSizeThreshold);
if (!(validSections.length >= 2)) {
return [];
}
displayCount = Math.min(Math.max(1, Math.floor(validSections.length / 2)), displayCount);
return _.chain(validSections).sortBy(function(s) {
return s.clue.value;
}).first(displayCount).value();
},
canPracticeWeakest: function(arg) {
var displayCount, minimumSectionCount, sampleSizeThreshold, sections;
sections = arg.sections, sampleSizeThreshold = arg.sampleSizeThreshold, displayCount = arg.displayCount, minimumSectionCount = arg.minimumSectionCount;
displayCount || (displayCount = 4);
minimumSectionCount || (minimumSectionCount = 1);
return this.weakestSections(sections, displayCount).length >= minimumSectionCount;
},
canDisplayWeakest: function(arg) {
var sampleSizeThreshold, sections;
sections = arg.sections, sampleSizeThreshold = arg.sampleSizeThreshold;
return this.filterForecastedSections(sections).length > 1;
},
pagesForSections: function(sections) {
return _.chain(sections).pluck('page_ids').flatten().uniq().value();
}
};
module.exports = {
Student: Student,
Teacher: Teacher,
TeacherStudent: TeacherStudent,
Helpers: Helpers
};
|