-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblending.html
254 lines (213 loc) · 9.12 KB
/
blending.html
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nitrox Blending Calculator</title>
<style>
body {
max-width: 600px;
font-family: Arial, sans-serif;
margin-left: auto;
margin-right: auto;
padding: 20px;
background-color: #f4f4f4;
text-align: center;
}
h1, h2, h3 {
color: #2c3e50;
text-align: center
}
p {
color: #34495e;
}
form {
max-width: 600px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
label {
font-size: 14px;
margin-bottom: 5px;
display: block;
color: #2c3e50;
}
input[type="text"],
input[type="answer"],
input[type="button"] {
width: 100%;
max-width: 600px;
padding: 8px;
margin: 10px 0 20px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
input[type="button"] {
background-color: #3498db;
color: white;
border: none;
cursor: pointer;
}
input[type="button"]:hover {
background-color: #2980b9;
}
.warning {
color: red;
font-weight: bold;
font-size: 20px;
}
</style>
<link rel="manifest" href="/manifest.json">
</head>
<body>
<h1>Nitrox Bank / Compressor Blending Tool</h1>
<!-- Instructions Toggle Button -->
<input type="button" value="Instructions" onclick="myFunction()">
<br>
<div id="myDIV" style="display:none" >
<p>Most nitrox calculators assume that the fill mix will always be 100% O2, however this is not the case when using a nitrox compressor or nitrox bank. This calculator is therefore designed to take any percentage of O2 as a fill mix. Top-off mixes usually will be air (20.9%). An example use of this calculator might therefore be wanting a 32% fill using a nitrox bank when your cylinders already have 32% in them and the bank is 38%.</p>
<p>Using this method, the maximum % that can be achieved in the final / desired mix is of course the % of the fill mix gas.</p>
<p>In some cases, a cylinder may need to be slightly drained to achieve the desired mix. The calculator will warn you if this is the case.</p>
<p>Finally, this calculator also allows you to calculate the cost of your fill. Simply enter the total size of your cylinders that you are filling below and press the second 'calculate' button.</p>
</div>
<br>
<form>
<label for="n1">Start Pressure (bar):</label>
<input id="n1" type="text" inputmode="decimal">
<label for="n2">End Pressure (bar):</label>
<input id="n2" type="text" inputmode="decimal">
<label for="n3">Start Mix (%):</label>
<input id="n3" type="text" inputmode="decimal">
<label for="n4">Desired (End) Mix (%):</label>
<input id="n4" type="text" inputmode="decimal">
<label for="n5">Fill (Bank or Compressor) Mix (%):</label>
<input id="n5" type="text" inputmode="decimal">
<label for="n6">Top-off Mix (%):</label>
<input id="n6" type="text" value="20.9" inputmode="decimal">
<input type="button" value="Calculate" onclick="calculate()">
<p id="pressure-warning" class="warning" style="display:none;">WARNING: Start pressure must be lower than end pressure!</p>
<p id="mix-over-100-warning" class="warning" style="display:none;">WARNING: Mix values cannot exceed 100%!</p>
<p id="mix-warning" class="warning" style="display:none;">WARNING: Desired (end) mix cannot be higher than fill mix!</p>
<p id="drain-message" class="warning" style="display:none;">WARNING: You must drain your cylinder to at least <span id="drain-pressure-value"></span> bar before filling it. Drain your cylinder and recalculate.</p>
<label for="ans">Add (Fill Mix):</label>
<input id="ans" type="answer" readonly>
<label for="ans1">(Fill from Start Pressure to):</label>
<input id="ans1" type="answer" readonly>
<label for="ans2">Add (Top-off Mix):</label>
<input id="ans2" type="answer" readonly>
<label for="ans4">(Fill to):</label>
<input id="ans4" type="answer" readonly>
</form>
<h3>Gas Filling Costs</h3>
<p> The pre-filled value below is the SSAC nitrox price as of 28/04/2023. It can be amended if required.</p>
<form>
<label for="n9">Cylinder Size (L):</label>
<input id="n9" type="text" inputmode="decimal">
<label for="n7">Nitrox Price (p/L):</label>
<input id="n7" type="text" value="0.210" inputmode="decimal">
<input type="button" value="Calculate Cost" onclick="calculateCost()">
<label for="ans5">Final Cost (£):</label>
<input id="ans5" type="answer" readonly>
</form>
<p>This tool comes with absolutely NO WARRANTY. Use of this tool is at your own risk.</p>
<p>You must be qualified in gas blending operations to use this calculator.</p>
<p>Always analyse your cylinders after blending.</p>
<p>Version 0.42 - 20241222</p>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/service-worker.js').then(function(registration) {
console.log('Service Worker registered with scope:', registration.scope);
}).catch(function(error) {
console.log('Service Worker registration failed:', error);
});
});
}
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
function calculate() {
let num1 = parseFloat(document.getElementById('n1').value);
let num2 = parseFloat(document.getElementById('n2').value);
let num3 = parseFloat(document.getElementById('n3').value);
let num4 = parseFloat(document.getElementById('n4').value);
let num5 = parseFloat(document.getElementById('n5').value);
let num6 = parseFloat(document.getElementById('n6').value);
let showWarning = false;
// Check if any mix value exceeds 100
if (num3 > 100 || num4 > 100 || num5 > 100 || num6 > 100) {
document.getElementById('mix-over-100-warning').style.display = 'block';
showWarning = true;
} else {
document.getElementById('mix-over-100-warning').style.display = 'none';
}
// Check if Start Pressure is lower than End Pressure
if (num1 >= num2) {
document.getElementById('pressure-warning').style.display = 'block';
showWarning = true;
} else {
document.getElementById('pressure-warning').style.display = 'none';
}
// Check if Desired (End) Mix is higher than Fill Mix
if (num4 > num5) {
document.getElementById('mix-warning').style.display = 'block';
showWarning = true;
} else {
document.getElementById('mix-warning').style.display = 'none';
}
if (showWarning) {
document.getElementById('drain-message').style.display = 'none';
document.getElementById('ans').value = '';
document.getElementById('ans1').value = '';
document.getElementById('ans2').value = '';
document.getElementById('ans4').value = '';
return; // Stop calculation if there's any warning
}
// Add logic to calculate gas quantities and fill pressures
let sum1 = (num2 * (num4 - num6) - num1 * (num3 - num6)) / (num5 - num6);
let sum2 = (num2 - num1 - sum1);
sum2 = sum2.toFixed(1); // Convert sum2 to 1 decimal place
let sum3 = (num1 + parseFloat(sum2));
// Handle drain pressure only if sum2 is less than 0
if (parseFloat(sum2) < 0) {
let drainPressure = (num1 + parseFloat(sum2)).toFixed(1);
document.getElementById('drain-message').style.display = 'block';
document.getElementById('drain-pressure-value').textContent = drainPressure;
// Hide output data when drain pressure warning is displayed
document.getElementById('ans').value = '';
document.getElementById('ans1').value = '';
document.getElementById('ans2').value = '';
document.getElementById('ans4').value = '';
} else {
document.getElementById('drain-message').style.display = 'none';
// Display results rounded to 1 decimal place
document.getElementById('ans').value = sum1.toFixed(1);
document.getElementById('ans1').value = (sum1 + num1).toFixed(1);
document.getElementById('ans2').value = sum2;
document.getElementById('ans4').value = (sum1 + parseFloat(sum2) + num1).toFixed(1);
}
}
function calculateCost() {
let price = parseFloat(document.getElementById('n7').value);
let size = parseFloat(document.getElementById('n9').value);
let filltotal = parseFloat(document.getElementById('ans').value);
if (isNaN(price) || isNaN(size) || isNaN(filltotal)) {
alert("Ensure all inputs are correctly filled and gas amount is calculated first.");
return;
}
let finalPrice = (price / 100) * size * filltotal;
finalPrice = Math.round((finalPrice + Number.EPSILON) * 100) / 100;
document.getElementById('ans5').value = finalPrice;
}
</script>
</body>
</html>