-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvaluation.sol
More file actions
260 lines (231 loc) · 9.53 KB
/
Evaluation.sol
File metadata and controls
260 lines (231 loc) · 9.53 KB
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
pragma solidity ^0.4.20;
contract Evaluation
{
//Model of an evaluator
struct Evaluator
{
uint e_id;
string name;
string password;
uint[] scores;
}
//Model of a student
struct Student
{
uint s_id;
string name;
string password;
uint[] taskList;
}
//Model of every submission
struct Submission
{
uint t_id;
string task;
uint technology;
uint[] upvoteEvalId;
uint[] downvoteEvalId;
uint[] upvoteNonEvaluators;
uint[] downvoteNonEvaluators;
string studentresult;
}
mapping(uint => Evaluator) public Evaluators;
mapping(uint => Student) public Students;
mapping(uint => Submission) public Submissions;
uint public student_id = 0;
uint public eval_id = 0;
uint public task_id = 0;
event recordVotes(uint taskId, uint evalId,bool evalOrNonEval, bool evaluatorRemark, uint timestamp);
//To onboard a student
function addStudent (string name,string password) public
{
student_id ++;
Students[student_id].s_id = student_id;
Students[student_id].name = name;
Students[student_id].password = password;
}
//To onboard an Evaluator
function addEvaluator (string name, string password,uint score1, uint score2, uint score3) public
{
eval_id++;
Evaluators[eval_id].scores.push(score1);
Evaluators[eval_id].scores.push(score2);
Evaluators[eval_id].scores.push(score3);
Evaluators[eval_id].e_id = eval_id;
Evaluators[eval_id].name= name;
Evaluators[eval_id].password=password;
}
//Pre-add a set of Evaluators
/*function Test1 () public
{
addEvaluator("Ram",900,1100,1050);
//add 9 more values like this
} */
//For a student to add a submission
function addSubmission (string name, uint tech,string studentName, string studentPass)
{
task_id++;
Submissions[task_id].t_id=task_id;
Submissions[task_id].task=name;
Submissions[task_id].technology=tech;
Submissions[task_id].studentresult="UNDER REVIEW";
for (uint i=1; i<=student_id; i++){
if(keccak256(Students[i].name)==keccak256(studentName) && keccak256(Students[i].password)==keccak256(studentPass)){
Students[i].taskList.push(task_id);
}
}
}
//To check if the evaluator's score is >1000 so that he can vote
function checkEvaluatorScore(uint techId, uint evaluatorId) returns (bool)
{
if (techId == 1)
{
if(Evaluators[evaluatorId].scores[0] > 1000)
return true;
}
if (techId == 2)
{
if(Evaluators[evaluatorId].scores[1] > 1000)
return true;
}
if (techId == 3)
{
if(Evaluators[evaluatorId].scores[2] > 1000)
return true;
}
return false;
}
//For a student to fetch the status of a particular submission
function viewStatus(uint task_id) returns (uint t_id, uint technology, string task, uint up_count, uint down_count, string passfail)
{
t_id=Submissions[task_id].t_id;
task=Submissions[task_id].task;
technology=Submissions[task_id].technology;
up_count=Submissions[task_id].upvoteEvalId.length;
down_count=Submissions[task_id].downvoteEvalId.length;
passfail=Submissions[task_id].studentresult;
return;
}
function getNumberofTasks()public returns (uint) {
return task_id;
}
//For an Evaluator to upvote/downvote the task
function vote (uint taskId, uint e_id, bool evalOrNonEval, bool evaluatorRemark) public
{
if((Submissions[taskId].upvoteEvalId.length <5) || (Submissions[taskId].upvoteEvalId.length+Submissions[taskId].downvoteEvalId.length <9)){
if(evalOrNonEval)
{
if(evaluatorRemark)
{
Submissions[taskId].upvoteEvalId.push(e_id);
}
else
{
Submissions[taskId].downvoteEvalId.push(e_id);
}
}
else
{
if(evaluatorRemark)
{
Submissions[taskId].upvoteNonEvaluators.push(e_id);
}
else
{
Submissions[taskId].downvoteNonEvaluators.push(e_id);
}
}
emit recordVotes(taskId,e_id,evalOrNonEval,evaluatorRemark,now);
}
else {
if(Submissions[taskId].upvoteEvalId.length >= 5)
Submissions[task_id].studentresult="PASSED";
else
Submissions[task_id].studentresult="FAILED";
}
}
//To check the details of upvoters and downvoters
function viewVoterResults(uint taskId) returns (uint[] upvoteEval, uint[] downvoteEval, uint[] upvoteNonEval, uint[] downvoteNonEval)
{
return(Submissions[taskId].upvoteEvalId, Submissions[taskId].downvoteEvalId, Submissions[taskId].upvoteNonEvaluators, Submissions[taskId].downvoteNonEvaluators);
}
//To update the credibility score of the voters. Evaluator by 20 and non-evaluator by 4
function credibilityScoreUpdate(uint taskId, uint techId, bool result) public
{
for (uint i = 1; i<=eval_id; i++)
{
if(result)
{
for(uint j=0; j<Submissions[taskId].upvoteEvalId.length; j++)
{
if (Submissions[taskId].upvoteEvalId[j]==i)
{
Evaluators[i].scores[techId-1]=Evaluators[i].scores[techId-1]+20;
}
}
for(uint k=0; k<Submissions[taskId].upvoteNonEvaluators.length; k++)
{
if (Submissions[taskId].upvoteNonEvaluators[k]==i) {
Evaluators[i].scores[techId-1]=Evaluators[i].scores[techId-1]+4;
}
}
}
if(!result)
{
for(uint l=0; l<Submissions[taskId].downvoteEvalId.length; l++)
{
if (Submissions[taskId].downvoteEvalId[l]==i)
{
Evaluators[i].scores[techId-1]=Evaluators[i].scores[techId-1]+20;
}
}
for (uint m=0; m<Submissions[taskId].downvoteNonEvaluators.length; m++)
{
if (Submissions[taskId].downvoteNonEvaluators[m]==i)
{
Evaluators[i].scores[techId-1]=Evaluators[i].scores[techId-1]+4;
}
}
}
}
}
function viewEvalDetails(uint evalId) returns(uint evaluatorId, string name, uint[] evalScores)
{
return(Evaluators[evalId].e_id,Evaluators[evalId].name,Evaluators[evalId].scores);
}
//Login function for student
function checkStudentLogin(string studentname, string password) returns (bool)
{
for (uint i=1; i<=student_id; i++)
{
if(keccak256(Students[i].name)==keccak256(studentname) && keccak256(Students[i].password)==keccak256(password))
return true;
}
return false;
}
//Return evaluator eval_id
function getEvaluatorId(string evaluatorname, string password) returns (uint)
{
for (uint i=1; i<=eval_id; i++){
if(keccak256(Evaluators[i].name)==keccak256(evaluatorname) && keccak256(Evaluators[i].password)==keccak256(password))
return Evaluators[i].e_id;
}
return 0;
}
//Login function for evaluator
function checkEvaluatorLogin(string evaluatorname, string password) returns (bool)
{
for (uint i=1; i<=eval_id; i++){
if(keccak256(Evaluators[i].name)==keccak256(evaluatorname) && keccak256(Evaluators[i].password)==keccak256(password))
return true;
}
return false;
}
function viewStudentTasklist(string name, string password) public returns (uint[] tasklist){
for (uint i=1; i<=student_id; i++){
if(keccak256(Students[i].name)==keccak256(name) && keccak256(Students[i].password)==keccak256(password)){
return(Students[i].taskList);
}
}
}
}