-
Notifications
You must be signed in to change notification settings - Fork 4
/
submission.sol
124 lines (91 loc) · 4.36 KB
/
submission.sol
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
pragma solidity ^0.4.18;
import './agreement.sol';
contract SubmissionContract is AgreementContract {
//submitting hash of the solution to the platform
function submitHash(string _solutionHash, uint _agreementId) onlyWorker(_agreementId){
uint numberOfEvalutor = _numberOfEvalutor();
agreements[_agreementId].solutionHash = _solutionHash;
workers[addressToIdWorker[msg.sender]].availableForEvaluation = true;
agreements[_agreementId].toEvalluateTaskCount = 0;
}
uint randNonce = 2;
function _numberOfEvalutor() private returns (uint){
return 3;
}
function randomNumberGen(uint _modulus) public returns(uint) {
randNonce++;
uint waste;
waste = uint(keccak256((now+randNonce), msg.sender, randNonce)) % _modulus;
return waste;
}
function _findingEvaluator(uint _numberOfEvalutor, uint _agreementId) {
// should not be an evaluator himself
uint MaxRep = 100;
uint Inlength;
uint[3] memory rangeCount = [uint(0),0,0];
uint RepInterval = MaxRep / _numberOfEvalutor;
uint[1000][3] workerInRepRange;
for (uint i = 0 ; i< workers.length; i++){// traverses all workers
uint upperRep = RepInterval;
uint count = 0 ;
while (upperRep<= MaxRep){//adds to interval
if (uint256(workers[i].repScore) >= uint256((count)*RepInterval) && uint256(workers[i].repScore) < uint256(upperRep) ){
if (((workers[i].availableForEvaluation == true) || (workers[i].becomeEvaluator == true)) && (workers[i].assignedEvaluation == false) && (agreements[_agreementId].workerId != i)){
Inlength = rangeCount[count];
workerInRepRange[count][Inlength] = i; //i is id of worker
rangeCount[count]++;
break;
}
}
count++;
upperRep = ((count+1)*RepInterval);
}
}
uint jValue = _numberOfEvalutor;
for(uint j = 0; j < jValue; j++){
uint randNum = randomNumberGen(rangeCount[j]);
agreementToEvaluators[_agreementId].push(workerInRepRange[j][randNum]);
workers[workerInRepRange[j][randNum]].assignedEvaluation = true;
}
}
// assigns evaluator to a submission upon request by worker.
function getEvaluators(uint agreementID){
require(agreements[agreementID].toEvalluateTaskCount == 0 && bytes(agreements[agreementID].solutionHash).length != 0);
_findingEvaluator(3, agreementID);
}
function getEvaluatorAddresses(uint _agreementId) view onlyWorker(_agreementId) returns(address[]) {
uint numberOfEvalutor = 3;
address[] memory eval_adresses = new address[](numberOfEvalutor);
for(uint8 i=0;i<numberOfEvalutor;i++){
uint eval_id = agreementToEvaluators[_agreementId][i];
eval_adresses[i] = workers[eval_id].publicAddress;
}
return eval_adresses;
}
function getEvaluatorPublicKeys(uint _agreementId,uint _evalNumber) view onlyWorker(_agreementId) returns(string) {
uint8 numberOfEvalutor = 3;
string[] memory eval_adresses = new string[](numberOfEvalutor);
for(uint8 i=0;i<numberOfEvalutor;i++){
uint eval_id = agreementToEvaluators[_agreementId][i];
eval_adresses[i] = workers[eval_id].encryptionkeyAddress;
}
return eval_adresses[_evalNumber];
}
function becomeEvaluator(){
require(workers[addressToIdWorker[msg.sender]].repScore > avgRep());
workers[addressToIdWorker[msg.sender]].becomeEvaluator = true;
}
function makingAvailableForEvaluation(uint workerID){
workers[workerID].availableForEvaluation = true;
}
function avgRep() returns(uint avgRepScore){
avgRepScore = 0;
for (uint i = 0 ; i< workers.length; i++){
avgRepScore += workers[i].repScore ;
}
return (avgRepScore/workers.length);
}
function extraRepUpdate(uint workerID, uint rep){
workers[workerID].repScore = rep;
}
}