-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scorer.java
57 lines (38 loc) · 1.48 KB
/
Scorer.java
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
package client;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class Scorer extends Thread{
private Hashtable<String, Attributes> statsMap = new Hashtable<String, Attributes>();
private TreeSet<Coo> scoreSet = new TreeSet<Coo>();
private double[] sigma = new double[7];
private double[] average = new double[7];
@Override
public void run() {
synchronized (Broker.lock) {
//System.out.println("*******Scorer Running**************");
statsMap = Broker.getStatsMap();
sigma = Broker.getSigma();
average = Broker.getAverage();
Set<String> keys = statsMap.keySet();
Iterator<String> itr = keys.iterator();
String key;
Attributes stats;
scoreSet.clear();
while (itr.hasNext()) {
Coo score = new Coo();
key = itr.next();
stats = statsMap.get(key);
score.name = key;
score.rank = ((stats.cpu - average[0]) / sigma[0]) + ((stats.ram - average[1]) / sigma[1]) + ((stats.location - average[2]) / sigma[2]) + ((stats.latency - average[3]) / sigma[3]) + ((stats.battery - average[4]) / sigma[4]) + ((stats.noTasks - average[5]) / sigma[5]) + ((stats.trust - average[6]) / sigma[6]);
scoreSet.add(score);
}
/*for (Coo i : scoreSet) {
System.out.println(i.name + "------" + i.rank);
}*/
Broker.setScoreSet(scoreSet);
//System.out.println("~~~~~~~Scorer Stopping~~~~~~~~~~~~~~~~~");
}
}
}