forked from badnatho/RaidCalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
115 lines (99 loc) · 2.03 KB
/
script.js
File metadata and controls
115 lines (99 loc) · 2.03 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
function calculateCapacity(n, c, t) {
let e = 0
switch (t) {
case '0':
// RAID 0
e = 1
break
case '1':
// RAID 1
e = 1 / n
break
case '2':
// RAID 5
e = 1 - (1 / n)
break
case '3':
// RAID 6
e = 1 - (2 / n)
break
case '4':
// RAID 10
e = 1 * 0.5
break
}
return e * (n * c)
}
function convertToGib(capacity) {
return capacity * 0.931
}
function test(disks, capacity, type) {
if (isNaN(disks) || disks <= 1) {
return "Number of disks must be a number greater than one."
}
if (type == '2' && disks <= 2) {
return "Raid 5 requires at least 3 drives to function."
}
if (type == '3' && disks <= 3) {
return "Raid 6 requires at least 4 drives to function."
}
if (isNaN(capacity) || capacity <= 0) {
return "Single disk capacity must be a number greater than zero."
}
return true;
}
function setResults(gb, gib, tolerance) {
$("#gbCapacityResult").text(gb)
$("#gibCapacityResult").text(gib)
$("#toleranceResult").text(tolerance + ' Drive Failure' + (tolerance == 1 ? '':'s'))
}
function clearResults() {
$("#gbCapacityResult").text('--')
$("#gibCapacityResult").text('--')
$("#toleranceResult").text('--')
}
function trigger() {
var disks = parseInt($("#diskCount").val())
var capacity = parseInt($("#diskCapacity").val())
var type = $("#raidType").val()
$("#errorText").text('')
var result = test(disks, capacity, type);
if (result !== true) {
clearResults()
$("#errorText").text(result)
return console.log(result)
}
var gb = Math.floor(calculateCapacity(disks, capacity, type))
var gib = Math.floor(convertToGib(gb))
var tolerance = 0
switch (type) {
case '0':
// RAID 0
tolerance = 0
break
case '1':
// RAID 1
tolerance = disks - 1
break
case '2':
// RAID 5
tolerance = 1
break
case '3':
// RAID 6
tolerance = 2
break
case '4':
// RAID 10
tolerance = 1
break
}
setResults(gb, gib, tolerance)
}
$(':input').bind('click keyup', function() {
trigger()
})
$("#raidType").change(function() {
trigger()
})
trigger()