Skip to content

Commit

Permalink
chore: use prettier-standard to format code
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 committed Aug 27, 2018
1 parent 52d328c commit 9318f3d
Show file tree
Hide file tree
Showing 20 changed files with 431 additions and 303 deletions.
26 changes: 14 additions & 12 deletions calcs/airDensity.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@

module.exports = function(app, plugin) {
module.exports = function (app, plugin) {
return {
group: 'air',
optionKey: 'Air density',
title: "Outside air density (based on humidity, temperature and pressure)",
derivedFrom: [ "environment.outside.temperature", "environment.outside.humidity", "environment.outside.pressure" ],
calculator: function(temp, hum, press) {
title: 'Outside air density (based on humidity, temperature and pressure)',
derivedFrom: [
'environment.outside.temperature',
'environment.outside.humidity',
'environment.outside.pressure'
],
calculator: function (temp, hum, press) {
var tempC = temp + 273.16
var psat = 6.1078 * 10^(7.5 * tempC / (tempC + 237.3)) //hPa
var pv = hum * psat/100 //vapour pressure of water
var pd = press - pv //dry air pressure
var airDensity = (pd/(287.058*temp)) + (pv/(461.495*temp))//https://en.wikipedia.org/wiki/Density_of_air#cite_note-wahiduddin_01-15

var psat = (6.1078 * 10) ^ (7.5 * tempC / (tempC + 237.3)) // hPa
var pv = hum * psat / 100 // vapour pressure of water
var pd = press - pv // dry air pressure
var airDensity = pd / (287.058 * temp) + pv / (461.495 * temp) // https://en.wikipedia.org/wiki/Density_of_air#cite_note-wahiduddin_01-15

return [{ path: "environment.outside.airDensity", value: airDensity}]
return [{ path: 'environment.outside.airDensity', value: airDensity }]
}
};
}
}
19 changes: 13 additions & 6 deletions calcs/batteryPower.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
const _ = require('lodash')

module.exports = function(app, plugin) {
module.exports = function (app, plugin) {
return plugin.batteries.map(instance => {
return {
group: 'electrical',
optionKey: 'batterPower' + instance,
title: "Battery " + instance + " Power ",
derivedFrom: function(){ return [ "electrical.batteries." + instance + ".voltage", "electrical.batteries." + instance + ".current" ] },
calculator: function(v, a) {
return [{ path: "electrical.batteries." + instance + ".power", value: v*a }]
title: 'Battery ' + instance + ' Power ',
derivedFrom: function () {
return [
'electrical.batteries.' + instance + '.voltage',
'electrical.batteries.' + instance + '.current'
]
},
calculator: function (v, a) {
return [
{ path: 'electrical.batteries.' + instance + '.power', value: v * a }
]
}
}
});
})
}
26 changes: 16 additions & 10 deletions calcs/depthBelowKeel.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
const _ = require('lodash')

module.exports = function(app) {
module.exports = function (app) {
var draft = app.getSelfPath('design.draft.maximum.value')

if ( ! draft ) {
if (!draft) {
draft = app.getSelfPath('design.draft.value.maximum')
}

var derivedFrom = typeof draft === 'undefined' ? [] : [ "environment.depth.belowSurface" ];

var derivedFrom =
typeof draft === 'undefined' ? [] : ['environment.depth.belowSurface']

return {
group: "depth",
group: 'depth',
optionKey: 'belowKeel',
title: "Depth Below Keel (based on depth.belowSurface and design.draft.maximum)",
title:
'Depth Below Keel (based on depth.belowSurface and design.draft.maximum)',
derivedFrom: derivedFrom,
calculator: function(depthBelowSurface)
{
return [{ path: 'environment.depth.belowKeel', value: depthBelowSurface - draft}]
calculator: function (depthBelowSurface) {
return [
{
path: 'environment.depth.belowKeel',
value: depthBelowSurface - draft
}
]
}
};
}
}
27 changes: 19 additions & 8 deletions calcs/depthBelowKeel2.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
const _ = require('lodash')

module.exports = function(app) {
var depthTransducerToKeel = app.getSelfPath('environment.depth.transducerToKeel.value')
module.exports = function (app) {
var depthTransducerToKeel = app.getSelfPath(
'environment.depth.transducerToKeel.value'
)

var derivedFrom = typeof depthTransducerToKeel === 'undefined' ? [] : [ "environment.depth.belowTransducer"];
var derivedFrom =
typeof depthTransducerToKeel === 'undefined'
? []
: ['environment.depth.belowTransducer']

return {
group: "depth",
group: 'depth',
optionKey: 'belowKeel_2',
title: "Depth Below Keel (based on depth.belowTransducer and depth.transducerToKeel)",
title:
'Depth Below Keel (based on depth.belowTransducer and depth.transducerToKeel)',
derivedFrom: derivedFrom,
calculator: function(depthBelowTransducer){
return [{ path: 'environment.depth.belowKeel', value: depthBelowTransducer + depthTransducerToKeel}]
calculator: function (depthBelowTransducer) {
return [
{
path: 'environment.depth.belowKeel',
value: depthBelowTransducer + depthTransducerToKeel
}
]
}
};
}
}
24 changes: 15 additions & 9 deletions calcs/depthBelowSurface.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
const _ = require('lodash')

module.exports = function(app) {
module.exports = function (app) {
var draft = app.getSelfPath('design.draft.maximum.value')

var derivedFrom = typeof draft === 'undefined' ? [] : [ "environment.depth.belowKeel" ];

var derivedFrom =
typeof draft === 'undefined' ? [] : ['environment.depth.belowKeel']

return {
group: "depth",
group: 'depth',
optionKey: 'belowSurface',
title: "Depth Below Surface (based on depth.belowKeel and design.draft.maximum)",
title:
'Depth Below Surface (based on depth.belowKeel and design.draft.maximum)',
derivedFrom: derivedFrom,
calculator: function(depthBelowKeel)
{
return [{ path: 'environment.depth.belowSurface', value: depthBelowKeel + draft}]
calculator: function (depthBelowKeel) {
return [
{
path: 'environment.depth.belowSurface',
value: depthBelowKeel + draft
}
]
}
};
}
}
24 changes: 14 additions & 10 deletions calcs/dewPoint.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@

module.exports = function(app, plugin) {
module.exports = function (app, plugin) {
return {
group: 'air',
optionKey: 'dewPoint',
title: "Outside air dew point (based on humidity and temperature)",
derivedFrom: [ "environment.outside.temperature", "environment.outside.humidity" ],
calculator: function(temp, hum) {
//Magnus formula:
title: 'Outside air dew point (based on humidity and temperature)',
derivedFrom: [
'environment.outside.temperature',
'environment.outside.humidity'
],
calculator: function (temp, hum) {
// Magnus formula:
var tempC = temp + 273.16
const b = 18.678
const c = 257.14
var magnus = Math.log(hum) + (b * tempC)/(c + tempC)
var dewPoint = (c * magnus) / (b - magnus) - 273.16
return [{ path: "environment.outside.dewPointTemperature", value: dewPoint}]
var magnus = Math.log(hum) + b * tempC / (c + tempC)
var dewPoint = c * magnus / (b - magnus) - 273.16
return [
{ path: 'environment.outside.dewPointTemperature', value: dewPoint }
]
}
};
}
}
21 changes: 15 additions & 6 deletions calcs/fuelConsumtion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _ = require('lodash')

module.exports = function(app, plugin) {
module.exports = function (app, plugin) {
var engines = plugin.engines

app.debug('engines: %j', engines)
Expand All @@ -10,11 +10,20 @@ module.exports = function(app, plugin) {
group: 'propulsion',
optionKey: 'economy' + instance,
title: `${instance} fuel economy (based on speed over ground, fuel rate)`,
derivedFrom: function(){ return [ "propulsion." + instance + ".fuel.rate", "navigation.speedOverGround" ] },
calculator: function(rate, speed) {
return [{ path: "propulsion." + instance + ".fuel.economy",
value: speed/rate }]
derivedFrom: function () {
return [
'propulsion.' + instance + '.fuel.rate',
'navigation.speedOverGround'
]
},
calculator: function (rate, speed) {
return [
{
path: 'propulsion.' + instance + '.fuel.economy',
value: speed / rate
}
]
}
}
});
})
}
31 changes: 19 additions & 12 deletions calcs/groundWind.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@

module.exports = function(app, plugin) {
module.exports = function (app, plugin) {
return {
group: 'wind',
optionKey: 'groundWind',
title: "Ground Wind Angle and Speed (based on SOG, AWA and AWS)",
derivedFrom: [ "navigation.speedOverGround", "environment.wind.speedApparent", "environment.wind.angleApparent" ],
calculator: function(sog, aws, awa) {
var apparentX = Math.cos(awa) * aws;
var apparentY = Math.sin(awa) * aws;
var angle = Math.atan2(apparentY, -sog + apparentX);
var speed = Math.sqrt(Math.pow(apparentY, 2) + Math.pow(-sog + apparentX, 2));
return [{ path: "environment.wind.angleTrueGround", value: angle},
{ path: "environment.wind.speedOverGround", value: speed}]
title: 'Ground Wind Angle and Speed (based on SOG, AWA and AWS)',
derivedFrom: [
'navigation.speedOverGround',
'environment.wind.speedApparent',
'environment.wind.angleApparent'
],
calculator: function (sog, aws, awa) {
var apparentX = Math.cos(awa) * aws
var apparentY = Math.sin(awa) * aws
var angle = Math.atan2(apparentY, -sog + apparentX)
var speed = Math.sqrt(
Math.pow(apparentY, 2) + Math.pow(-sog + apparentX, 2)
)
return [
{ path: 'environment.wind.angleTrueGround', value: angle },
{ path: 'environment.wind.speedOverGround', value: speed }
]
}
};
}
}
23 changes: 10 additions & 13 deletions calcs/headingTrue.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@



module.exports = function(app, plugin) {
module.exports = function (app, plugin) {
return {
group: 'heading',
optionKey: 'heading',
title: "True Heading (based on magnetic heading and magneticVarition)",
derivedFrom: [ "navigation.headingMagnetic", "navigation.magneticVariation" ],
calculator: function(heading, magneticVariation) {
title: 'True Heading (based on magnetic heading and magneticVarition)',
derivedFrom: ['navigation.headingMagnetic', 'navigation.magneticVariation'],
calculator: function (heading, magneticVariation) {
var headingTrue = heading + magneticVariation
if ( headingTrue < 0 ) {
headingTrue = (Math.PI*2) + headingTrue
} else if ( headingTrue > (Math.PI*2) ) {
headingTrue = headingTrue - (Math.PI*2)
if (headingTrue < 0) {
headingTrue = Math.PI * 2 + headingTrue
} else if (headingTrue > Math.PI * 2) {
headingTrue = headingTrue - Math.PI * 2
}
return [{ path: "navigation.headingTrue", value: headingTrue}]
return [{ path: 'navigation.headingTrue', value: headingTrue }]
}
};
}
}
39 changes: 30 additions & 9 deletions calcs/propslip.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
const _ = require("lodash")
const _ = require('lodash')

module.exports = function(app, plugin) {
module.exports = function (app, plugin) {
return plugin.engines.map(instance => {
return {
group: 'propulsion',
optionKey: 'propslip' + instance,
title: "propulsion." + instance + ".slip (based on RPM, propulsion." + instance + ".transmission.gearRatio and propulsion." + instance + ".drive.propeller.pitch)",
derivedFrom: function() { return [ "propulsion." + instance + ".revolutions", "navigation.speedThroughWater"] },
calculator: function(revolutions, stw) {
var gearRatio = app.getSelfPath('propulsion.' + instance + '.transmission.gearRatio.value')
var pitch = app.getSelfPath('propulsion.' + instance + '.drive.propeller.pitch.value')
return [{ path: 'propulsion.' + instance + '.drive.propeller.slip', value: 1 - ((stw * gearRatio)/(revolutions*pitch))}]
title:
'propulsion.' +
instance +
'.slip (based on RPM, propulsion.' +
instance +
'.transmission.gearRatio and propulsion.' +
instance +
'.drive.propeller.pitch)',
derivedFrom: function () {
return [
'propulsion.' + instance + '.revolutions',
'navigation.speedThroughWater'
]
},
calculator: function (revolutions, stw) {
var gearRatio = app.getSelfPath(
'propulsion.' + instance + '.transmission.gearRatio.value'
)
var pitch = app.getSelfPath(
'propulsion.' + instance + '.drive.propeller.pitch.value'
)
return [
{
path: 'propulsion.' + instance + '.drive.propeller.slip',
value: 1 - stw * gearRatio / (revolutions * pitch)
}
]
}
}
});
})
}
Loading

0 comments on commit 9318f3d

Please sign in to comment.