@zac-apps/helium 2.0.0 → 2.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1972
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -1,1972 +1 @@
1
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
- import React, { useState, createContext, useContext, useEffect } from 'react';
4
- import moment from 'moment';
5
- import { useImmer } from 'use-immer';
6
- import useMediaQuery from '@mui/material/useMediaQuery';
7
- import Grid from '@mui/material/Grid';
8
- import TableBody from '@mui/material/TableBody';
9
- import TableCell from '@mui/material/TableCell';
10
- import TableHead from '@mui/material/TableHead';
11
- import TableRow from '@mui/material/TableRow';
12
- import IconButton from '@mui/material/IconButton';
13
- import SaveIcon from '@mui/icons-material/Save';
14
- import EditIcon from '@mui/icons-material/Edit';
15
- import { ErrorAlert, AppTable, TableHeadCell, Percentage, AppTheme, SpecSwitch, DivTitle, PublicFetch, Progress, AppGrid, AppCard } from '@zac-apps/commons';
16
- import TextField from '@mui/material/TextField';
17
- import InputAdornment from '@mui/material/InputAdornment';
18
- import { jsxs, jsx } from 'react/jsx-runtime';
19
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
20
- import Chip from '@mui/material/Chip';
21
- import AddBoxIcon from '@mui/icons-material/AddBox';
22
- import DeleteIcon from '@mui/icons-material/Delete';
23
- import Divider from '@mui/material/Divider';
24
- import FormControlLabel from '@mui/material/FormControlLabel';
25
- import FormControl from '@mui/material/FormControl';
26
- import FormGroup from '@mui/material/FormGroup';
27
- import Checkbox from '@mui/material/Checkbox';
28
- import Button from '@mui/material/Button';
29
- import moment$1 from 'moment/moment.js';
30
- import Typography from '@mui/material/Typography';
31
- import Paper from '@mui/material/Paper';
32
- import { LineChart, Line, CartesianGrid, XAxis, Label, YAxis, ReferenceLine, ReferenceArea, Tooltip } from 'recharts';
33
- import ButtonGroup from '@mui/material/ButtonGroup';
34
- import Switch from '@mui/material/Switch';
35
- import regression from 'regression';
36
- import { mean, sqrt, sum } from 'mathjs';
37
-
38
- function NumField(_ref) {
39
- var input = _ref.input,
40
- SetInput = _ref.SetInput,
41
- error = _ref.error,
42
- SetError = _ref.SetError,
43
- minValue = _ref.minValue,
44
- maxValue = _ref.maxValue,
45
- adornment = _ref.adornment,
46
- size = _ref.size;
47
- var _useState = useState(""),
48
- _useState2 = _slicedToArray(_useState, 2),
49
- errorMessage = _useState2[0],
50
- SetErrorMessage = _useState2[1];
51
- var _useState3 = useState(false),
52
- _useState4 = _slicedToArray(_useState3, 2),
53
- alert = _useState4[0],
54
- SetAlert = _useState4[1];
55
- var sx = {};
56
- if (size === "small") {
57
- sx = {
58
- maxWidth: 75
59
- };
60
- }
61
- function handleEntry(e) {
62
- var errorFound = false;
63
- var inputVal = e.target.value;
64
- if (!inputVal.match(/[0-9-]*/)[0] || inputVal.match(/[0-9-]*/)[0] !== inputVal) {
65
- errorFound = true;
66
- SetErrorMessage("Input is not numerical.");
67
- }
68
- if (inputVal > maxValue || inputVal < minValue) {
69
- errorFound = true;
70
- SetErrorMessage("Input is outside allowed boundaries.");
71
- }
72
- SetInput(inputVal);
73
- SetError(errorFound);
74
- SetAlert(errorFound);
75
- }
76
- return /*#__PURE__*/jsxs(React.Fragment, {
77
- children: [/*#__PURE__*/jsx(TextField, {
78
- size: "small",
79
- sx: sx,
80
- onChange: function onChange(e) {
81
- return handleEntry(e);
82
- },
83
- value: input,
84
- error: error,
85
- inputProps: {
86
- inputMode: "numeric"
87
- },
88
- InputProps: {
89
- endAdornment: /*#__PURE__*/jsx(InputAdornment, {
90
- position: "end",
91
- children: adornment
92
- })
93
- }
94
- }), /*#__PURE__*/jsx(ErrorAlert, {
95
- alert: alert,
96
- SetAlert: SetAlert,
97
- message: errorMessage
98
- })]
99
- });
100
- }
101
-
102
- // Define context
103
-
104
- var LookupContext = /*#__PURE__*/createContext(null);
105
-
106
- // Look up amount in liters for specific spectrometer
107
-
108
- function CalcLiters(_ref) {
109
- var spec = _ref.spec,
110
- value = _ref.value;
111
- var heliumLookup = useContext(LookupContext).lookup;
112
-
113
- // Catch negative values
114
-
115
- if (value < 0 || !value) {
116
- value = 0;
117
- } else {
118
- value = Number(value);
119
- }
120
- var returnVal = heliumLookup[spec].find(function (m) {
121
- return m.level === value;
122
- }).liters;
123
- return returnVal;
124
- }
125
-
126
- // Look up percentage for liter value in specific spectrometer
127
-
128
- function CalcPercent(_ref2) {
129
- var spec = _ref2.spec,
130
- value = _ref2.value;
131
- var heliumLookup = useContext(LookupContext).lookup;
132
- var returnVal = 0;
133
-
134
- // Catch values out of boundary
135
-
136
- if (value < 0 || !value) {
137
- value = 0;
138
- } else {
139
- value = Number(value);
140
- }
141
- if (value > heliumLookup[spec].find(function (m) {
142
- return m.level === 100;
143
- }).liters) {
144
- returnVal = 100;
145
- } else {
146
- var closestLiters = heliumLookup[spec].reduce(function (prev, curr) {
147
- return Math.abs(curr.liters - value) < Math.abs(prev.liters - value) ? curr : prev;
148
- }).liters;
149
- returnVal = heliumLookup[spec].find(function (m) {
150
- return m.liters === closestLiters;
151
- }).level;
152
- }
153
- return returnVal;
154
- }
155
-
156
- // Look up difference from maximum
157
-
158
- function CalcToMax(_ref3) {
159
- var spec = _ref3.spec,
160
- value = _ref3.value;
161
- var heliumLookup = useContext(LookupContext).lookup;
162
-
163
- // Catch negative values
164
-
165
- value = Number(value) || 0;
166
- if (value < 0 || !value) {
167
- value = 0;
168
- }
169
- var maxLiters = Math.max.apply(null, heliumLookup[spec].map(function (m) {
170
- return m.liters;
171
- }));
172
- var returnVal = maxLiters - heliumLookup[spec].find(function (m) {
173
- return m.level === value;
174
- }).liters;
175
- returnVal = Math.round(returnVal * 10) / 10;
176
- return returnVal;
177
- }
178
-
179
- function HeliumEntry(_ref) {
180
- var heliumData = _ref.heliumData,
181
- SetHeliumData = _ref.SetHeliumData,
182
- spec = _ref.spec,
183
- SetLevelsEdited = _ref.SetLevelsEdited;
184
- var heliumLookup = useContext(LookupContext).lookup;
185
- var value = Number(heliumData.helium[spec]) || 0;
186
- var maxValue = Math.max.apply(null, heliumLookup[spec].map(function (m) {
187
- return m.level;
188
- }));
189
- var minValue = 0;
190
- var _useState = useState(false),
191
- _useState2 = _slicedToArray(_useState, 2),
192
- edit = _useState2[0],
193
- SetEdit = _useState2[1];
194
- var _useState3 = useState(value),
195
- _useState4 = _slicedToArray(_useState3, 2),
196
- input = _useState4[0],
197
- SetInput = _useState4[1];
198
- var _useState5 = useState(false),
199
- _useState6 = _slicedToArray(_useState5, 2),
200
- error = _useState6[0],
201
- SetError = _useState6[1];
202
- if (edit) {
203
- return /*#__PURE__*/jsxs(TableCell, {
204
- children: [/*#__PURE__*/jsx(NumField, {
205
- input: input,
206
- SetInput: SetInput,
207
- error: error,
208
- SetError: SetError,
209
- minValue: minValue,
210
- maxValue: maxValue,
211
- adornment: "%",
212
- size: "small"
213
- }), /*#__PURE__*/jsx(IconButton, {
214
- disabled: error,
215
- onClick: function onClick() {
216
- SetHeliumData(function (heliumData) {
217
- heliumData.helium[spec] = Number(input);
218
- });
219
- SetEdit(!edit);
220
- SetLevelsEdited(true);
221
- },
222
- children: /*#__PURE__*/jsx(SaveIcon, {})
223
- })]
224
- });
225
- } else {
226
- return /*#__PURE__*/jsxs(TableCell, {
227
- children: [Percentage(value, true), /*#__PURE__*/jsx(IconButton, {
228
- size: "small",
229
- onClick: function onClick() {
230
- return SetEdit(!edit);
231
- },
232
- children: /*#__PURE__*/jsx(EditIcon, {})
233
- })]
234
- });
235
- }
236
- }
237
-
238
- // render Helium level table
239
-
240
- function HeliumTable(_ref2) {
241
- var heliumData = _ref2.heliumData,
242
- SetHeliumData = _ref2.SetHeliumData,
243
- SetLevelsEdited = _ref2.SetLevelsEdited;
244
- // Catch if no data present
245
-
246
- if (heliumData.helium.length === 0) {
247
- return /*#__PURE__*/jsx(Grid, {
248
- children: /*#__PURE__*/jsx("em", {
249
- children: "No Helium data found."
250
- })
251
- });
252
- }
253
-
254
- // Calculate sum of missing helium
255
-
256
- var totalToMax = Object.keys(heliumData.helium).reduce(function (total, current) {
257
- return total + CalcToMax({
258
- spec: current,
259
- value: heliumData.helium[current]
260
- });
261
- }, 0);
262
- totalToMax = Math.round(totalToMax * 10) / 10;
263
- return /*#__PURE__*/jsxs(AppTable, {
264
- children: [/*#__PURE__*/jsx(TableHead, {
265
- children: /*#__PURE__*/jsxs(TableRow, {
266
- children: [/*#__PURE__*/jsx(TableHeadCell, {
267
- children: "Spectrometer"
268
- }), /*#__PURE__*/jsxs(TableHeadCell, {
269
- children: ["Helium level", /*#__PURE__*/jsx("br", {}), "[%]"]
270
- }), /*#__PURE__*/jsxs(TableHeadCell, {
271
- children: ["Helium level", /*#__PURE__*/jsx("br", {}), "[liters]"]
272
- }), /*#__PURE__*/jsxs(TableHeadCell, {
273
- children: ["Diff. to maximum", /*#__PURE__*/jsx("br", {}), "[liters]"]
274
- })]
275
- })
276
- }), /*#__PURE__*/jsx(TableBody, {
277
- children: Object.keys(heliumData.helium).map(function (m) {
278
- return /*#__PURE__*/jsxs(TableRow, {
279
- children: [/*#__PURE__*/jsx(TableCell, {
280
- children: m
281
- }), /*#__PURE__*/jsx(HeliumEntry, {
282
- heliumData: heliumData,
283
- SetHeliumData: SetHeliumData,
284
- SetLevelsEdited: SetLevelsEdited,
285
- spec: m
286
- }), /*#__PURE__*/jsx(TableCell, {
287
- children: /*#__PURE__*/jsx(CalcLiters, {
288
- spec: m,
289
- value: heliumData.helium[m]
290
- })
291
- }), /*#__PURE__*/jsx(TableCell, {
292
- children: /*#__PURE__*/jsx("strong", {
293
- children: /*#__PURE__*/jsx(CalcToMax, {
294
- spec: m,
295
- value: heliumData.helium[m]
296
- })
297
- })
298
- })]
299
- }, m + "_entry");
300
- })
301
- }), /*#__PURE__*/jsx("tfoot", {
302
- children: /*#__PURE__*/jsxs(TableRow, {
303
- children: [/*#__PURE__*/jsx(TableCell, {
304
- children: /*#__PURE__*/jsx("strong", {
305
- children: "Sum"
306
- })
307
- }), /*#__PURE__*/jsx(TableCell, {}), /*#__PURE__*/jsx(TableCell, {}), /*#__PURE__*/jsx(TableCell, {
308
- children: /*#__PURE__*/jsx("strong", {
309
- children: totalToMax
310
- })
311
- })]
312
- })
313
- })]
314
- });
315
- }
316
- function EditAdmon(_ref3) {
317
- var levelsEdited = _ref3.levelsEdited;
318
- if (levelsEdited) {
319
- return /*#__PURE__*/jsxs(React.Fragment, {
320
- children: [", ", /*#__PURE__*/jsx("strong", {
321
- children: "edited"
322
- })]
323
- });
324
- } else {
325
- return null;
326
- }
327
- }
328
-
329
- function SelectSpecs(_ref) {
330
- var specs = _ref.specs,
331
- SetSpecs = _ref.SetSpecs;
332
- function SetAll(value) {
333
- SetSpecs(function (specs) {
334
- Object.keys(specs).map(function (spec) {
335
- return specs[spec] = value;
336
- });
337
- });
338
- return;
339
- }
340
- return /*#__PURE__*/jsxs(FormControl, {
341
- children: [/*#__PURE__*/jsx(Divider, {
342
- textAlign: "left",
343
- children: /*#__PURE__*/jsx("strong", {
344
- children: "Select spectrometers"
345
- })
346
- }), /*#__PURE__*/jsxs(FormGroup, {
347
- row: true,
348
- sx: {
349
- px: 2
350
- },
351
- children: [Object.keys(specs).map(function (m) {
352
- return /*#__PURE__*/jsx(FormControlLabel, {
353
- control: /*#__PURE__*/jsx(Checkbox, {
354
- size: "small"
355
- }),
356
- checked: specs[m],
357
- onChange: function onChange() {
358
- return SetSpecs(function (specs) {
359
- specs[m] = !specs[m];
360
- });
361
- },
362
- label: m
363
- }, m + "_check");
364
- }), " ", /*#__PURE__*/jsx(Button, {
365
- size: "small",
366
- onClick: function onClick() {
367
- return SetAll(true);
368
- },
369
- children: "all"
370
- }), " ", "\u2002", " ", /*#__PURE__*/jsx(Button, {
371
- size: "small",
372
- onClick: function onClick() {
373
- return SetAll(false);
374
- },
375
- children: "none"
376
- })]
377
- })]
378
- });
379
- }
380
-
381
- function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
382
- function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
383
-
384
- // Admonition colors
385
-
386
- var errorBg = AppTheme.palette.primary.main;
387
- var errorText = AppTheme.palette.primary.contrastText;
388
- var warnText = AppTheme.palette.warning.main;
389
- function HePrognosisEntry(_ref) {
390
- var value = _ref.value,
391
- days = _ref.days,
392
- spec = _ref.spec;
393
- var heliumLookupData = useContext(LookupContext);
394
-
395
- // Define lookup objects
396
-
397
- var boilOff = heliumLookupData.boilOff;
398
- var minima = heliumLookupData.minima;
399
- var boil = Math.round(value + days * boilOff[spec]);
400
-
401
- // Catch negative values
402
-
403
- if (boil < 0) {
404
- boil = 0;
405
- }
406
- var boilLiter = CalcLiters({
407
- value: boil,
408
- spec: spec
409
- });
410
- var boilToMax = CalcToMax({
411
- value: boil,
412
- spec: spec
413
- });
414
- var style = {};
415
- if (boil < minima[spec] - 30 * boilOff[spec]) {
416
- style = {
417
- backgroundColor: errorBg,
418
- color: errorText
419
- };
420
- } else if (boil < minima[spec] - 60 * boilOff[spec]) {
421
- style = {
422
- color: warnText
423
- };
424
- }
425
- return /*#__PURE__*/jsxs(TableCell, {
426
- sx: style,
427
- children: [Percentage(boil, true), " ", /*#__PURE__*/jsx("br", {}), boilLiter, " L", /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsxs("strong", {
428
- children: [boilToMax, " L"]
429
- })]
430
- });
431
- }
432
-
433
- // Calculate total missing helium at prognosed date
434
-
435
- function HePrognosisSum(_ref2) {
436
- var heliumData = _ref2.heliumData,
437
- days = _ref2.days;
438
- var heliumLookupData = useContext(LookupContext);
439
-
440
- // Define lookup objects
441
-
442
- var boilOff = heliumLookupData.boilOff;
443
- var boilData = {};
444
- Object.keys(heliumData).map(function (spec) {
445
- boilData = _objectSpread$4(_objectSpread$4({}, boilData), {}, _defineProperty({}, spec, Math.round(heliumData[spec] + days * boilOff[spec])));
446
- return null;
447
- });
448
- var toMaxSum = Object.keys(boilData).reduce(function (total, current) {
449
- return total + CalcToMax({
450
- spec: current,
451
- value: boilData[current]
452
- });
453
- }, 0);
454
- toMaxSum = Math.round(toMaxSum * 10) / 10;
455
- return /*#__PURE__*/jsx(TableCell, {
456
- children: /*#__PURE__*/jsxs("strong", {
457
- children: [toMaxSum, " L"]
458
- })
459
- });
460
- }
461
-
462
- // Cell for day increment with edit switch
463
-
464
- function HePrognosisIncr(_ref3) {
465
- var days = _ref3.days,
466
- increments = _ref3.increments,
467
- SetIncrements = _ref3.SetIncrements,
468
- dates = _ref3.dates;
469
- var _useState = useState(false),
470
- _useState2 = _slicedToArray(_useState, 2),
471
- edit = _useState2[0],
472
- SetEdit = _useState2[1];
473
- var _useState3 = useState(days),
474
- _useState4 = _slicedToArray(_useState3, 2),
475
- input = _useState4[0],
476
- SetInput = _useState4[1];
477
- var _useState5 = useState(false),
478
- _useState6 = _slicedToArray(_useState5, 2),
479
- error = _useState6[0],
480
- SetError = _useState6[1];
481
- if (edit) {
482
- return /*#__PURE__*/jsxs(TableCell, {
483
- children: [dates[days], " ", /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsx(NumField, {
484
- input: input,
485
- SetInput: SetInput,
486
- error: error,
487
- SetError: SetError,
488
- size: "small"
489
- }), /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsx(IconButton, {
490
- disabled: error,
491
- size: "small",
492
- onClick: function onClick() {
493
- SetEdit(!edit);
494
- SetIncrements(increments.map(function (inc) {
495
- if (inc === days) {
496
- return Number(input);
497
- } else {
498
- return inc;
499
- }
500
- }));
501
- },
502
- children: /*#__PURE__*/jsx(SaveIcon, {})
503
- }), /*#__PURE__*/jsx(IconButton, {
504
- size: "small",
505
- onClick: function onClick() {
506
- return SetIncrements(increments.filter(function (n) {
507
- return n !== days;
508
- }));
509
- },
510
- children: /*#__PURE__*/jsx(DeleteIcon, {})
511
- })]
512
- });
513
- } else {
514
- return /*#__PURE__*/jsxs(TableCell, {
515
- children: [dates[days], " ", /*#__PURE__*/jsx("br", {}), " in ", days, " days ", /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsx(IconButton, {
516
- size: "small",
517
- onClick: function onClick() {
518
- return SetEdit(!edit);
519
- },
520
- children: /*#__PURE__*/jsx(EditIcon, {})
521
- }), /*#__PURE__*/jsx(IconButton, {
522
- size: "small",
523
- onClick: function onClick() {
524
- return SetIncrements(increments.filter(function (n) {
525
- return n !== days;
526
- }));
527
- },
528
- children: /*#__PURE__*/jsx(DeleteIcon, {})
529
- })]
530
- });
531
- }
532
- }
533
-
534
- // Render table row in prognosis table
535
-
536
- function HePrognosisBody(_ref4) {
537
- var increments = _ref4.increments,
538
- SetIncrements = _ref4.SetIncrements,
539
- heliumData = _ref4.heliumData,
540
- dates = _ref4.dates;
541
- return /*#__PURE__*/jsx(React.Fragment, {
542
- children: increments.map(function (m) {
543
- return /*#__PURE__*/jsxs(TableRow, {
544
- children: [/*#__PURE__*/jsx(HePrognosisIncr, {
545
- days: m,
546
- increments: increments,
547
- SetIncrements: SetIncrements,
548
- dates: dates
549
- }), Object.keys(heliumData).map(function (spec) {
550
- return /*#__PURE__*/jsx(HePrognosisEntry, {
551
- value: heliumData[spec],
552
- days: m,
553
- spec: spec
554
- }, spec + "_progentry");
555
- }), /*#__PURE__*/jsx(HePrognosisSum, {
556
- heliumData: heliumData,
557
- days: m
558
- })]
559
- }, m + "_incr");
560
- })
561
- });
562
- }
563
-
564
- // function for adding additional table entries
565
-
566
- function AddPrognoEntry(_ref5) {
567
- var increments = _ref5.increments,
568
- SetIncrements = _ref5.SetIncrements;
569
- var _useState7 = useState(""),
570
- _useState8 = _slicedToArray(_useState7, 2),
571
- input = _useState8[0],
572
- SetInput = _useState8[1];
573
- var _useState9 = useState(false),
574
- _useState0 = _slicedToArray(_useState9, 2),
575
- error = _useState0[0],
576
- SetError = _useState0[1];
577
- return /*#__PURE__*/jsxs(React.Fragment, {
578
- children: [/*#__PURE__*/jsx(Divider, {
579
- textAlign: "left",
580
- children: /*#__PURE__*/jsx("strong", {
581
- children: "Add prediction row"
582
- })
583
- }), /*#__PURE__*/jsxs(Grid, {
584
- children: [/*#__PURE__*/jsx(NumField, {
585
- input: input,
586
- SetInput: SetInput,
587
- error: error,
588
- SetError: SetError,
589
- adornment: "days",
590
- size: "medium"
591
- }), /*#__PURE__*/jsx(IconButton, {
592
- disabled: error,
593
- onClick: function onClick() {
594
- SetIncrements([Number(input)].concat(_toConsumableArray(increments)));
595
- },
596
- children: /*#__PURE__*/jsx(AddBoxIcon, {})
597
- })]
598
- })]
599
- });
600
- }
601
-
602
- // render prognosis table based on day increments state array
603
-
604
- function HePrognosis(_ref6) {
605
- var heliumData = _ref6.heliumData;
606
- var heliumLookupData = useContext(LookupContext);
607
-
608
- // Define lookup objects
609
-
610
- var minima = heliumLookupData.minima;
611
- var specDefault = {};
612
- var specList = Object.keys(heliumData.helium);
613
- specList.map(function (spec) {
614
- return specDefault = _objectSpread$4(_objectSpread$4({}, specDefault), {}, _defineProperty({}, spec, true));
615
- });
616
- var _useImmer = useImmer(specDefault),
617
- _useImmer2 = _slicedToArray(_useImmer, 2),
618
- specs = _useImmer2[0],
619
- SetSpecs = _useImmer2[1];
620
- var _useState1 = useState([14, 30, 60, 90]),
621
- _useState10 = _slicedToArray(_useState1, 2),
622
- increments = _useState10[0],
623
- SetIncrements = _useState10[1];
624
- var currHeliumData = {};
625
- Object.keys(specs).filter(function (spec) {
626
- return specs[spec];
627
- }).map(function (spec) {
628
- return currHeliumData = _objectSpread$4(_objectSpread$4({}, currHeliumData), {}, _defineProperty({}, spec, heliumData.helium[spec]));
629
- });
630
- var dates = {};
631
- for (var i in increments) {
632
- var d = new Date();
633
- d.setDate(d.getDate() + increments[i]);
634
- dates = _objectSpread$4(_objectSpread$4({}, dates), {}, _defineProperty({}, increments[i], moment(d).format("ll")));
635
- }
636
- return /*#__PURE__*/jsxs(Grid, {
637
- container: true,
638
- columns: {
639
- xs: 6,
640
- sm: 12
641
- },
642
- children: [/*#__PURE__*/jsx(Grid, {
643
- size: 6,
644
- children: /*#__PURE__*/jsx(SelectSpecs, {
645
- specs: specs,
646
- SetSpecs: SetSpecs
647
- })
648
- }), /*#__PURE__*/jsx(Grid, {
649
- size: 6,
650
- children: /*#__PURE__*/jsx(AddPrognoEntry, {
651
- increments: increments,
652
- SetIncrements: SetIncrements
653
- })
654
- }), /*#__PURE__*/jsx(Grid, {
655
- size: 12,
656
- children: /*#__PURE__*/jsxs(AppTable, {
657
- children: [/*#__PURE__*/jsxs(TableHead, {
658
- children: [/*#__PURE__*/jsxs(TableRow, {
659
- children: [/*#__PURE__*/jsx(TableHeadCell, {}), Object.keys(currHeliumData).map(function (spec) {
660
- return /*#__PURE__*/jsxs(TableHeadCell, {
661
- children: [spec, /*#__PURE__*/jsx("br", {}), "(", minima[spec], " %)"]
662
- }, spec + "_th");
663
- }), /*#__PURE__*/jsx(TableHeadCell, {
664
- children: "Sum"
665
- })]
666
- }), /*#__PURE__*/jsxs(TableRow, {
667
- children: [/*#__PURE__*/jsx(TableHeadCell, {}), /*#__PURE__*/jsx(TableHeadCell, {
668
- align: "center",
669
- colSpan: Object.keys(specs).length + 1,
670
- children: /*#__PURE__*/jsx("em", {
671
- children: "[%], Liters, L. to max"
672
- })
673
- })]
674
- })]
675
- }), /*#__PURE__*/jsx(TableBody, {
676
- children: /*#__PURE__*/jsx(HePrognosisBody, {
677
- increments: increments,
678
- SetIncrements: SetIncrements,
679
- dates: dates,
680
- heliumData: currHeliumData
681
- })
682
- })]
683
- })
684
- }), /*#__PURE__*/jsxs(Grid, {
685
- sx: {
686
- display: "flex",
687
- justifyContent: "center",
688
- alignItems: "center",
689
- pt: 2
690
- },
691
- size: 12,
692
- children: [/*#__PURE__*/jsx(Chip, {
693
- sx: {
694
- backgroundColor: errorBg,
695
- color: errorText,
696
- mx: 1
697
- },
698
- label: "Minimum in less than 30 days"
699
- }), /*#__PURE__*/jsx(Chip, {
700
- sx: {
701
- color: warnText,
702
- mx: 1
703
- },
704
- variant: "outlined",
705
- label: "Minimum in less than 60 days"
706
- })]
707
- })]
708
- });
709
- }
710
-
711
- function LiterInput(_ref) {
712
- var limit = _ref.limit,
713
- SetLimit = _ref.SetLimit,
714
- error = _ref.error,
715
- SetError = _ref.SetError;
716
- var _useState = useState(limit),
717
- _useState2 = _slicedToArray(_useState, 2),
718
- input = _useState2[0],
719
- SetInput = _useState2[1];
720
- var _useState3 = useState(false),
721
- _useState4 = _slicedToArray(_useState3, 2),
722
- edit = _useState4[0],
723
- SetEdit = _useState4[1];
724
- if (edit) {
725
- return /*#__PURE__*/jsxs(React.Fragment, {
726
- children: [/*#__PURE__*/jsx(NumField, {
727
- input: input,
728
- SetInput: SetInput,
729
- error: error,
730
- SetError: SetError,
731
- size: "medium",
732
- adornment: "L"
733
- }), " ", /*#__PURE__*/jsx(IconButton, {
734
- disabled: error,
735
- size: "small",
736
- onClick: function onClick() {
737
- SetEdit(!edit);
738
- SetLimit(Number(input));
739
- },
740
- children: /*#__PURE__*/jsx(SaveIcon, {})
741
- })]
742
- });
743
- } else {
744
- return /*#__PURE__*/jsxs(React.Fragment, {
745
- children: [limit, " L", " ", /*#__PURE__*/jsx(IconButton, {
746
- size: "small",
747
- onClick: function onClick() {
748
- return SetEdit(!edit);
749
- },
750
- children: /*#__PURE__*/jsx(EditIcon, {})
751
- })]
752
- });
753
- }
754
- }
755
-
756
- function FindPair(_ref) {
757
- var currSpecs = _ref.currSpecs,
758
- heliumData = _ref.heliumData,
759
- boilOff = _ref.boilOff,
760
- limit = _ref.limit;
761
- // find all possible pairs of spectrometers
762
-
763
- var specPairs = [];
764
- currSpecs.map(function (spec1) {
765
- currSpecs.map(function (spec2) {
766
- if (spec1 !== spec2) {
767
- specPairs.push([spec1, spec2].sort()); // sort to facilitate duplicate removal
768
- }
769
- });
770
- });
771
-
772
- // remove duplicates from array by conversion to string
773
-
774
- specPairs = Array.from(new Set(specPairs.map(JSON.stringify)), JSON.parse);
775
- var specPairsLiters = [];
776
- var _loop = function _loop() {
777
- var j = 1;
778
- var pairBoil = 0;
779
-
780
- // Add current pair of specs
781
-
782
- specPairsLiters.push(specPairs[i]);
783
-
784
- // Calculate L. to max for pair until reaching target value
785
-
786
- do {
787
- pairBoil = specPairs[i].reduce(function (total, current) {
788
- var boil = Math.round(heliumData.helium[current] + j * boilOff[current]);
789
-
790
- // Catch negative values
791
- if (boil < 0) {
792
- boil = 0;
793
- }
794
- var boilToMax = CalcToMax({
795
- value: boil,
796
- spec: current
797
- });
798
- return total + boilToMax;
799
- }, 0);
800
- j++;
801
- } while (pairBoil < limit && j < 300);
802
-
803
- // Result to pair
804
-
805
- specPairsLiters[i].push(j);
806
- specPairsLiters[i].push(pairBoil);
807
- specPairsLiters[i].push(pairBoil > limit);
808
- };
809
- for (var i in specPairs) {
810
- _loop();
811
- }
812
-
813
- // Remove pairs that did not converge
814
-
815
- specPairsLiters = specPairsLiters.filter(function (pair) {
816
- return pair[4];
817
- });
818
-
819
- // Find pair with minimal number of days
820
-
821
- var minPair = [];
822
- switch (specPairsLiters.length) {
823
- case 0:
824
- minPair = [];
825
- break;
826
- case 1:
827
- minPair = _toConsumableArray(specPairsLiters);
828
- break;
829
- default:
830
- minPair = specPairsLiters.reduce(function (min, current) {
831
- var i = current[2] < min[2] ? current : min;
832
- return i;
833
- });
834
- break;
835
- }
836
- minPair = minPair.flat();
837
- return minPair;
838
- }
839
- function FindTriple(_ref2) {
840
- var currSpecs = _ref2.currSpecs,
841
- heliumData = _ref2.heliumData,
842
- boilOff = _ref2.boilOff,
843
- limit = _ref2.limit;
844
- // find all possible triples of spectrometers
845
-
846
- var specTriples = [];
847
- currSpecs.map(function (spec1) {
848
- currSpecs.map(function (spec2) {
849
- currSpecs.map(function (spec3) {
850
- if (!(spec1 === spec2 || spec2 === spec3 || spec3 === spec1)) {
851
- specTriples.push([spec1, spec2, spec3].sort()); // sort to facilitate duplicate removal
852
- }
853
- });
854
- });
855
- });
856
-
857
- // remove duplicates from array by conversion to string
858
-
859
- specTriples = Array.from(new Set(specTriples.map(JSON.stringify)), JSON.parse);
860
- var specTriplesLiters = [];
861
- var _loop2 = function _loop2() {
862
- var j = 1;
863
- var pairBoil = 0;
864
-
865
- // Add current pair of specs
866
-
867
- specTriplesLiters.push(specTriples[i]);
868
-
869
- // Calculate L. to max for pair until reaching target value
870
-
871
- do {
872
- pairBoil = specTriples[i].reduce(function (total, current) {
873
- var boil = Math.round(heliumData.helium[current] + j * boilOff[current]);
874
-
875
- // Catch negative values
876
- if (boil < 0) {
877
- boil = 0;
878
- }
879
- var boilToMax = CalcToMax({
880
- value: boil,
881
- spec: current
882
- });
883
- return total + boilToMax;
884
- }, 0);
885
- j++;
886
- } while (pairBoil < limit && j < 300);
887
-
888
- // Result to triple
889
-
890
- specTriplesLiters[i].push(j);
891
- specTriplesLiters[i].push(pairBoil);
892
- specTriplesLiters[i].push(pairBoil > limit);
893
- };
894
- for (var i in specTriples) {
895
- _loop2();
896
- }
897
-
898
- // Remove triples that did not converge
899
-
900
- specTriplesLiters = specTriplesLiters.filter(function (pair) {
901
- return pair[5];
902
- });
903
-
904
- // Find triple with minimal number of days
905
-
906
- var minTriple = [];
907
- switch (specTriplesLiters.length) {
908
- case 0:
909
- minTriple = [];
910
- break;
911
- case 1:
912
- minTriple = _toConsumableArray(specTriplesLiters);
913
- break;
914
- default:
915
- minTriple = specTriplesLiters.reduce(function (min, current) {
916
- var i = current[3] < min[3] ? current : min;
917
- return i;
918
- });
919
- break;
920
- }
921
- minTriple = minTriple.flat();
922
- return minTriple;
923
- }
924
-
925
- function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
926
- function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
927
- function TupleResult(_ref) {
928
- var children = _ref.children,
929
- title = _ref.title;
930
- return /*#__PURE__*/jsx(Grid, {
931
- children: /*#__PURE__*/jsxs(AppTable, {
932
- children: [/*#__PURE__*/jsx(TableHead, {
933
- children: /*#__PURE__*/jsx(TableRow, {
934
- children: /*#__PURE__*/jsx(TableHeadCell, {
935
- children: title
936
- })
937
- })
938
- }), /*#__PURE__*/jsx(TableBody, {
939
- children: /*#__PURE__*/jsx(TableRow, {
940
- children: /*#__PURE__*/jsx(TableCell, {
941
- children: children
942
- })
943
- })
944
- })]
945
- })
946
- });
947
- }
948
- function PairResult(_ref2) {
949
- var minPair = _ref2.minPair;
950
- if (minPair.length !== 0) {
951
- var d = new Date();
952
- d.setDate(d.getDate() + minPair[2]);
953
- var date = moment$1(d).format("ll");
954
- return /*#__PURE__*/jsxs(TupleResult, {
955
- title: "Pair",
956
- children: [/*#__PURE__*/jsx("strong", {
957
- children: minPair[0]
958
- }), " and ", /*#__PURE__*/jsx("strong", {
959
- children: minPair[1]
960
- }), " ", "in ", /*#__PURE__*/jsxs("strong", {
961
- children: [minPair[2], " days"]
962
- }), " (", date, ")"]
963
- });
964
- } else {
965
- return /*#__PURE__*/jsx(TupleResult, {
966
- title: "Pair",
967
- children: /*#__PURE__*/jsx("em", {
968
- children: "No spectrometer pair reaches the target value."
969
- })
970
- });
971
- }
972
- }
973
- function TripleResult(_ref3) {
974
- var minTriple = _ref3.minTriple;
975
- if (minTriple.length !== 0) {
976
- var d = new Date();
977
- d.setDate(d.getDate() + minTriple[3]);
978
- var date = moment$1(d).format("ll");
979
- return /*#__PURE__*/jsxs(TupleResult, {
980
- title: "Triple",
981
- children: [/*#__PURE__*/jsx("strong", {
982
- children: minTriple[0]
983
- }), ", ", /*#__PURE__*/jsx("strong", {
984
- children: minTriple[1]
985
- }), ", and ", /*#__PURE__*/jsx("strong", {
986
- children: minTriple[2]
987
- }), " in", " ", /*#__PURE__*/jsxs("strong", {
988
- children: [minTriple[3], " days"]
989
- }), " (", date, ")"]
990
- });
991
- } else {
992
- return /*#__PURE__*/jsx(TupleResult, {
993
- title: "Triple",
994
- children: /*#__PURE__*/jsx("p", {
995
- children: /*#__PURE__*/jsx("em", {
996
- children: "No spectrometer triple reaches the target value."
997
- })
998
- })
999
- });
1000
- }
1001
- }
1002
- function PairWizard(_ref4) {
1003
- var heliumData = _ref4.heliumData;
1004
- var heliumLookupData = useContext(LookupContext);
1005
-
1006
- // Define lookup objects
1007
-
1008
- var boilOff = heliumLookupData.boilOff;
1009
- var defaultSpecs = {};
1010
- Object.keys(boilOff).map(function (spec) {
1011
- return defaultSpecs = _objectSpread$3(_objectSpread$3({}, defaultSpecs), {}, _defineProperty({}, spec, true));
1012
- });
1013
- var _useImmer = useImmer(defaultSpecs),
1014
- _useImmer2 = _slicedToArray(_useImmer, 2),
1015
- specs = _useImmer2[0],
1016
- SetSpecs = _useImmer2[1];
1017
- var currSpecs = Object.keys(specs).filter(function (spec) {
1018
- return specs[spec];
1019
- });
1020
- var _useState = useState(false),
1021
- _useState2 = _slicedToArray(_useState, 2),
1022
- error = _useState2[0],
1023
- SetError = _useState2[1];
1024
- var _useState3 = useState(100),
1025
- _useState4 = _slicedToArray(_useState3, 2),
1026
- limit = _useState4[0],
1027
- SetLimit = _useState4[1];
1028
- var minPair = FindPair(_objectSpread$3({}, {
1029
- currSpecs: currSpecs,
1030
- heliumData: heliumData,
1031
- boilOff: boilOff,
1032
- limit: limit
1033
- }));
1034
- var minTriple = FindTriple(_objectSpread$3({}, {
1035
- currSpecs: currSpecs,
1036
- heliumData: heliumData,
1037
- boilOff: boilOff,
1038
- limit: limit
1039
- }));
1040
- return /*#__PURE__*/jsx(React.Fragment, {
1041
- children: /*#__PURE__*/jsxs(Grid, {
1042
- container: true,
1043
- columns: {
1044
- xs: 6,
1045
- md: 12
1046
- },
1047
- children: [/*#__PURE__*/jsxs(Grid, {
1048
- sx: {
1049
- px: 2
1050
- },
1051
- size: 6,
1052
- children: [/*#__PURE__*/jsx(Divider, {
1053
- textAlign: "left",
1054
- children: /*#__PURE__*/jsx("strong", {
1055
- children: "Find earliest set of spectrometers requiring"
1056
- })
1057
- }), /*#__PURE__*/jsx(Grid, {
1058
- sx: {
1059
- padding: 2,
1060
- display: "flex",
1061
- justifyContent: "center"
1062
- },
1063
- children: /*#__PURE__*/jsx(Typography, {
1064
- variant: "h4",
1065
- children: /*#__PURE__*/jsx(LiterInput, {
1066
- limit: limit,
1067
- SetLimit: SetLimit,
1068
- error: error,
1069
- SetError: SetError
1070
- })
1071
- })
1072
- }), /*#__PURE__*/jsx(Grid, {
1073
- children: /*#__PURE__*/jsx(SelectSpecs, {
1074
- specs: specs,
1075
- SetSpecs: SetSpecs
1076
- })
1077
- })]
1078
- }), /*#__PURE__*/jsxs(Grid, {
1079
- sx: {
1080
- px: 2
1081
- },
1082
- size: 6,
1083
- children: [/*#__PURE__*/jsx(Divider, {
1084
- textAlign: "left",
1085
- children: /*#__PURE__*/jsx("strong", {
1086
- children: "Result"
1087
- })
1088
- }), /*#__PURE__*/jsxs(Grid, {
1089
- sx: {
1090
- px: 3
1091
- },
1092
- children: [/*#__PURE__*/jsx(PairResult, {
1093
- minPair: minPair
1094
- }), /*#__PURE__*/jsx(TripleResult, {
1095
- minTriple: minTriple
1096
- })]
1097
- })]
1098
- })]
1099
- })
1100
- });
1101
- }
1102
-
1103
- function FillTarget(_ref) {
1104
- var heliumData = _ref.heliumData;
1105
- var heliumLookupData = useContext(LookupContext);
1106
- var boilOff = heliumLookupData.boilOff;
1107
- var lookup = heliumLookupData.lookup;
1108
- var _useState = useState(false),
1109
- _useState2 = _slicedToArray(_useState, 2),
1110
- error = _useState2[0],
1111
- SetError = _useState2[1];
1112
- var _useState3 = useState(25),
1113
- _useState4 = _slicedToArray(_useState3, 2),
1114
- amount = _useState4[0],
1115
- SetAmount = _useState4[1];
1116
- var _useState5 = useState(Object.keys(lookup)[0]),
1117
- _useState6 = _slicedToArray(_useState5, 2),
1118
- spec = _useState6[0],
1119
- SetSpec = _useState6[1];
1120
- var currLevel = heliumData.helium[spec];
1121
- var currLiter = CalcLiters({
1122
- value: currLevel,
1123
- spec: spec
1124
- });
1125
- var finalLiter = currLiter + amount;
1126
- var finalLevel = CalcPercent({
1127
- value: finalLiter,
1128
- spec: spec
1129
- });
1130
- return /*#__PURE__*/jsx(React.Fragment, {
1131
- children: /*#__PURE__*/jsxs(Grid, {
1132
- container: true,
1133
- columns: {
1134
- xs: 6,
1135
- md: 12
1136
- },
1137
- children: [/*#__PURE__*/jsxs(Grid, {
1138
- sx: {
1139
- px: 2
1140
- },
1141
- size: 6,
1142
- children: [/*#__PURE__*/jsx(Divider, {
1143
- textAlign: "left",
1144
- children: /*#__PURE__*/jsx("strong", {
1145
- children: "Select Spectrometer"
1146
- })
1147
- }), /*#__PURE__*/jsx(Grid, {
1148
- sx: {
1149
- padding: 2,
1150
- display: "flex",
1151
- justifyContent: "center"
1152
- },
1153
- children: /*#__PURE__*/jsx(SpecSwitch, {
1154
- setup: boilOff,
1155
- spec: spec,
1156
- SetSpec: SetSpec
1157
- })
1158
- })]
1159
- }), /*#__PURE__*/jsxs(Grid, {
1160
- sx: {
1161
- px: 2
1162
- },
1163
- size: 6,
1164
- children: [/*#__PURE__*/jsx(Divider, {
1165
- textAlign: "left",
1166
- children: /*#__PURE__*/jsx("strong", {
1167
- children: "Current status"
1168
- })
1169
- }), /*#__PURE__*/jsx(Grid, {
1170
- sx: {
1171
- padding: 2,
1172
- display: "flex",
1173
- justifyContent: "center"
1174
- },
1175
- children: /*#__PURE__*/jsxs(Typography, {
1176
- variant: "h4",
1177
- children: [currLevel, " % (", currLiter, " L)"]
1178
- })
1179
- })]
1180
- }), /*#__PURE__*/jsxs(Grid, {
1181
- sx: {
1182
- px: 2
1183
- },
1184
- size: 6,
1185
- children: [/*#__PURE__*/jsx(Divider, {
1186
- textAlign: "left",
1187
- children: /*#__PURE__*/jsx("strong", {
1188
- children: "Helium fill amount"
1189
- })
1190
- }), /*#__PURE__*/jsx(Grid, {
1191
- sx: {
1192
- padding: 2,
1193
- display: "flex",
1194
- justifyContent: "center"
1195
- },
1196
- children: /*#__PURE__*/jsx(Typography, {
1197
- variant: "h4",
1198
- children: /*#__PURE__*/jsx(LiterInput, {
1199
- error: error,
1200
- SetError: SetError,
1201
- limit: amount,
1202
- SetLimit: SetAmount
1203
- })
1204
- })
1205
- })]
1206
- }), /*#__PURE__*/jsxs(Grid, {
1207
- sx: {
1208
- px: 2
1209
- },
1210
- size: 6,
1211
- children: [/*#__PURE__*/jsx(Divider, {
1212
- textAlign: "left",
1213
- children: /*#__PURE__*/jsx("strong", {
1214
- children: "After filling"
1215
- })
1216
- }), /*#__PURE__*/jsx(Grid, {
1217
- sx: {
1218
- padding: 2,
1219
- display: "flex",
1220
- justifyContent: "center"
1221
- },
1222
- children: /*#__PURE__*/jsx(Typography, {
1223
- variant: "h4",
1224
- children: /*#__PURE__*/jsxs("em", {
1225
- style: {
1226
- color: AppTheme.palette.warning.main
1227
- },
1228
- children: ["~ ", finalLevel, " % (", CalcLiters({
1229
- value: finalLevel,
1230
- spec: spec
1231
- }), " L)"]
1232
- })
1233
- })
1234
- })]
1235
- })]
1236
- })
1237
- });
1238
- }
1239
-
1240
- function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1241
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1242
- function EstimateConsumption() {
1243
- // Get data
1244
-
1245
- var heliumLookupData = useContext(LookupContext);
1246
- var boilOff = heliumLookupData.boilOff;
1247
- var lookup = heliumLookupData.lookup;
1248
-
1249
- // Define array and populate with days and liters to get from 100% to 50%
1250
-
1251
- var specCons = [];
1252
- Object.keys(lookup).map(function (spec) {
1253
- return specCons.push({
1254
- name: spec,
1255
- liters: (lookup[spec].filter(function (x) {
1256
- return x.level === 100;
1257
- })[0].liters - lookup[spec].filter(function (x) {
1258
- return x.level === 50;
1259
- })[0].liters).toFixed(1),
1260
- days: (-50 / boilOff[spec]).toFixed(1)
1261
- });
1262
- });
1263
-
1264
- // Calculate consumption per day, month, year from values above
1265
-
1266
- specCons = specCons.map(function (spec) {
1267
- return _objectSpread$2(_objectSpread$2({}, spec), {}, {
1268
- perDay: spec.liters / spec.days,
1269
- perMonth: (spec.liters / spec.days * 30).toFixed(1),
1270
- perYear: (spec.liters / spec.days * 365).toFixed(1)
1271
- });
1272
- });
1273
- return /*#__PURE__*/jsxs(React.Fragment, {
1274
- children: [/*#__PURE__*/jsx("p", {
1275
- children: "Helium consumption estimated based on lookup values."
1276
- }), /*#__PURE__*/jsxs(AppTable, {
1277
- children: [/*#__PURE__*/jsx(TableHead, {
1278
- children: /*#__PURE__*/jsxs(TableRow, {
1279
- children: [/*#__PURE__*/jsx(TableHeadCell, {}), specCons.map(function (spec) {
1280
- return /*#__PURE__*/jsx(TableHeadCell, {
1281
- children: spec.name
1282
- }, "Head" + spec.name);
1283
- }), /*#__PURE__*/jsx(TableHeadCell, {
1284
- children: "Sum"
1285
- })]
1286
- })
1287
- }), /*#__PURE__*/jsxs(TableBody, {
1288
- children: [/*#__PURE__*/jsxs(TableRow, {
1289
- children: [/*#__PURE__*/jsx(TableCell, {
1290
- children: "per month"
1291
- }), specCons.map(function (spec) {
1292
- return /*#__PURE__*/jsxs(TableCell, {
1293
- children: [spec.perMonth, " L ", /*#__PURE__*/jsx("br", {}), "(", (spec.perMonth * 0.79).toFixed(2), " m", /*#__PURE__*/jsx("sup", {
1294
- children: "3"
1295
- }), " Gas)"]
1296
- }, "perMonth" + spec.name);
1297
- }), /*#__PURE__*/jsx(TableCell, {
1298
- children: /*#__PURE__*/jsxs("strong", {
1299
- children: [specCons.reduce(function (total, spec) {
1300
- return total + Number(spec.perMonth);
1301
- }, 0).toFixed(1), " ", "L", /*#__PURE__*/jsx("br", {}), "(", (specCons.reduce(function (total, spec) {
1302
- return total + Number(spec.perMonth);
1303
- }, 0) * 0.79).toFixed(2), " ", "m", /*#__PURE__*/jsx("sup", {
1304
- children: "3"
1305
- }), " Gas)"]
1306
- })
1307
- })]
1308
- }), /*#__PURE__*/jsxs(TableRow, {
1309
- children: [/*#__PURE__*/jsx(TableCell, {
1310
- rowSpan: 2,
1311
- children: "per year"
1312
- }), specCons.map(function (spec) {
1313
- return /*#__PURE__*/jsxs(TableCell, {
1314
- children: [spec.perYear, " L ", /*#__PURE__*/jsx("br", {}), "(", (spec.perYear * 0.79).toFixed(2), " m", /*#__PURE__*/jsx("sup", {
1315
- children: "3"
1316
- }), " ", "Gas)"]
1317
- }, "perYear" + spec.name);
1318
- }), /*#__PURE__*/jsx(TableCell, {
1319
- children: /*#__PURE__*/jsxs("strong", {
1320
- children: [specCons.reduce(function (total, spec) {
1321
- return total + Number(spec.perYear);
1322
- }, 0).toFixed(1), " ", "L", /*#__PURE__*/jsx("br", {}), "(", (specCons.reduce(function (total, spec) {
1323
- return total + Number(spec.perYear);
1324
- }, 0) * 0.79).toFixed(2), " ", "m", /*#__PURE__*/jsx("sup", {
1325
- children: "3"
1326
- }), " Gas)"]
1327
- })
1328
- })]
1329
- })]
1330
- })]
1331
- })]
1332
- });
1333
- }
1334
-
1335
- function ShowEstimate(_ref) {
1336
- var spec = _ref.spec,
1337
- estimatedBoiloff = _ref.estimatedBoiloff,
1338
- estimatedError = _ref.estimatedError;
1339
- var heliumLookupData = useContext(LookupContext);
1340
-
1341
- // Get stored data
1342
-
1343
- var storedBoiloff = heliumLookupData.boilOff[spec].toFixed(3) || "N/A";
1344
-
1345
- // Round values from props
1346
-
1347
- estimatedBoiloff = estimatedBoiloff.toFixed(3) || "N/A";
1348
- estimatedError = estimatedError.toFixed(3) || "N/A";
1349
-
1350
- // Warn if values differ
1351
-
1352
- var renderEstimatedBoiloff = Math.abs(estimatedBoiloff - storedBoiloff) < 0.01 ? estimatedBoiloff : /*#__PURE__*/jsx("strong", {
1353
- style: {
1354
- color: AppTheme.palette.primary.main
1355
- },
1356
- children: estimatedBoiloff
1357
- });
1358
- return /*#__PURE__*/jsxs("div", {
1359
- children: [/*#__PURE__*/jsx("h4", {
1360
- children: "Boiloff coefficients (%/day)"
1361
- }), /*#__PURE__*/jsx(Grid, {
1362
- container: true,
1363
- children: /*#__PURE__*/jsxs(AppTable, {
1364
- children: [/*#__PURE__*/jsx(TableHead, {
1365
- children: /*#__PURE__*/jsxs(TableRow, {
1366
- children: [/*#__PURE__*/jsx(TableHeadCell, {
1367
- children: "Estimated"
1368
- }), /*#__PURE__*/jsx(TableHeadCell, {
1369
- children: "Stored"
1370
- })]
1371
- })
1372
- }), /*#__PURE__*/jsx(TableBody, {
1373
- children: /*#__PURE__*/jsxs(TableRow, {
1374
- children: [/*#__PURE__*/jsxs(TableCell, {
1375
- children: [renderEstimatedBoiloff, " ", /*#__PURE__*/jsxs("em", {
1376
- style: {
1377
- color: AppTheme.palette.secondary.main
1378
- },
1379
- children: ["(\xB1", estimatedError, ")"]
1380
- })]
1381
- }), /*#__PURE__*/jsx(TableCell, {
1382
- children: storedBoiloff
1383
- })]
1384
- })
1385
- })]
1386
- })
1387
- })]
1388
- });
1389
- }
1390
-
1391
- function EstimateSlope(_ref) {
1392
- var data = _ref.data;
1393
- _ref.spec;
1394
- // define slope and intercept
1395
-
1396
- var slope = 0;
1397
- var intercept = 0;
1398
-
1399
- // Define firstMax and firstMaxIndex
1400
-
1401
- var firstMax = Number(data[data.length - 1].level);
1402
- var firstMaxIndex = data.length - 1;
1403
-
1404
- // Check if the last time when the spectrometer was filled is more than 45 days ago
1405
-
1406
- var lastMaxIndex = data.length - 1;
1407
- var lastMax = Number(data[lastMaxIndex].level);
1408
- for (var i = data.length - 2; i >= 0; i--) {
1409
- var level = Number(data[i].level);
1410
- if (level > firstMax) {
1411
- lastMax = level;
1412
- lastMaxIndex = i;
1413
- }
1414
-
1415
- // stop if level decreases from maximum
1416
-
1417
- if (level < lastMax) {
1418
- break;
1419
- }
1420
- }
1421
-
1422
- // if the last maximum is less than 45 days ago, use the last maximum as the first maximum
1423
- // otherwise, the initial firstMaxIndex is the last maximum index
1424
-
1425
- if (lastMaxIndex >= data.length - 45) {
1426
- firstMaxIndex = lastMaxIndex - 1;
1427
- firstMax = Number(data[firstMaxIndex].level);
1428
- }
1429
-
1430
- // minimum level is the level at firstMaxIndex
1431
-
1432
- var minLevelIndex = firstMaxIndex - 1;
1433
-
1434
- // find previous time when spectrometer was filled - for this start from lastMinimumIndex and go back until a maximum is found or until level reaches 90%
1435
-
1436
- var maxLevel = Number(data[minLevelIndex].level);
1437
- var maxLevelIndex = minLevelIndex;
1438
- for (var _i = minLevelIndex - 1; _i >= 0; _i--) {
1439
- var _level = Number(data[_i].level);
1440
- if (_level > maxLevel) {
1441
- maxLevel = _level;
1442
- maxLevelIndex = _i;
1443
- }
1444
-
1445
- // stop if level is decreases from maximum or if level is above 90%
1446
-
1447
- if (_level < maxLevel - 1 || _level >= 90) {
1448
- break;
1449
- }
1450
- }
1451
-
1452
- // Create an array of points between maximum and minimum in the form [[x1, y1], [x2, y2], ...]
1453
-
1454
- var points = [];
1455
- for (var _i2 = maxLevelIndex; _i2 <= minLevelIndex; _i2++) {
1456
- points.push([_i2, Number(data[_i2].level)]);
1457
- }
1458
-
1459
- // Perform linear regression on the points
1460
-
1461
- var result = regression.linear(points, {
1462
- precision: 6
1463
- });
1464
- slope = result.equation[0];
1465
- intercept = result.equation[1];
1466
-
1467
- // Determine slope uncertainty based on regression result
1468
- // For that, create an array of control values
1469
- var control = [];
1470
- for (var _i3 = maxLevelIndex; _i3 <= minLevelIndex; _i3++) {
1471
- control.push([_i3, _i3 * slope + intercept]);
1472
- }
1473
-
1474
- // Calculate mean x value
1475
-
1476
- var meanX = mean(points.map(function (point) {
1477
- return point[0];
1478
- }));
1479
-
1480
- // Calculate standard slope error
1481
-
1482
- var slopeError = sqrt(1 / (control.length - 2) * sum(points.map(function (point, i) {
1483
- return Math.pow(point[1] - control[i][1], 2);
1484
- })) / sum(points.map(function (point, i) {
1485
- return Math.pow(point[0] - meanX, 2);
1486
- })));
1487
- return {
1488
- slope: slope,
1489
- intercept: intercept,
1490
- slopeError: slopeError
1491
- };
1492
- }
1493
-
1494
- function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1495
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1496
- function RenderGraph(_ref) {
1497
- var data = _ref.data,
1498
- height = _ref.height,
1499
- width = _ref.width,
1500
- spec = _ref.spec;
1501
- // Import Context
1502
-
1503
- var heliumLookupData = useContext(LookupContext);
1504
-
1505
- // Get estimated data
1506
-
1507
- var estimateResult = EstimateSlope(_objectSpread$1({}, {
1508
- data: data,
1509
- spec: spec
1510
- }));
1511
- var estimatedBoiloff = estimateResult.slope;
1512
- var estimatedIntercept = estimateResult.intercept;
1513
- var estimatedError = estimateResult.slopeError;
1514
-
1515
- // Custom Tooltip for LineChart
1516
-
1517
- var CustomTooltip = function CustomTooltip(_ref2) {
1518
- var active = _ref2.active,
1519
- payload = _ref2.payload,
1520
- label = _ref2.label;
1521
- if (active && payload && payload.length) {
1522
- var date = moment(payload[0].payload.date, "ddd MMM D HH:mm:ss YYYY").format("LL");
1523
- return /*#__PURE__*/jsxs("div", {
1524
- style: {
1525
- border: "solid 1px " + AppTheme.palette.secondary.main,
1526
- padding: "0.75em",
1527
- backgroundColor: "#ffffffaa"
1528
- },
1529
- children: [/*#__PURE__*/jsx("strong", {
1530
- children: date
1531
- }), /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsxs("em", {
1532
- children: ["(", label, " days ago)"]
1533
- }), /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsxs("strong", {
1534
- style: {
1535
- color: AppTheme.palette.primary.main
1536
- },
1537
- children: [payload[0].value, " %"]
1538
- })]
1539
- });
1540
- }
1541
- };
1542
-
1543
- // Button for days state change
1544
-
1545
- function DayButton(_ref3) {
1546
- var value = _ref3.value;
1547
- return /*#__PURE__*/jsx(Button, {
1548
- onClick: function onClick() {
1549
- return SetDays(value);
1550
- },
1551
- color: value === days ? "primary" : "secondary" // Active button style
1552
- ,
1553
- variant: value === days ? "contained" : "outlined" // Active button style
1554
- ,
1555
- size: "small",
1556
- children: value
1557
- });
1558
- }
1559
-
1560
- // State
1561
-
1562
- var _useState = useState(90),
1563
- _useState2 = _slicedToArray(_useState, 2),
1564
- days = _useState2[0],
1565
- SetDays = _useState2[1];
1566
- var _useState3 = useState(true),
1567
- _useState4 = _slicedToArray(_useState3, 2),
1568
- showMinima = _useState4[0],
1569
- setShowMinima = _useState4[1];
1570
- var _useState5 = useState(false),
1571
- _useState6 = _slicedToArray(_useState5, 2),
1572
- showEstimate = _useState6[0],
1573
- setShowEstimate = _useState6[1];
1574
-
1575
- // Add days ago to data (do not mutate props — create a new array)
1576
- var dataWithDays = (data || []).map(function (item) {
1577
- return _objectSpread$1(_objectSpread$1({}, item), {}, {
1578
- days: -moment(item.date, "ddd MMM D HH:mm:ss YYYY").diff(moment(), "days")
1579
- });
1580
- });
1581
-
1582
- // Get chart data from estimate
1583
-
1584
- // First, get difference between today and last data point
1585
-
1586
- // Guard against empty data
1587
- var daysSinceUpate = 0;
1588
- if (dataWithDays.length > 0) {
1589
- daysSinceUpate = moment().diff(moment(dataWithDays[dataWithDays.length - 1].date, "ddd MMM D HH:mm:ss YYYY"), "days");
1590
- }
1591
-
1592
- // Then calculate estimated data points
1593
-
1594
- // Build final dataset (with optional estimate) without mutating original
1595
- var dataWithEstimate = showEstimate ? dataWithDays.map(function (item) {
1596
- var itemDays = item.days;
1597
- var level = item.level;
1598
- var estimate = estimatedBoiloff * (dataWithDays.length - itemDays + daysSinceUpate) + estimatedIntercept;
1599
- return {
1600
- date: item.date,
1601
- days: itemDays,
1602
- level: level,
1603
- estimate: estimate
1604
- };
1605
- }) : dataWithDays;
1606
-
1607
- // Get last n elements of array
1608
-
1609
- var slicedData = dataWithEstimate.slice(Math.max(dataWithEstimate.length - days, 0));
1610
-
1611
- // Improve visibility of estimate
1612
-
1613
- var lineColor = showEstimate ? AppTheme.palette.grey[300] : AppTheme.palette.primary.main;
1614
- return /*#__PURE__*/jsxs(React.Fragment, {
1615
- children: [/*#__PURE__*/jsxs(LineChart, {
1616
- height: height,
1617
- width: width,
1618
- data: slicedData,
1619
- margin: {
1620
- top: 5,
1621
- right: 20,
1622
- bottom: 25,
1623
- left: 0
1624
- },
1625
- children: [/*#__PURE__*/jsx(Line, {
1626
- dataKey: "level",
1627
- stroke: lineColor,
1628
- fill: lineColor,
1629
- type: "linear",
1630
- dot: {
1631
- r: 1.5
1632
- }
1633
- }), showEstimate ? /*#__PURE__*/jsx(Line, {
1634
- dataKey: "estimate",
1635
- stroke: AppTheme.palette.action.main,
1636
- type: "monotone",
1637
- strokeDasharray: "5 5",
1638
- strokeWidth: 2,
1639
- dot: false
1640
- }) : null, /*#__PURE__*/jsx(CartesianGrid, {
1641
- stroke: AppTheme.palette.divider,
1642
- strokeDasharray: "5 5"
1643
- }), /*#__PURE__*/jsx(XAxis, {
1644
- dataKey: "days",
1645
- interval: days < 15 ? 1 : Math.round(days / 3),
1646
- children: /*#__PURE__*/jsx(Label, {
1647
- value: "Days ago",
1648
- offset: 1,
1649
- position: "bottom"
1650
- })
1651
- }), /*#__PURE__*/jsx(YAxis, {
1652
- dataKey: "level",
1653
- unit: "%",
1654
- type: "number",
1655
- domain: [0, 100]
1656
- }), showMinima ? /*#__PURE__*/jsxs(React.Fragment, {
1657
- children: [/*#__PURE__*/jsx(ReferenceLine, {
1658
- y: heliumLookupData.minima[spec],
1659
- stroke: AppTheme.palette.secondary.main,
1660
- strokeDasharray: (3)
1661
- }), /*#__PURE__*/jsx(ReferenceArea, {
1662
- y1: heliumLookupData.minima[spec],
1663
- y2: 0,
1664
- stroke: "none",
1665
- stro: true,
1666
- fill: AppTheme.palette.secondary.main,
1667
- fillOpacity: 0.1
1668
- })]
1669
- }) : null, /*#__PURE__*/jsx(Tooltip, {
1670
- content: /*#__PURE__*/jsx(CustomTooltip, {})
1671
- })]
1672
- }), /*#__PURE__*/jsxs(ButtonGroup, {
1673
- disableElevation: true,
1674
- variant: "outlined",
1675
- fullWidth: true,
1676
- color: "secondary",
1677
- "aria-label": "contained primary button group",
1678
- sx: {
1679
- justifySelf: "center",
1680
- px: 5
1681
- },
1682
- size: "small",
1683
- children: [/*#__PURE__*/jsx(DayButton, {
1684
- value: 7
1685
- }), /*#__PURE__*/jsx(DayButton, {
1686
- value: 30
1687
- }), /*#__PURE__*/jsx(DayButton, {
1688
- value: 90
1689
- }), /*#__PURE__*/jsx(DayButton, {
1690
- value: 180
1691
- }), /*#__PURE__*/jsx(DayButton, {
1692
- value: 365
1693
- })]
1694
- }), /*#__PURE__*/jsxs(FormGroup, {
1695
- children: [/*#__PURE__*/jsx(FormControlLabel, {
1696
- control: /*#__PURE__*/jsx(Switch, {
1697
- label: "Show Minimum",
1698
- checked: showMinima,
1699
- onChange: function onChange() {
1700
- return setShowMinima(!showMinima);
1701
- }
1702
- }),
1703
- label: "Show Minimum",
1704
- sx: {
1705
- justifyContent: "center"
1706
- }
1707
- }), /*#__PURE__*/jsx(FormControlLabel, {
1708
- control: /*#__PURE__*/jsx(Switch, {
1709
- label: "Show Estimate",
1710
- checked: showEstimate,
1711
- onChange: function onChange() {
1712
- return setShowEstimate(!showEstimate);
1713
- }
1714
- }),
1715
- label: "Show Estimate",
1716
- sx: {
1717
- justifyContent: "center"
1718
- }
1719
- })]
1720
- }), /*#__PURE__*/jsx(ShowEstimate, {
1721
- spec: spec,
1722
- estimatedBoiloff: estimatedBoiloff,
1723
- estimatedError: estimatedError
1724
- })]
1725
- });
1726
- }
1727
-
1728
- function HeliumGraph(_ref) {
1729
- var graphData = _ref.graphData,
1730
- graphDataMeta = _ref.graphDataMeta,
1731
- matches = _ref.matches;
1732
- var height = matches ? 250 : 200;
1733
- var width = matches ? 300 : 280;
1734
- var heliumLookupData = useContext(LookupContext);
1735
-
1736
- // remove spectrometers not existing in heliumLookupData
1737
-
1738
- Object.keys(graphData).forEach(function (spec) {
1739
- if (!heliumLookupData.boilOff[spec]) {
1740
- delete graphData[spec];
1741
- }
1742
- });
1743
-
1744
- // Catch missing data
1745
-
1746
- if (graphData.error) {
1747
- return /*#__PURE__*/jsxs(React.Fragment, {
1748
- children: [/*#__PURE__*/jsx(DivTitle, {
1749
- children: /*#__PURE__*/jsx("strong", {
1750
- children: "Helium level monitoring"
1751
- })
1752
- }), /*#__PURE__*/jsx(Grid, {
1753
- sx: {
1754
- display: "flex",
1755
- justifyContent: "center"
1756
- },
1757
- children: /*#__PURE__*/jsx("em", {
1758
- children: "No graph data available"
1759
- })
1760
- })]
1761
- });
1762
- }
1763
-
1764
- // Render component
1765
-
1766
- return /*#__PURE__*/jsxs(React.Fragment, {
1767
- children: [/*#__PURE__*/jsxs(DivTitle, {
1768
- children: [/*#__PURE__*/jsx("strong", {
1769
- children: "Helium level monitoring"
1770
- }), " ", /*#__PURE__*/jsxs("em", {
1771
- children: ["(updated ", moment(graphDataMeta.date).fromNow(), ")"]
1772
- })]
1773
- }), /*#__PURE__*/jsx(Grid, {
1774
- container: true,
1775
- sx: {
1776
- display: "flex",
1777
- justifyContent: "center"
1778
- },
1779
- children: Object.keys(graphData).map(function (spec) {
1780
- return /*#__PURE__*/jsxs(Paper, {
1781
- sx: {
1782
- display: "flex",
1783
- flexDirection: "column",
1784
- justifyItems: "center",
1785
- stroke: AppTheme.palette.divider,
1786
- px: 2,
1787
- paddingBottom: 2,
1788
- margin: 2
1789
- },
1790
- children: [/*#__PURE__*/jsx("h4", {
1791
- children: spec
1792
- }), /*#__PURE__*/jsx(RenderGraph, {
1793
- data: graphData[spec],
1794
- height: height,
1795
- width: width,
1796
- spec: spec
1797
- })]
1798
- }, "graph_" + spec);
1799
- })
1800
- })]
1801
- });
1802
- }
1803
-
1804
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1805
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1806
- var heliumLookupData = process.env.HELIUM_LOOKUP || {
1807
- lookup: {}
1808
- };
1809
- console.log("Helium Lookup Data:", heliumLookupData);
1810
-
1811
- // Site config
1812
- var site = process.env.SITE_CONFIG || {};
1813
- console.log("Site Config:", site);
1814
-
1815
- // Principal function
1816
-
1817
- function Helium(props) {
1818
- var basePath = site.basePath || props.basePath || "";
1819
-
1820
- // State
1821
-
1822
- var _useImmer = useImmer(null),
1823
- _useImmer2 = _slicedToArray(_useImmer, 2),
1824
- heliumData = _useImmer2[0],
1825
- SetHeliumData = _useImmer2[1];
1826
- var _useState = useState(false),
1827
- _useState2 = _slicedToArray(_useState, 2),
1828
- levelsEdited = _useState2[0],
1829
- SetLevelsEdited = _useState2[1];
1830
- var _useState3 = useState(false),
1831
- _useState4 = _slicedToArray(_useState3, 2),
1832
- preprocessed = _useState4[0],
1833
- SetPreprocessed = _useState4[1];
1834
- var _useState5 = useState(null),
1835
- _useState6 = _slicedToArray(_useState5, 2),
1836
- heliumError = _useState6[0],
1837
- SetHeliumError = _useState6[1];
1838
-
1839
- // Query Media size for responsive column wrapping
1840
-
1841
- var matches = useMediaQuery(AppTheme.breakpoints.up("lg"));
1842
- var maxHeight = matches ? props.maxHeight || 1280 : 1000000;
1843
- var cardSize = matches ? 6 : 12;
1844
- var collapsed = !matches;
1845
-
1846
- // fetch data
1847
-
1848
- var fetchGraph = site.showGraphs ? PublicFetch({
1849
- url: basePath + "/graphdata.json"
1850
- }) : {};
1851
- PublicFetch({
1852
- url: basePath + "/helium.json",
1853
- SetState: SetHeliumData,
1854
- SetError: SetHeliumError
1855
- });
1856
-
1857
- // Catch empty data
1858
-
1859
- useEffect(function () {
1860
- if (heliumError) {
1861
- SetHeliumData(function (heliumData) {
1862
- heliumData.helium = {};
1863
- });
1864
- Object.keys(heliumLookupData.lookup).map(function (spec) {
1865
- SetHeliumData(function (heliumData) {
1866
- heliumData.helium[spec] = 0;
1867
- });
1868
- });
1869
- SetHeliumData(function (heliumData) {
1870
- heliumData.meta = {};
1871
- heliumData.meta.date = 0;
1872
- });
1873
- SetPreprocessed(true);
1874
- }
1875
- }, [heliumError]);
1876
- useEffect(function () {
1877
- if (heliumData !== null && heliumError === null) {
1878
- Object.keys(heliumLookupData.lookup).map(function (spec) {
1879
- SetHeliumData(function (heliumData) {
1880
- heliumData.helium[spec] = Number(heliumData.helium[spec]);
1881
- });
1882
- });
1883
- SetPreprocessed(true);
1884
- }
1885
- }, [heliumData]);
1886
- if (!heliumData || !fetchGraph || !preprocessed) {
1887
- return /*#__PURE__*/jsx(Progress, {});
1888
- }
1889
- var graphDataMeta = fetchGraph.meta;
1890
- var graphData = _objectSpread({}, fetchGraph);
1891
- delete graphData.meta;
1892
- if (!graphDataMeta) {
1893
- graphDataMeta = {};
1894
- }
1895
- return /*#__PURE__*/jsx(AppGrid, {
1896
- children: /*#__PURE__*/jsxs(LookupContext.Provider, {
1897
- value: heliumLookupData,
1898
- children: [site.showGraphs ? /*#__PURE__*/jsx(AppCard, {
1899
- title: "Helium Graphs",
1900
- size: 12,
1901
- collapsed: collapsed,
1902
- children: /*#__PURE__*/jsx(HeliumGraph, {
1903
- graphData: graphData,
1904
- graphDataMeta: graphDataMeta,
1905
- matches: matches
1906
- })
1907
- }) : null, /*#__PURE__*/jsxs(Grid, {
1908
- sx: {
1909
- display: "flex",
1910
- flexFlow: "column wrap",
1911
- maxHeight: maxHeight
1912
- },
1913
- children: [/*#__PURE__*/jsxs(AppCard, {
1914
- title: "Helium Calculator",
1915
- size: cardSize,
1916
- collapsed: collapsed,
1917
- children: [/*#__PURE__*/jsx(Grid, {
1918
- children: /*#__PURE__*/jsxs(DivTitle, {
1919
- children: [/*#__PURE__*/jsx("strong", {
1920
- children: "Current levels"
1921
- }), " ", /*#__PURE__*/jsxs("em", {
1922
- children: [heliumData.meta.date || heliumData.meta.date !== 0 ? "(updated " + moment(heliumData.meta.date).fromNow() + ")" : "(manual)", /*#__PURE__*/jsx(EditAdmon, {
1923
- levelsEdited: levelsEdited
1924
- })]
1925
- })]
1926
- })
1927
- }), /*#__PURE__*/jsx(Grid, {
1928
- children: /*#__PURE__*/jsx(HeliumTable, {
1929
- heliumLookupData: heliumLookupData,
1930
- heliumData: heliumData,
1931
- SetHeliumData: SetHeliumData,
1932
- SetLevelsEdited: SetLevelsEdited
1933
- })
1934
- })]
1935
- }), /*#__PURE__*/jsx(AppCard, {
1936
- title: "Spectrometer Set",
1937
- size: cardSize,
1938
- collapsed: collapsed,
1939
- children: /*#__PURE__*/jsx(Grid, {
1940
- children: /*#__PURE__*/jsx(PairWizard, {
1941
- heliumData: heliumData
1942
- })
1943
- })
1944
- }), /*#__PURE__*/jsx(AppCard, {
1945
- title: "Estimated Consumption",
1946
- size: cardSize,
1947
- collapsed: collapsed,
1948
- children: /*#__PURE__*/jsx(Grid, {
1949
- children: /*#__PURE__*/jsx(EstimateConsumption, {})
1950
- })
1951
- }), /*#__PURE__*/jsx(AppCard, {
1952
- title: "Helium Estimation",
1953
- size: cardSize,
1954
- children: /*#__PURE__*/jsx(HePrognosis, {
1955
- heliumData: heliumData,
1956
- heliumLookupData: heliumLookupData
1957
- })
1958
- }), /*#__PURE__*/jsx(AppCard, {
1959
- title: "Fill Target",
1960
- size: cardSize,
1961
- children: /*#__PURE__*/jsx(FillTarget, {
1962
- heliumData: heliumData
1963
- })
1964
- })]
1965
- })]
1966
- })
1967
- });
1968
- }
1969
-
1970
- // Import and export all components
1971
-
1972
- export { Helium as default };
1
+ import e from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/helpers/slicedToArray";import t,{createContext as n,useContext as i,useState as l,useEffect as a}from"react";import{useImmer as o}from"use-immer";import c from"@mui/material/useMediaQuery";import u from"@mui/material/Grid";import{AppTheme as s,AppTable as m,TableHeadCell as d,DivTitle as h,AppCard as p,ErrorAlert as f,Percentage as b,SpecSwitch as v,PublicFetch as y,Progress as g,AppGrid as O}from"@zac-apps/commons";import x from"moment";import j from"@mui/material/Paper";import{LineChart as S,Line as k,CartesianGrid as D,XAxis as w,Label as P,YAxis as M,ReferenceLine as z,ReferenceArea as C,Tooltip as E}from"recharts";import L from"@mui/material/ButtonGroup";import N from"@mui/material/Button";import F from"@mui/material/FormGroup";import H from"@mui/material/FormControlLabel";import A from"@mui/material/Switch";import I from"@mui/material/TableHead";import Y from"@mui/material/TableCell";import T from"@mui/material/TableRow";import G from"@mui/material/TableBody";import{jsx as B,jsxs as _}from"react/jsx-runtime";import K from"regression";import{mean as J,sqrt as V,sum as q}from"mathjs";import W from"@mui/material/IconButton";import R from"@mui/icons-material/Save";import U from"@mui/icons-material/Edit";import Q from"@mui/material/TextField";import X from"@mui/material/InputAdornment";import Z from"moment/moment.js";import $ from"@mui/material/Divider";import ee from"@mui/material/Typography";import re from"@mui/material/FormControl";import te from"@mui/material/Checkbox";import ne from"@babel/runtime/helpers/toConsumableArray";import ie from"@mui/material/Chip";import le from"@mui/icons-material/AddBox";import ae from"@mui/icons-material/Delete";var oe=n(null);function ce(e){var r=e.spec,t=e.estimatedBoiloff,n=e.estimatedError,l=i(oe).heliumLookupData.boilOff[r].toFixed(3)||"N/A";t=t.toFixed(3)||"N/A",n=n.toFixed(3)||"N/A";var a=Math.abs(t-l)<.01?t:B("strong",{style:{color:s.palette.primary.main},children:t});return _("div",{children:[B("h4",{children:"Boiloff coefficients (%/day)"}),B(u,{container:!0,children:_(m,{children:[B(I,{children:_(T,{children:[B(d,{children:"Estimated"}),B(d,{children:"Stored"})]})}),B(G,{children:_(T,{children:[_(Y,{children:[a," ",_("em",{style:{color:s.palette.secondary.main},children:["(±",n,")"]})]}),B(Y,{children:l})]})})]})})]})}function ue(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function se(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ue(Object(n),!0).forEach(function(t){e(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):ue(Object(n)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))})}return r}function me(e){var n=e.data,a=e.height,o=e.width,c=e.spec,u=i(oe).heliumLookupData,m=function(e){var r=e.data;e.spec;for(var t,n,i=Number(r[r.length-1].level),l=r.length-1,a=r.length-1,o=Number(r[a].level),c=r.length-2;c>=0;c--){var u=Number(r[c].level);if(u>i&&(o=u,a=c),u<o)break}a>=r.length-45&&(l=a-1,i=Number(r[l].level));for(var s=l-1,m=Number(r[s].level),d=s,h=s-1;h>=0;h--){var p=Number(r[h].level);if(p>m&&(m=p,d=h),p<m-1||p>=90)break}for(var f=[],b=d;b<=s;b++)f.push([b,Number(r[b].level)]);var v=K.linear(f,{precision:6});t=v.equation[0],n=v.equation[1];for(var y=[],g=d;g<=s;g++)y.push([g,g*t+n]);var O=J(f.map(function(e){return e[0]})),x=V(1/(y.length-2)*q(f.map(function(e,r){return Math.pow(e[1]-y[r][1],2)}))/q(f.map(function(e,r){return Math.pow(e[0]-O,2)})));return{slope:t,intercept:n,slopeError:x}}(se({},{data:n,spec:c})),d=m.slope,h=m.intercept,p=m.slopeError,f=function(e){var r=e.active,t=e.payload,n=e.label;if(r&&t&&t.length){var i=x(t[0].payload.date,"ddd MMM D HH:mm:ss YYYY").format("LL");return _("div",{style:{border:"solid 1px "+s.palette.secondary.main,padding:"0.75em",backgroundColor:"#ffffffaa"},children:[B("strong",{children:i}),B("br",{}),_("em",{children:["(",n," days ago)"]}),B("br",{}),_("strong",{style:{color:s.palette.primary.main},children:[t[0].value," %"]})]})}};function b(e){var r=e.value;return B(N,{onClick:function(){return O(r)},color:r===g?"primary":"secondary",variant:r===g?"contained":"outlined",size:"small",children:r})}var v=l(90),y=r(v,2),g=y[0],O=y[1],j=l(!0),I=r(j,2),Y=I[0],T=I[1],G=l(!1),W=r(G,2),R=W[0],U=W[1],Q=(n||[]).map(function(e){return se(se({},e),{},{days:-x(e.date,"ddd MMM D HH:mm:ss YYYY").diff(x(),"days")})}),X=0;Q.length>0&&(X=x().diff(x(Q[Q.length-1].date,"ddd MMM D HH:mm:ss YYYY"),"days"));var Z=R?Q.map(function(e){var r=e.days,t=e.level,n=d*(Q.length-r+X)+h;return{date:e.date,days:r,level:t,estimate:n}}):Q,$=Z.slice(Math.max(Z.length-g,0)),ee=R?s.palette.grey[300]:s.palette.primary.main;return _(t.Fragment,{children:[_(S,{height:a,width:o,data:$,margin:{top:5,right:20,bottom:25,left:0},children:[B(k,{dataKey:"level",stroke:ee,fill:ee,type:"linear",dot:{r:1.5}}),R?B(k,{dataKey:"estimate",stroke:s.palette.action.main,type:"monotone",strokeDasharray:"5 5",strokeWidth:2,dot:!1}):null,B(D,{stroke:s.palette.divider,strokeDasharray:"5 5"}),B(w,{dataKey:"days",interval:g<15?1:Math.round(g/3),children:B(P,{value:"Days ago",offset:1,position:"bottom"})}),B(M,{dataKey:"level",unit:"%",type:"number",domain:[0,100]}),Y?_(t.Fragment,{children:[B(z,{y:u.minima[c],stroke:s.palette.secondary.main,strokeDasharray:3}),B(C,{y1:u.minima[c],y2:0,stroke:"none",stro:!0,fill:s.palette.secondary.main,fillOpacity:.1})]}):null,B(E,{content:B(f,{})})]}),_(L,{disableElevation:!0,variant:"outlined",fullWidth:!0,color:"secondary","aria-label":"contained primary button group",sx:{justifySelf:"center",px:5},size:"small",children:[B(b,{value:7}),B(b,{value:30}),B(b,{value:90}),B(b,{value:180}),B(b,{value:365})]}),_(F,{children:[B(H,{control:B(A,{label:"Show Minimum",checked:Y,onChange:function(){return T(!Y)}}),label:"Show Minimum",sx:{justifyContent:"center"}}),B(H,{control:B(A,{label:"Show Estimate",checked:R,onChange:function(){return U(!R)}}),label:"Show Estimate",sx:{justifyContent:"center"}})]}),B(ce,{spec:c,estimatedBoiloff:d,estimatedError:p})]})}function de(e){var r=e.graphData,n=e.graphDataMeta,l=e.matches,a=l?250:200,o=l?300:280,c=i(oe).heliumLookupData;return Object.keys(r).forEach(function(e){c.boilOff[e]||delete r[e]}),r.error?_(t.Fragment,{children:[B(h,{children:B("strong",{children:"Helium level monitoring"})}),B(u,{sx:{display:"flex",justifyContent:"center"},children:B("em",{children:"No graph data available"})})]}):_(t.Fragment,{children:[_(h,{children:[B("strong",{children:"Helium level monitoring"})," ",_("em",{children:["(updated ",x(n.date).fromNow(),")"]})]}),B(u,{container:!0,sx:{display:"flex",justifyContent:"center"},children:Object.keys(r).map(function(e){return _(j,{sx:{display:"flex",flexDirection:"column",justifyItems:"center",stroke:s.palette.divider,px:2,paddingBottom:2,margin:2},children:[B("h4",{children:e}),B(me,{data:r[e],height:a,width:o,spec:e})]},"graph_"+e)})})]})}function he(e){var r=e.graphData,t=e.graphDataMeta,n=i(oe),l=n.collapsed,a=n.matches;return B(p,{title:"Helium Graphs",size:12,collapsed:l,children:B(de,{graphData:r,graphDataMeta:t,matches:a})})}function pe(e){var n=e.input,i=e.SetInput,a=e.error,o=e.SetError,c=e.minValue,u=e.maxValue,s=e.adornment,m=e.size,d=l(""),h=r(d,2),p=h[0],b=h[1],v=l(!1),y=r(v,2),g=y[0],O=y[1],x={};return"small"===m&&(x={maxWidth:75}),_(t.Fragment,{children:[B(Q,{size:"small",sx:x,onChange:function(e){return function(e){var r=!1,t=e.target.value;t.match(/[0-9-]*/)[0]&&t.match(/[0-9-]*/)[0]===t||(r=!0,b("Input is not numerical.")),(t>u||t<c)&&(r=!0,b("Input is outside allowed boundaries.")),i(t),o(r),O(r)}(e)},value:n,error:a,inputProps:{inputMode:"numeric"},InputProps:{endAdornment:B(X,{position:"end",children:s})}}),B(f,{alert:g,SetAlert:O,message:p})]})}function fe(e){var r=e.spec,t=e.value,n=i(oe).heliumLookupData.lookup;return t=t<0||!t?0:Number(t),n[r].find(function(e){return e.level===t}).liters}function be(e){var r=e.spec,t=e.value,n=i(oe).heliumLookupData.lookup;((t=Number(t)||0)<0||!t)&&(t=0);var l=Math.max.apply(null,n[r].map(function(e){return e.liters}))-n[r].find(function(e){return e.level===t}).liters;return l=Math.round(10*l)/10}function ve(e){var t=e.spec,n=i(oe),a=n.heliumLookupData.lookup,o=n.heliumData,c=n.SetHeliumData,u=n.SetLevelsEdited,s=Number(o.helium[t])||0,m=Math.max.apply(null,a[t].map(function(e){return e.level})),d=l(!1),h=r(d,2),p=h[0],f=h[1],v=l(s),y=r(v,2),g=y[0],O=y[1],x=l(!1),j=r(x,2),S=j[0],k=j[1];return _(Y,p?{children:[B(pe,{input:g,SetInput:O,error:S,SetError:k,minValue:0,maxValue:m,adornment:"%",size:"small"}),B(W,{disabled:S,onClick:function(){c(function(e){e.helium[t]=Number(g)}),f(!p),u(!0)},children:B(R,{})})]}:{children:[b(s,!0),B(W,{size:"small",onClick:function(){return f(!p)},children:B(U,{})})]})}function ye(){var e=i(oe),r=e.heliumData;if(e.SetHeliumData,e.SetLevelsEdited,0===r.helium.length)return B(u,{children:B("em",{children:"No Helium data found."})});var t=Object.keys(r.helium).reduce(function(e,t){return e+be({spec:t,value:r.helium[t]})},0);return t=Math.round(10*t)/10,_(m,{children:[B(I,{children:_(T,{children:[B(d,{children:"Spectrometer"}),_(d,{children:["Helium level",B("br",{}),"[%]"]}),_(d,{children:["Helium level",B("br",{}),"[liters]"]}),_(d,{children:["Diff. to maximum",B("br",{}),"[liters]"]})]})}),B(G,{children:Object.keys(r.helium).map(function(e){return _(T,{children:[B(Y,{children:e}),B(ve,{spec:e}),B(Y,{children:B(fe,{spec:e,value:r.helium[e]})}),B(Y,{children:B("strong",{children:B(be,{spec:e,value:r.helium[e]})})})]},e+"_entry")})}),B("tfoot",{children:_(T,{children:[B(Y,{children:B("strong",{children:"Sum"})}),B(Y,{}),B(Y,{}),B(Y,{children:B("strong",{children:t})})]})})]})}function ge(){return i(oe).levelsEdited?_(t.Fragment,{children:[", ",B("strong",{children:"edited"})]}):null}function Oe(){var e=i(oe),r=e.heliumData;return e.levelsEdited,_(p,{title:"Helium Calculator",size:e.cardSize,collapsed:e.collapsed,sx:{mb:e.bottomMargin},children:[B(u,{children:_(h,{children:[B("strong",{children:"Current levels"})," ",_("em",{children:[r.meta.date||0!==r.meta.date?"(updated "+x(r.meta.date).fromNow()+")":"(manual)",B(ge,{})]})]})}),B(u,{children:B(ye,{})})]})}function xe(e){var n=e.limit,i=e.SetLimit,a=e.error,o=e.SetError,c=l(n),u=r(c,2),s=u[0],m=u[1],d=l(!1),h=r(d,2),p=h[0],f=h[1];return _(t.Fragment,p?{children:[B(pe,{input:s,SetInput:m,error:a,SetError:o,size:"medium",adornment:"L"})," ",B(W,{disabled:a,size:"small",onClick:function(){f(!p),i(Number(s))},children:B(R,{})})]}:{children:[n," L"," ",B(W,{size:"small",onClick:function(){return f(!p)},children:B(U,{})})]})}function je(e){var r=e.specs,t=e.SetSpecs;function n(e){t(function(r){Object.keys(r).map(function(t){return r[t]=e})})}return _(re,{children:[B($,{textAlign:"left",children:B("strong",{children:"Select spectrometers"})}),_(F,{row:!0,sx:{px:2},children:[Object.keys(r).map(function(e){return B(H,{control:B(te,{size:"small"}),checked:r[e],onChange:function(){return t(function(r){r[e]=!r[e]})},label:e},e+"_check")})," ",B(N,{size:"small",onClick:function(){return n(!0)},children:"all"})," "," "," ",B(N,{size:"small",onClick:function(){return n(!1)},children:"none"})]})]})}function Se(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function ke(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Se(Object(n),!0).forEach(function(t){e(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):Se(Object(n)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))})}return r}function De(e){var r=e.children,t=e.title;return B(u,{children:_(m,{children:[B(I,{children:B(T,{children:B(d,{children:t})})}),B(G,{children:B(T,{children:B(Y,{children:r})})})]})})}function we(e){var r=e.minPair;if(0!==r.length){var t=new Date;t.setDate(t.getDate()+r[2]);var n=Z(t).format("ll");return _(De,{title:"Pair",children:[B("strong",{children:r[0]})," and ",B("strong",{children:r[1]})," ","in ",_("strong",{children:[r[2]," days"]})," (",n,")"]})}return B(De,{title:"Pair",children:B("em",{children:"No spectrometer pair reaches the target value."})})}function Pe(e){var r=e.minTriple;if(0!==r.length){var t=new Date;t.setDate(t.getDate()+r[3]);var n=Z(t).format("ll");return _(De,{title:"Triple",children:[B("strong",{children:r[0]}),", ",B("strong",{children:r[1]}),", and ",B("strong",{children:r[2]})," in"," ",_("strong",{children:[r[3]," days"]})," (",n,")"]})}return B(De,{title:"Triple",children:B("p",{children:B("em",{children:"No spectrometer triple reaches the target value."})})})}function Me(){var n=i(oe),a=n.heliumLookupData,c=n.heliumData,s=a.boilOff,m={};Object.keys(s).map(function(r){return m=ke(ke({},m),{},e({},r,!0))});var d=o(m),h=r(d,2),p=h[0],f=h[1],b=Object.keys(p).filter(function(e){return p[e]}),v=l(!1),y=r(v,2),g=y[0],O=y[1],x=l(100),j=r(x,2),S=j[0],k=j[1],D=function(e){var r=e.currSpecs,t=e.heliumData,n=e.boilOff,i=e.limit,l=[];r.map(function(e){r.map(function(r){e!==r&&l.push([e,r].sort())})}),l=Array.from(new Set(l.map(JSON.stringify)),JSON.parse);var a=[],o=function(){var e=1,r=0;a.push(l[c]);do{r=l[c].reduce(function(r,i){var l=Math.round(t.helium[i]+e*n[i]);return l<0&&(l=0),r+be({value:l,spec:i})},0),e++}while(r<i&&e<300);a[c].push(e),a[c].push(r),a[c].push(r>i)};for(var c in l)o();var u=[];switch((a=a.filter(function(e){return e[4]})).length){case 0:u=[];break;case 1:u=ne(a);break;default:u=a.reduce(function(e,r){return r[2]<e[2]?r:e})}return u.flat()}(ke({},{currSpecs:b,heliumData:c,boilOff:s,limit:S})),w=function(e){var r=e.currSpecs,t=e.heliumData,n=e.boilOff,i=e.limit,l=[];r.map(function(e){r.map(function(t){r.map(function(r){e!==t&&t!==r&&r!==e&&l.push([e,t,r].sort())})})}),l=Array.from(new Set(l.map(JSON.stringify)),JSON.parse);var a=[],o=function(){var e=1,r=0;a.push(l[c]);do{r=l[c].reduce(function(r,i){var l=Math.round(t.helium[i]+e*n[i]);return l<0&&(l=0),r+be({value:l,spec:i})},0),e++}while(r<i&&e<300);a[c].push(e),a[c].push(r),a[c].push(r>i)};for(var c in l)o();var u=[];switch((a=a.filter(function(e){return e[5]})).length){case 0:u=[];break;case 1:u=ne(a);break;default:u=a.reduce(function(e,r){return r[3]<e[3]?r:e})}return u.flat()}(ke({},{currSpecs:b,heliumData:c,boilOff:s,limit:S}));return B(t.Fragment,{children:_(u,{container:!0,columns:{xs:6,md:12},children:[_(u,{sx:{px:2},size:6,children:[B($,{textAlign:"left",children:B("strong",{children:"Find earliest set of spectrometers requiring"})}),B(u,{sx:{padding:2,display:"flex",justifyContent:"center"},children:B(ee,{variant:"h4",children:B(xe,{limit:S,SetLimit:k,error:g,SetError:O})})}),B(u,{children:B(je,{specs:p,SetSpecs:f})})]}),_(u,{sx:{px:2},size:6,children:[B($,{textAlign:"left",children:B("strong",{children:"Result"})}),_(u,{sx:{px:3},children:[B(we,{minPair:D}),B(Pe,{minTriple:w})]})]})]})})}function ze(){var e=i(oe);return B(p,{title:"Spectrometer Set",size:e.cardSize,collapsed:e.collapsed,sx:{mb:e.bottomMargin},children:B(u,{children:B(Me,{})})})}function Ce(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function Ee(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ce(Object(n),!0).forEach(function(t){e(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):Ce(Object(n)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))})}return r}function Le(){var e=i(oe).heliumLookupData,r=e.boilOff,n=e.lookup,l=[];return Object.keys(n).map(function(e){return l.push({name:e,liters:(n[e].filter(function(e){return 100===e.level})[0].liters-n[e].filter(function(e){return 50===e.level})[0].liters).toFixed(1),days:(-50/r[e]).toFixed(1)})}),l=l.map(function(e){return Ee(Ee({},e),{},{perDay:e.liters/e.days,perMonth:(e.liters/e.days*30).toFixed(1),perYear:(e.liters/e.days*365).toFixed(1)})}),_(t.Fragment,{children:[B("p",{children:"Helium consumption estimated based on lookup values."}),_(m,{children:[B(I,{children:_(T,{children:[B(d,{}),l.map(function(e){return B(d,{children:e.name},"Head"+e.name)}),B(d,{children:"Sum"})]})}),_(G,{children:[_(T,{children:[B(Y,{children:"per month"}),l.map(function(e){return _(Y,{children:[e.perMonth," L ",B("br",{}),"(",(.79*e.perMonth).toFixed(2)," m",B("sup",{children:"3"})," Gas)"]},"perMonth"+e.name)}),B(Y,{children:_("strong",{children:[l.reduce(function(e,r){return e+Number(r.perMonth)},0).toFixed(1)," ","L",B("br",{}),"(",(.79*l.reduce(function(e,r){return e+Number(r.perMonth)},0)).toFixed(2)," ","m",B("sup",{children:"3"})," Gas)"]})})]}),_(T,{children:[B(Y,{rowSpan:2,children:"per year"}),l.map(function(e){return _(Y,{children:[e.perYear," L ",B("br",{}),"(",(.79*e.perYear).toFixed(2)," m",B("sup",{children:"3"})," ","Gas)"]},"perYear"+e.name)}),B(Y,{children:_("strong",{children:[l.reduce(function(e,r){return e+Number(r.perYear)},0).toFixed(1)," ","L",B("br",{}),"(",(.79*l.reduce(function(e,r){return e+Number(r.perYear)},0)).toFixed(2)," ","m",B("sup",{children:"3"})," Gas)"]})})]})]})]})]})}function Ne(){var e=i(oe),r=e.cardSize,t=e.collapsed;return B(p,{title:"Estimated Consumption",size:r,collapsed:t,sx:{mb:e.bottomMargin},children:B(u,{children:B(Le,{})})})}function Fe(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function He(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Fe(Object(n),!0).forEach(function(t){e(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):Fe(Object(n)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))})}return r}var Ae=s.palette.primary.main,Ie=s.palette.primary.contrastText,Ye=s.palette.warning.main;function Te(e){var r=e.value,t=e.days,n=e.spec,l=i(oe).heliumLookupData,a=l.boilOff,o=l.minima,c=Math.round(r+t*a[n]);c<0&&(c=0);var u=fe({value:c,spec:n}),s=be({value:c,spec:n}),m={};return c<o[n]-30*a[n]?m={backgroundColor:Ae,color:Ie}:c<o[n]-60*a[n]&&(m={color:Ye}),_(Y,{sx:m,children:[b(c,!0)," ",B("br",{}),u," L",B("br",{}),_("strong",{children:[s," L"]})]})}function Ge(r){var t=r.currHeliumData,n=r.days,l=i(oe).heliumLookupData.boilOff,a={};Object.keys(t).map(function(r){return a=He(He({},a),{},e({},r,Math.round(t[r]+n*l[r]))),null});var o=Object.keys(a).reduce(function(e,r){return e+be({spec:r,value:a[r]})},0);return o=Math.round(10*o)/10,B(Y,{children:_("strong",{children:[o," L"]})})}function Be(e){var t=e.days,n=e.increments,i=e.SetIncrements,a=e.dates,o=l(!1),c=r(o,2),u=c[0],s=c[1],m=l(t),d=r(m,2),h=d[0],p=d[1],f=l(!1),b=r(f,2),v=b[0],y=b[1];return _(Y,u?{children:[a[t]," ",B("br",{}),B(pe,{input:h,SetInput:p,error:v,SetError:y,size:"small"}),B("br",{}),B(W,{disabled:v,size:"small",onClick:function(){s(!u),i(n.map(function(e){return e===t?Number(h):e}))},children:B(R,{})}),B(W,{size:"small",onClick:function(){return i(n.filter(function(e){return e!==t}))},children:B(ae,{})})]}:{children:[a[t]," ",B("br",{})," in ",t," days ",B("br",{}),B(W,{size:"small",onClick:function(){return s(!u)},children:B(U,{})}),B(W,{size:"small",onClick:function(){return i(n.filter(function(e){return e!==t}))},children:B(ae,{})})]})}function _e(e){var r=e.increments,n=e.SetIncrements,i=e.currHeliumData,l=e.dates;return B(t.Fragment,{children:r.map(function(e){return _(T,{children:[B(Be,{days:e,increments:r,SetIncrements:n,dates:l}),Object.keys(i).map(function(r){return B(Te,{value:i[r],days:e,spec:r},r+"_progentry")}),B(Ge,{currHeliumData:i,days:e})]},e+"_incr")})})}function Ke(e){var n=e.increments,i=e.SetIncrements,a=l(""),o=r(a,2),c=o[0],s=o[1],m=l(!1),d=r(m,2),h=d[0],p=d[1];return _(t.Fragment,{children:[B($,{textAlign:"left",children:B("strong",{children:"Add prediction row"})}),_(u,{children:[B(pe,{input:c,SetInput:s,error:h,SetError:p,adornment:"days",size:"medium"}),B(W,{disabled:h,onClick:function(){i([Number(c)].concat(ne(n)))},children:B(le,{})})]})]})}function Je(){var t=i(oe),n=t.heliumLookupData,a=t.heliumData,c=n.minima,s={};Object.keys(a.helium).map(function(r){return s=He(He({},s),{},e({},r,!0))});var h=o(s),p=r(h,2),f=p[0],b=p[1],v=l([14,30,60,90]),y=r(v,2),g=y[0],O=y[1],j={};Object.keys(f).filter(function(e){return f[e]}).map(function(r){return j=He(He({},j),{},e({},r,a.helium[r]))});var S={};for(var k in g){var D=new Date;D.setDate(D.getDate()+g[k]),S=He(He({},S),{},e({},g[k],x(D).format("ll")))}return _(u,{container:!0,columns:{xs:6,sm:12},children:[B(u,{size:6,children:B(je,{specs:f,SetSpecs:b})}),B(u,{size:6,children:B(Ke,{increments:g,SetIncrements:O})}),B(u,{size:12,children:_(m,{children:[_(I,{children:[_(T,{children:[B(d,{}),Object.keys(j).map(function(e){return _(d,{children:[e,B("br",{}),"(",c[e]," %)"]},e+"_th")}),B(d,{children:"Sum"})]}),_(T,{children:[B(d,{}),B(d,{align:"center",colSpan:Object.keys(f).length+1,children:B("em",{children:"[%], Liters, L. to max"})})]})]}),B(G,{children:B(_e,{increments:g,SetIncrements:O,dates:S,currHeliumData:j})})]})}),_(u,{sx:{display:"flex",justifyContent:"center",alignItems:"center",pt:2},size:12,children:[B(ie,{sx:{backgroundColor:Ae,color:Ie,mx:1},label:"Minimum in less than 30 days"}),B(ie,{sx:{color:Ye,mx:1},variant:"outlined",label:"Minimum in less than 60 days"})]})]})}function Ve(){var e=i(oe);return B(p,{title:"Helium Estimation",size:e.cardSize,sx:{mb:e.bottomMargin},children:B(Je,{})})}function qe(){var e=i(oe),n=e.heliumLookupData,a=e.heliumData,o=n.boilOff,c=n.lookup,m=l(!1),d=r(m,2),h=d[0],p=d[1],f=l(25),b=r(f,2),y=b[0],g=b[1],O=l(Object.keys(c)[0]),x=r(O,2),j=x[0],S=x[1],k=a.helium[j],D=fe({value:k,spec:j}),w=function(e){var r=e.spec,t=e.value,n=i(oe).heliumLookupData.lookup,l=0;if((t=t<0||!t?0:Number(t))>n[r].find(function(e){return 100===e.level}).liters)l=100;else{var a=n[r].reduce(function(e,r){return Math.abs(r.liters-t)<Math.abs(e.liters-t)?r:e}).liters;l=n[r].find(function(e){return e.liters===a}).level}return l}({value:D+y,spec:j});return B(t.Fragment,{children:_(u,{container:!0,columns:{xs:6,md:12},children:[_(u,{sx:{px:2},size:6,children:[B($,{textAlign:"left",children:B("strong",{children:"Select Spectrometer"})}),B(u,{sx:{padding:2,display:"flex",justifyContent:"center"},children:B(v,{setup:o,spec:j,SetSpec:S})})]}),_(u,{sx:{px:2},size:6,children:[B($,{textAlign:"left",children:B("strong",{children:"Current status"})}),B(u,{sx:{padding:2,display:"flex",justifyContent:"center"},children:_(ee,{variant:"h4",children:[k," % (",D," L)"]})})]}),_(u,{sx:{px:2},size:6,children:[B($,{textAlign:"left",children:B("strong",{children:"Helium fill amount"})}),B(u,{sx:{padding:2,display:"flex",justifyContent:"center"},children:B(ee,{variant:"h4",children:B(xe,{error:h,SetError:p,limit:y,SetLimit:g})})})]}),_(u,{sx:{px:2},size:6,children:[B($,{textAlign:"left",children:B("strong",{children:"After filling"})}),B(u,{sx:{padding:2,display:"flex",justifyContent:"center"},children:B(ee,{variant:"h4",children:_("em",{style:{color:s.palette.warning.main},children:["~ ",w," % (",fe({value:w,spec:j})," L)"]})})})]})]})})}function We(){var e=i(oe);return B(p,{title:"Fill Target",size:e.cardSize,sx:{mb:e.bottomMargin},children:B(qe,{})})}function Re(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}var Ue=process.env.HELIUM_LOOKUP||{lookup:{}};console.log("Helium Lookup Data:",Ue);var Qe=process.env.SITE_CONFIG||{};function Xe(t){var n=Qe.basePath||t.basePath||"",i=o(null),m=r(i,2),d=m[0],h=m[1],p=l(!1),f=r(p,2),b=f[0],v=f[1],x=l(!1),j=r(x,2),S=j[0],k=j[1],D=l(null),w=r(D,2),P=w[0],M=w[1],z=c(s.breakpoints.up("lg")),C=z?t.maxHeight||1280:1e6,E=z?6:12,L=!z,N=Qe.showGraphs?y({url:n+"/graphdata.json"}):{};if(y({url:n+"/helium.json",SetState:h,SetError:M}),a(function(){P&&(h(function(e){e.helium={}}),Object.keys(Ue.lookup).map(function(e){h(function(r){r.helium[e]=0})}),h(function(e){e.meta={},e.meta.date=0}),k(!0))},[P]),a(function(){null!==d&&null===P&&(Object.keys(Ue.lookup).map(function(e){h(function(r){r.helium[e]=Number(r.helium[e])})}),k(!0))},[d]),!d||!N||!S)return B(g,{});var F=N.meta,H=function(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Re(Object(n),!0).forEach(function(t){e(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):Re(Object(n)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))})}return r}({},N);delete H.meta,F||(F={});var A={heliumData:d,SetHeliumData:h,levelsEdited:b,SetLevelsEdited:v,heliumLookupData:Ue,cardSize:E,collapsed:L,matches:z,bottomMargin:1};return B(O,{children:_(oe.Provider,{value:A,children:[Qe.showGraphs?B(he,{graphData:H,graphDataMeta:F}):null,_(u,{sx:{display:"flex",flexFlow:"column wrap",maxHeight:C},children:[B(Oe,{}),B(ze,{}),B(Ne,{}),B(Ve,{}),B(We,{})]})]})})}console.log("Site Config:",Qe);export{Xe as default};