Skip to content

Commit

Permalink
fix percent to ratio (0-100 -> 0-1) (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
e-sailing authored and tkurki committed Aug 5, 2017
1 parent da9f201 commit 309a77b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 4 additions & 1 deletion pgns/127505.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module.exports = [
'.currentLevel'
)
},
source: 'Level'
value: function (n2k) {
var ratio100 = Number(n2k.fields['Level'])
return ratio100 / 100
}
},
{
node: function (n2k) {
Expand Down
8 changes: 7 additions & 1 deletion pgns/130311.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ module.exports = [
'.humidity'
)
},
source: 'Humidity'
filter: function (n2k) {
return typeof n2k.fields['Humidity'] !== 'undefined'
},
value: function (n2k) {
var ratio100 = Number(n2k.fields['Humidity'])
return ratio100 / 100
}
},
{
node: 'environment.outside.pressure',
Expand Down
12 changes: 6 additions & 6 deletions test/127505_fluid_level.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('127505 fuel', function () {
'{"timestamp":"2015-01-15-16:15:30.984Z","prio":"6","src":"17","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Fuel","Level":"131.068"}}'
)
)
tree.should.have.nested.property('tanks.fuel.0.currentLevel.value', 131.068)
tree.should.have.nested.property('tanks.fuel.0.currentLevel.value', 1.31068)
tree.should.be.validSignalKVesselIgnoringIdentity
})
it('level and capacity', function () {
Expand All @@ -19,7 +19,7 @@ describe('127505 fuel', function () {
'{"timestamp":"2015-01-15-16:15:33.341Z","prio":"6","src":"112","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"1","Type":"Fuel","Level":"64.284","Capacity":"41.6"}}'
)
)
tree.should.have.nested.property('tanks.fuel.1.currentLevel.value', 64.284)
tree.tanks.fuel['1'].currentLevel.value.should.be.closeTo(0.64284, 0.000005)
tree.should.have.nested.property('tanks.fuel.1.capacity.value', 41.6)
tree.should.be.validSignalKVesselIgnoringIdentity
})
Expand All @@ -32,9 +32,9 @@ describe('127505 water', function () {
'{"timestamp":"2015-01-15-16:15:33.366Z","prio":"6","src":"114","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Water","Level":"88.596","Capacity":"71.9"}}'
)
)
tree.should.have.nested.property(
'tanks.freshWater.0.currentLevel.value',
88.596
tree.tanks.freshWater['0'].currentLevel.value.should.be.closeTo(
0.88596,
0.000005
)
tree.should.have.nested.property('tanks.freshWater.0.capacity.value', 71.9)
tree.should.be.validSignalKVesselIgnoringIdentity
Expand All @@ -50,7 +50,7 @@ describe('127505 grayWater', function () {
)
tree.should.have.nested.property(
'tanks.wasteWater.0.currentLevel.value',
90.24
0.9024
)
tree.should.have.nested.property('tanks.wasteWater.0.capacity.value', 37.9)
tree.should.be.validSignalKVesselIgnoringIdentity
Expand Down

0 comments on commit 309a77b

Please sign in to comment.