-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboinc-combined-statistics.js
113 lines (87 loc) · 2.98 KB
/
boinc-combined-statistics.js
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
console.info("Note: The Project Whitelist Requirement Checker plugin may not work if boinc.netsoft-online.com changes the layout of the page. This plugin was designed with multiple assumptions about the page layout")
function parseXML(text){
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");
return xmlDoc
}
function processData(xml){
root = xml.children[0]
tags = root.children
len = tags.length
totalCredits = []
for(i=len-1; i>len-42; i--){
curVal = parseInt(tags[i].textContent)
totalCredits.push(curVal)
}
newCredit = []
for (i=0; i<totalCredits.length-1; i++){
newCredit.push(totalCredits[i] - totalCredits[i+1])
}
return newCredit
}
function displayData(rowData){
const tableDiv = document.getElementsByClassName("nforumholder")[0]
//ZCD check
var zcdCount = 0
for (number of rowData.slice(0,20)){
if (number === 0){
zcdCount++;
}
}
//display results for ZCD
console.log("ZCD: " + zcdCount)
var zcdDiv = document.createElement("div")
var zcdText = "ZCD is " + zcdCount;
var br = document.createElement("br");
if (zcdCount <= 7){
zcdText += " (pass) "
zcdDiv.classList.add("check-display-pass");
console.log("ZCD check passed")
} else {
zcdText += " (fail) "
zcdDiv.classList.add("check-display-fail");
console.log("ZCD check failed")
}
zcdDiv.appendChild(document.createTextNode(zcdText));
zcdDiv.appendChild(br);
tableDiv.prepend(zcdDiv);
//WAS Check
var sum40days = 0
for (number of rowData.slice(0,40)) { //just in case something changes - we only want the last 40 days anyway
sum40days += number;
}
var sum7days = 0
for (number of rowData.slice(0,7)) {
sum7days += number;
}
const avg40days = sum40days/40;
const avg7days = sum7days/7;
const ratio = avg7days/avg40days;
//display results for WAS
console.log("WAS " + ratio);
var wasDiv = document.createElement("div")
var wasText = "WAS ratio is " + ratio.toFixed(4) + "…";
var br = document.createElement("br");
if (ratio >= 0.1){
wasText += " (pass) ";
wasDiv.classList.add("check-display-pass");
console.log("WAS check passed");
} else {
wasText += " (fail) "
wasDiv.classList.add("check-display-fail");
console.log("WAS check failed");
}
wasDiv.appendChild(document.createTextNode(wasText));
wasDiv.appendChild(br);
tableDiv.prepend(wasDiv)
}
params=new URLSearchParams(window.location.search)
projectID = params.get("project")
requestParams = new URLSearchParams()
requestParams.append("projectid", projectID)
requestURL = "https://boinc.netsoft-online.com/rpc/get_project_tc_history.php?" + requestParams.toString()
fetch(requestURL)
.then(response => response.text())
.then(data => parseXML(data))
.then(processData)
.then(displayData)