-
Notifications
You must be signed in to change notification settings - Fork 29
/
utils.js
62 lines (57 loc) · 1.32 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function chooseField (n2k, field1, field2) {
let res =
typeof n2k.fields[field1] === 'undefined'
? n2k.fields[field2]
: n2k.fields[field1]
// console.log(`chooseField ${typeof n2k.fields[field1]} '${field1}' '${field2}' ${res} ${JSON.stringify(n2k.fields)}`)
return res
}
function skEngineId (n2k) {
let id = chooseField(n2k, 'Engine Instance', 'Instance')
if (typeof id === 'number') {
return id
} else {
return id === 'Single Engine or Dual Engine Port' ? 'port' : 'starboard'
}
}
function skEngineTitle (n2k) {
var engine = skEngineId(n2k)
if (typeof engine === 'number') {
return engine
} else {
return engine.charAt(0).toUpperCase() + engine.slice(1)
}
}
function acPhase (n2k) {
const line = n2k.fields['Line']
if (!line) {
return 'A'
} else {
switch (line) {
case 'Line 1':
return 'A'
case 'Line 2':
return 'B'
case 'Line 3':
return 'C'
default:
return 'A'
}
}
}
function timeToSeconds (time) {
if (typeof time !== 'undefined' && time !== null) {
let split = time.split(':')
if (split.length === 3) {
return Number(split[0]) * 3600 + Number(split[1]) * 60 + Number(split[2])
}
}
return null
}
module.exports = {
chooseField,
skEngineId,
skEngineTitle,
acPhase,
timeToSeconds
}