-
Notifications
You must be signed in to change notification settings - Fork 9
/
gradeable.h
260 lines (223 loc) · 8.6 KB
/
gradeable.h
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#ifndef _GRADEABLE_H_
#define _GRADEABLE_H_
#include <string>
#include <vector>
#include <map>
enum class GRADEABLE_ENUM {
HOMEWORK, ASSIGNMENT, PROBLEM_SET,
QUIZ, TEST, EXAM,
EXERCISE, LECTURE_EXERCISE, READING, WORKSHEET, LAB, RECITATION,
PROJECT, PARTICIPATION, NOTE,
NONE };
inline std::string gradeable_to_string(const GRADEABLE_ENUM &g) {
if (g == GRADEABLE_ENUM::HOMEWORK) { return "HOMEWORK"; }
if (g == GRADEABLE_ENUM::ASSIGNMENT) { return "ASSIGNMENT"; }
if (g == GRADEABLE_ENUM::PROBLEM_SET) { return "PROBLEM_SET"; }
if (g == GRADEABLE_ENUM::QUIZ) { return "QUIZ"; }
if (g == GRADEABLE_ENUM::TEST) { return "TEST"; }
if (g == GRADEABLE_ENUM::EXAM) { return "EXAM"; }
if (g == GRADEABLE_ENUM::EXERCISE) { return "EXERCISE"; }
if (g == GRADEABLE_ENUM::LECTURE_EXERCISE) { return "LECTURE_EXERCISE"; }
if (g == GRADEABLE_ENUM::READING) { return "READING"; }
if (g == GRADEABLE_ENUM::WORKSHEET) { return "WORKSHEET"; }
if (g == GRADEABLE_ENUM::LAB) { return "LAB"; }
if (g == GRADEABLE_ENUM::RECITATION) { return "RECITATION"; }
if (g == GRADEABLE_ENUM::PROJECT) { return "PROJECT"; }
if (g == GRADEABLE_ENUM::PARTICIPATION) { return "PARTICIPATION"; }
if (g == GRADEABLE_ENUM::NOTE) { return "NOTE"; }
if (g == GRADEABLE_ENUM::NONE) { return "NONE"; }
std::cerr << "ERROR! UNKNOWN GRADEABLE" << std::endl;
exit(0);
}
inline std::string tolower(const std::string &s) {
std::string answer;
for (unsigned int i = 0; i < s.size(); i++) {
answer += tolower(s[i]);
}
return answer;
}
inline std::string spacify(const std::string &s) {
std::string tmp = "";
for (unsigned int i = 0; i < s.size(); i++) {
tmp += std::string(1,s[i]) + " ";
}
return tmp;
}
// ===============================================================================
class Gradeable {
public:
// CONSTRUTORS
Gradeable() { count=0;percent=0;remove_lowest=0; }
Gradeable(int c, float p) : count(c),percent(p) { remove_lowest=0; }
// ACCESSORS
int getCount() const { return count; }
float getPercent() const { return percent; }
float getBucketPercentageUpperClamp() const { return this->bucket_percentage_upper_clamp; }
float getMaximum() const {
if (maximums.size() == 0) return 0;
assert (maximums.size() > 0);
float max_sum = 0;
for (std::map<std::string,float>::const_iterator itr = maximums.begin();
itr != maximums.end(); itr++) {
max_sum += itr->second;
}
return max_sum * getCount() / maximums.size();
}
int getRemoveLowest() const { return remove_lowest; }
std::string getID(int index) const {
std::map<std::string,std::pair<int,std::string> >::const_iterator itr = correspondences.begin();
while (itr != correspondences.end()) {
if (itr->second.first == index) return itr->first;
itr++;
}
return "";
}
void isResubmit(int index,
std::string &original_id, std::string &resubmit_id,
float &autograde_replacement_percentage) {
std::string id = getID(index);
if (original_ids.find(id) == original_ids.end()) return;
assert (resubmit_ids.find(id) != resubmit_ids.end());
assert (autograde_replacement_percentages.find(id) != autograde_replacement_percentages.end());
original_id = original_ids.find(id)->second;
resubmit_id = resubmit_ids.find(id)->second;
autograde_replacement_percentage = autograde_replacement_percentages.find(id)->second;
}
bool hasCorrespondence(const std::string &id) const {
/*
for (std::map<std::string,std::pair<int,std::string> >::const_iterator itr = correspondences.begin();
itr != correspondences.end(); itr++) {
std::cout << "looking for " << id << " " << itr->first << std::endl;
}
*/
std::map<std::string,std::pair<int,std::string> >::const_iterator itr = correspondences.find(id);
return (itr != correspondences.end());
}
const std::pair<int,std::string>& getCorrespondence(const std::string& id) {
assert (hasCorrespondence(id));
return correspondences.find(id)->second;
}
bool isReleased(const std::string &id) const {
assert (released.find(id) != released.end());
return released.find(id)->second;
}
float getItemMaximum(const std::string &id) const {
if (maximums.find(id) == maximums.end()){
return 0;
}
return maximums.find(id)->second;
}
float getScaleMaximum(const std::string &id) const {
if (scale_maximums.find(id) == scale_maximums.end()) {
return -1;
}
return scale_maximums.find(id)->second;
}
float getItemPercentage(const std::string &id) const {
if (item_percentages.find(id) == item_percentages.end())
return -1;
else
return item_percentages.find(id)->second;
}
float getClamp(const std::string &id) const {
assert (clamps.find(id) != clamps.end());
return clamps.find(id)->second;
}
float getSortedWeight(unsigned int position){
assert(position < sorted_weights.size());
return sorted_weights[position];
}
bool hasSortedWeight(){
return !sorted_weights.empty();
}
// MODIFIERS
void setRemoveLowest(int r) { remove_lowest=r; }
int setCorrespondence(const std::string& id) {
assert (!hasCorrespondence(id));
//std::cout << "SET CORR " << id << std::endl;
assert (int(correspondences.size()) < count);
int index = correspondences.size();
correspondences[id] = std::make_pair(index,"");
return index;
}
// Set the max percentage that can be received for a gradeable type.
// If the value is less than 0, it should be ignored.
void setBucketPercentageUpperClamp(float bucket_percentage_upper_clamp) {
this->bucket_percentage_upper_clamp = bucket_percentage_upper_clamp;
}
void setCorrespondenceName(const std::string& id, const std::string& name) {
assert (hasCorrespondence(id));
assert (correspondences[id].second == "");
correspondences[id].second = name;
}
void setReleased(const std::string&id, bool is_released) {
assert (hasCorrespondence(id));
assert (released.find(id) == released.end());
released[id] = is_released;
}
void setMaximum(const std::string&id, float maximum) {
assert (hasCorrespondence(id));
assert (maximums.find(id) == maximums.end());
maximums[id] = maximum;
}
void setScaleMaximum(const std::string&id, float scale_maximum) {
assert (hasCorrespondence(id));
assert (scale_maximums.find(id) == scale_maximums.end());
scale_maximums[id] = scale_maximum;
}
void setItemPercentage(const std::string&id, float item_percentage) {
assert (hasCorrespondence(id));
assert (item_percentages.find(id) == item_percentages.end());
item_percentages[id] = item_percentage;
}
void setClamp(const std::string&id, float clamp) {
assert (hasCorrespondence(id));
assert (clamps.find(id) == clamps.end());
clamps[id] = clamp;
}
void setResubmissionValues(const std::string &id,
const std::string &original_id, const std::string &resubmit_id,
const std::string &title,
float autograde_replacement_percentage) {
setCorrespondenceName(id,title);
original_ids[id] = original_id;
resubmit_ids[id] = resubmit_id;
autograde_replacement_percentages[id] = autograde_replacement_percentage;
}
void addSortedWeight(float weight){
sorted_weights.push_back(weight);
}
private:
// REPRESENTATION
int count;
float percent;
int remove_lowest;
float bucket_percentage_upper_clamp;
std::map<std::string,std::pair<int,std::string> > correspondences;
std::map<std::string,float> maximums;
std::map<std::string,float> scale_maximums;
std::map<std::string,float> item_percentages;
std::vector<float> sorted_weights;
std::map<std::string,float> clamps;
std::map<std::string,bool> released;
std::map<std::string,std::string> original_ids;
std::map<std::string,std::string> resubmit_ids;
std::map<std::string,float> autograde_replacement_percentages;
};
// ===============================================================================
extern std::vector<GRADEABLE_ENUM> ALL_GRADEABLES;
extern std::map<GRADEABLE_ENUM,Gradeable> GRADEABLES;
inline void LookupGradeable(const std::string &id,
GRADEABLE_ENUM &g_e, int &i) {
for (std::size_t k = 0; k < ALL_GRADEABLES.size(); k++) {
GRADEABLE_ENUM e = ALL_GRADEABLES[k];
Gradeable g = GRADEABLES[e];
if (g.hasCorrespondence(id)) {
g_e = e;
i = g.getCorrespondence(id).first;
return;
}
}
assert (0);
}
#endif