Skip to content

Commit

Permalink
Fix: convert salinity and relativeHumidity in VDM from percentage val…
Browse files Browse the repository at this point in the history
…ues to ratio (#254)
  • Loading branch information
panaaj committed May 10, 2024
1 parent e19cf0b commit 542c4ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions hooks/VDM.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const knotsToMs = (v) =>
const degToRad = (v) => utils.transform(v, 'deg', 'rad')
const cToK = (v) => parseFloat(utils.transform(v, 'c', 'k').toFixed(2))
const nmToM = (v) => parseFloat(utils.transform(v, 'nm', 'm').toFixed(2))
const percentToRatio = (v) => v / 100

const stateMapping = {
0: 'motoring',
Expand Down Expand Up @@ -326,7 +327,7 @@ module.exports = function (input, session) {
['winddir', 'wind.directionTrue', degToRad],
['windgustdir', 'wind.gustDirectionTrue', degToRad],
['airtemp', 'outside.temperature', cToK],
['relhumid', 'outside.relativeHumidity', (v) => v],
['relhumid', 'outside.relativeHumidity', percentToRatio],
['dewpoint', 'outside.dewPointTemperature', cToK],
['airpress', 'outside.pressure', (v) => v * 100],
['waterlevel', 'water.level', (v) => v],
Expand All @@ -337,7 +338,7 @@ module.exports = function (input, session) {
['swellperiod', 'water.swell.period', (v) => v],
['swelldir', 'water.swell.directionTrue', degToRad],
['watertemp', 'water.temperature', cToK],
['salinity', 'water.salinity', (v) => v],
['salinity', 'water.salinity', percentToRatio],
['surfcurrspd', 'water.current.drift', knotsToMs],
['surfcurrdir', 'water.current.set', degToRad],
].forEach(([propName, path, f]) => {
Expand Down
6 changes: 4 additions & 2 deletions test/VDM.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,12 @@ describe('VDM', function () {
)
delta.context.should.equal('meteo.urn:mrn:imo:mmsi:002655619:366097')
const currentYear = new Date().getFullYear();
const currentMonth = ('00' + (new Date().getMonth()+1)).slice(-2);
const output = [
['environment.water.level', -0.17],
['environment.water.levelTendency', 'steady'],
['environment.water.levelTendencyValue', 0],
['environment.date', currentYear + '-02-22T15:42:00.000Z']
['environment.date', `${currentYear}-${currentMonth}-22T15:42:00.000Z`]
]
output.forEach(([path, value]) =>
delta.updates[0].values
Expand All @@ -270,14 +271,15 @@ describe('VDM', function () {
delta.updates[0].values[3].value.longitude.should.equal(11.7283)
delta.updates[0].values[3].value.latitude.should.equal(57.9669)
const currentYear = new Date().getFullYear()
const currentMonth = ('00' + (new Date().getMonth()+1)).slice(-2);
const output = [
['sensors.ais.designatedAreaCode', 1],
['sensors.ais.functionalId', 31],
['environment.wind.averageSpeed', 9.26],
['environment.wind.gust', 11.32],
['environment.wind.directionTrue', 4.817108736604238],
['environment.wind.gustDirectionTrue', 4.817108736604238],
['environment.date', currentYear + '-02-20T14:47:00.000Z'],
['environment.date', `${currentYear}-${currentMonth}-20T14:47:00.000Z`],
]
output.forEach(([path, value]) =>
delta.updates[0].values
Expand Down

0 comments on commit 542c4ea

Please sign in to comment.