-
Notifications
You must be signed in to change notification settings - Fork 1
/
findData.js
61 lines (58 loc) · 1.58 KB
/
findData.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
var getKeyByName = function(content, name) {
for (var key in content) {
if (content[key].friendlyName === name) {
return key;
}
}
};
var getKeys = function(content, check) {
var keys = [];
for (var key in content) {
if (typeof check === 'object') {
if (content[key][check.item] === check.match) {
keys.push(key);
}
} else {
keys.push(key);
}
}
return keys;
};
var getSignals = function(source, dishKey, spacecraftKey) {
var signals = [];
var idx = 0;
source.map(function(val) {
if (val.spacecraft === spacecraftKey) {
signals[idx] = val;
idx++;
}
});
return signals;
};
module.exports = {
// Return a list of site keys
siteList: function(content) {
return getKeys(content.site);
},
// Return a list of dish keys for a site
siteDishes: function(content, siteKey) {
var check = { item: 'site', match: siteKey };
return getKeys(content.dish, check);
},
// Return an arrat of friendly target names belonging to a dish
dishTargets: function(content, dishKey) {
var source = content.dish[dishKey].target;
return getKeys(source);
},
getSpacecraft: function(content, spacecraftKey) {
return content.spacecraft[spacecraftKey.toLowerCase()];
},
getDownSignals: function(content, dishKey, spacecraftKey) {
var source = content.dish[dishKey].downSignal;
return getSignals(source, dishKey, spacecraftKey);
},
getUpSignals: function(content, dishKey, spacecraftKey) {
var source = content.dish[dishKey].upSignal;
return getSignals(source, dishKey, spacecraftKey);
},
};