-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathevaluationHelper.sol
143 lines (100 loc) · 3.62 KB
/
evaluationHelper.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
pragma solidity ^0.4.18;
import './evaluation.sol';
//import './strings.sol';
import "github.com/Arachnid/solidity-stringutils/strings.sol";
contract EvaluationHelper is EvaluationContract {
using strings for *;
event pleaseEvaluate(
string _solutionHash,
uint _agreementId,
address indexed _evaluatorAddress
);
//TEST THIS
function submitToEvaluators(string _solutions_mergerd,address[] _evaluatorAddresses,uint _agreementId) onlyWorker(_agreementId) {
var s = _solutions_mergerd.toSlice();
var delim = ",".toSlice();
var parts = new string[](s.count(delim) + 1);
for(uint i = 0; i < parts.length; i++) {
parts[i] = s.split(delim).toString();
}
/*
var delim = ",".toSlice();
//uint count_solns = _solutions_mergerd.count(delim) + 1;
var _solutions = new string[](_solutions_mergerd.count(delim) + 1);
uint i ;
for( i = 0; i < _solutions.length; i++) {
_solutions[i] = _solutions_mergerd.split(delim).toString();
}*/
require( parts.length == agreementToEvaluators[_agreementId].length );
agreements[_agreementId].submittedToEvaluator = true;
for(i = 0;i<parts.length;i++){
pleaseEvaluate(parts[i],_agreementId,_evaluatorAddresses[i]);
}
}
mapping (uint => uint[]) public agreementToRatings;
mapping (uint => uint) public agreementToRecievedEvaluationsCount;
function _simpleRecieveFromEvaluators(uint _rating,uint _agreementId) private {
//require(_rating<upperlimit);
//added modifier body
uint[] evalArray = agreementToEvaluators[_agreementId];
bool present = false;
uint i;
for (i = 0; i < evalArray.length; i++){
if (msg.sender == workers[evalArray[i]].publicAddress){
present = true;
break;
}
}
require(present);
agreementToRatings[_agreementId].push(_rating);
//agreementToEvaluators_recievedStatus[_agreementId][i] = true; //THIS IS LEFT
agreementToRecievedEvaluationsCount[_agreementId]+=1;
}
function recieveOrchestrator(uint _rating,uint _agreementId) external {
_simpleRecieveFromEvaluators(_rating,_agreementId);
if(agreementToRecievedEvaluationsCount[_agreementId] == agreementToEvaluators[_agreementId].length ){
//bool concencus = _RepCal(_agreementId);
//if (concencus ){terminate and reward} else {add time and worker resubmits}
bool concencus = _RepCal(_agreementId);
if (concencus){
//terminate and reward
_sendRewardAndTerminateAgreement(_agreementId);
//define event
}
else {
//re-evaluate by resubmit, increase submission timeine
//THIS IS LEFT
//def event
}
}
}
function _RepCal(uint _agreementId) private returns (bool) {
bool concensus = false;
//calculating reputation
uint deltaRep;
uint[] ratingsArray = agreementToRatings[_agreementId];
bool present = false;
for (uint i = 0; i < ratingsArray.length; i++){
deltaRep += ratingsArray[i];
}
deltaRep = deltaRep / ratingsArray.length;
workers[agreements[_agreementId].workerId].repScore += deltaRep;
//test
concensus = true;
return concensus;
}
function sqrt(uint x) returns (uint y) {
uint z = (x + 1) / 2;
y = x;
while (z < y) {
y = z;
z = (x / z + z) / 2;
}
}
uint public stdDev = 0 ;
function _maths(uint _no1, uint _no2, uint _no3) {
uint avg = (_no3 + _no2 + _no1)/3 ;
uint variance = ((avg - _no2)* (avg - _no2) + (avg - _no1)*(avg - _no1) + (avg - _no3)*(avg - _no3)) /3 ;
stdDev = sqrt(variance) ;
}
}