Skip to content

Commit

Permalink
Merge branch 'SignalK:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
macjl authored May 15, 2024
2 parents a7ed1a3 + 7fdb36c commit 753a810
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 32 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release_on_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Release on tag'
on:
push:
tags:
- '*'

jobs:
release:
permissions:
contents: write
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}

- name: Create Release
uses: actions/create-release@v1
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: ${{steps.github_release.outputs.changelog}}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
13 changes: 13 additions & 0 deletions .github/workflows/require_pr_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Pull Request Labels
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: mheap/github-action-required-labels@v1
with:
mode: exactly
count: 1
labels: "fix, feature, doc, chore, test, ignore, other, dependencies"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It currently calculates:
* True Wind Direction (based on AWA and headingTrue)
* Ground Wind Angle and Speed (based on SOG, AWA and AWS)
* Magnetic Wind Direction (based on AWA and headingMagnetic)
* Magnetic Wind Direction (based on wind.directionTrue and magneticVarition)
* Magnetic Wind Direction (based on wind.directionTrue and magneticVariation)
* Wind Shift (experimental)
* Moon illumination and times (based on time and navigation.position)
* Sunlight Times: sunrise, sunriseEnd, goldenHourEnd, solarNoon, goldenHour, sunsetStart, sunset, dusk, nauticalDusk, night, nadir, nightEnd, nauticalDawn, dawn (based on time and navigation.position)
Expand Down
10 changes: 10 additions & 0 deletions calcs/courseOverGroundMagnetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module.exports = function (app, plugin) {
return
}
}
if (
_.isUndefined(courseOverGroundTrue) ||
courseOverGroundTrue === null
) {
return [{ path: 'navigation.courseOverGroundMagnetic', value: null }]
}
var courseOverGroundMagnetic = courseOverGroundTrue - magneticVariation
if (courseOverGroundMagnetic < 0) {
courseOverGroundMagnetic = Math.PI * 2 + courseOverGroundMagnetic
Expand All @@ -36,6 +42,10 @@ module.exports = function (app, plugin) {
{
input: [1.0, 0.1],
expected: [{ path: 'navigation.courseOverGroundMagnetic', value: 0.9 }]
},
{
input: [null, -0.01],
expected: [{ path: 'navigation.courseOverGroundMagnetic', value: null }]
}
]
}
Expand Down
14 changes: 13 additions & 1 deletion calcs/courseOverGroundTrue.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module.exports = function (app, plugin) {
return
}
}
if (
_.isUndefined(courseOverGroundMagnetic) ||
courseOverGroundMagnetic === null
) {
return [{ path: 'navigation.courseOverGroundTrue', value: null }]
}
var courseOverGroundTrue = courseOverGroundMagnetic + magneticVariation
if (courseOverGroundTrue < 0) {
courseOverGroundTrue = Math.PI * 2 + courseOverGroundTrue
Expand All @@ -28,6 +34,12 @@ module.exports = function (app, plugin) {
return [
{ path: 'navigation.courseOverGroundTrue', value: courseOverGroundTrue }
]
}
},
tests: [
{
input: [null, 0.01],
expected: [{ path: 'navigation.courseOverGroundTrue', value: null }]
}
]
}
}
10 changes: 8 additions & 2 deletions calcs/eta.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,22 @@ module.exports = function (app) {
if (velocityMadeGood > 0) {
var etad = new Date(parseInt(etams))
var eta = etad.toISOString()
var ttg = Math.floor(timetopoint / 1000)
} else {
var eta = '--'
var eta = null
var ttg = null
}
app.debug(`what is eta: ${eta} etams: ${etams} etad: ${etad}`)
// app.debug(`what is eta: ${eta} etams: ${etams} etad: ${etad}`)

return [
{
path: 'navigation.courseGreatCircle.nextPoint.estimatedTimeOfArrival',
value: eta
},
{
path: 'navigation.courseGreatCircle.nextPoint.timeToGo',
value: ttg
},
{
path: 'navigation.courseGreatCircle.nextPoint.eta',
value: eta
Expand Down
11 changes: 10 additions & 1 deletion calcs/headingTrue.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ module.exports = function (app, plugin) {
return
}
}
if (_.isUndefined(heading) || heading === null) {
return [{ path: 'navigation.headingTrue', value: null }]
}
var headingTrue = heading + magneticVariation
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 }]
}
},
tests: [
{
input: [null, 0.01],
expected: [{ path: 'navigation.headingTrue', value: null }]
}
]
}
}
9 changes: 4 additions & 5 deletions calcs/leeway.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function (app, plugin) {
group: 'heading',
optionKey: 'leeway',
title: 'Leeway',
derivedFrom: ['navigation.attitude.roll', 'navigation.speedThroughWater'],
derivedFrom: ['navigation.attitude', 'navigation.speedThroughWater'],
properties: {
kFactor: {
type: 'number',
Expand All @@ -13,12 +13,11 @@ module.exports = function (app, plugin) {
default: 12
}
},
calculator: function (roll, stw) {
calculator: function (attitude, stw) {
var kFactor = plugin.properties.heading.kFactor
var rollDegrees = roll / Math.PI * 360
var rollDegrees = attitude.roll / Math.PI * 360
var stwKnots = stw * 1.94384
var leewayAngle =
kFactor * rollDegrees / Math.pow(stwKnots, 2) / 360 * Math.PI
var leewayAngle = stwKnots <= 0 ? 0 : kFactor * rollDegrees / Math.pow(stwKnots, 2) / 360 * Math.PI
// app.debug('roll: ' + rollDegrees + ' stw: ' + stwKnots + ' knots => leeway: ' + leewayAngle/Math.PI*360)
return [{ path: 'performance.leeway', value: leewayAngle }]
}
Expand Down
21 changes: 11 additions & 10 deletions calcs/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ module.exports = function (app, plugin) {
optionKey: 'Moon',
title: 'Sets environment.moon.* information such as phase, rise, and set',
derivedFrom: ['navigation.datetime', 'navigation.position'],
defaults: ['', undefined],
defaults: [undefined, undefined],
debounceDelay: 60 * 1000,
calculator: function (datetime, position) {
var value
var mode
var date

if (datetime && datetime.length > 0) {
if (!_.isUndefined(datetime) && datetime.length > 0) {
date = new Date(datetime)
} else {
date = new Date()
}

app.debug(`Using datetime: ${date} position: ${JSON.stringify(position)}`)

var illumination = suncalc.getMoonIllumination(date)
const illumination = suncalc.getMoonIllumination(date)
_.keys(illumination).forEach(key => {
illumination[key] = illumination[key].toFixed(2)
illumination[key] = _.round(illumination[key], 2)
})
app.debug('moon illumination:' + JSON.stringify(illumination, null, 2))

Expand Down Expand Up @@ -57,27 +55,30 @@ module.exports = function (app, plugin) {
}
app.debug('Phase Name:' + phaseName)

var times = suncalc.getMoonTimes(
const times = suncalc.getMoonTimes(
date,
position.latitude,
position.longitude
)
app.debug('moon times:' + JSON.stringify(times, null, 2))

return [
{ path: 'environment.moon.fraction', value: illumination.fraction },
{
path: 'environment.moon.fraction',
value: illumination.fraction
},
{ path: 'environment.moon.phase', value: illumination.phase },
{ path: 'environment.moon.phaseName', value: phaseName },
{ path: 'environment.moon.angle', value: illumination.angle },
{ path: 'environment.moon.times.rise', value: times.rise || null },
{ path: 'environment.moon.times.set', value: times.set || null },
{
path: 'environment.moon.times.alwaysUp',
value: times.alwaysUp ? 'true' : 'false'
value: !!times.alwaysUp
},
{
path: 'environment.moon.times.alwaysDown',
value: times.alwaysDown ? 'true' : 'false'
value: !!times.alwaysDown
}
]
}
Expand Down
6 changes: 1 addition & 5 deletions calcs/vmg_wind.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ module.exports = function (app) {
],
calculator: function (trueWindAngle, speedOverGround) {
var vmg_wind = Math.cos(trueWindAngle) * speedOverGround
if (vmg_wind < 0) {
return [{ path: 'performance.velocityMadeGood', value: vmg_wind }]
} else {
return [{ path: 'performance.velocityMadeGood', value: vmg_wind }]
}
return [{ path: 'performance.velocityMadeGood', value: vmg_wind }]
}
}
}
20 changes: 20 additions & 0 deletions calcs/vmg_wind_stw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = function (app) {
return {
group: 'course data',
optionKey: 'vmg_Wind_STW',
title:
'Velocity Made Good to wind (based on wind.angleTrueWater and speedThroughWater)',
derivedFrom: [
'environment.wind.angleTrueWater',
'navigation.speedThroughWater'
],
calculator: function (angleTrueWater, speedThroughWater) {
return [
{
path: 'performance.velocityMadeGood',
value: Math.cos(angleTrueWater) * speedThroughWater
}
]
}
}
}
11 changes: 10 additions & 1 deletion calcs/windDirectionMagnetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = function (app, plugin) {
'navigation.magneticVariation'
],
calculator: function (directionTrue, magneticVariation) {
if (directionTrue === null) {
return [{ path: 'environment.wind.directionMagnetic', value: null }]
}
var directionMagnetic = directionTrue - magneticVariation
if (directionMagnetic < 0) {
directionMagnetic = Math.PI * 2 + directionMagnetic
Expand All @@ -17,6 +20,12 @@ module.exports = function (app, plugin) {
return [
{ path: 'environment.wind.directionMagnetic', value: directionMagnetic }
]
}
},
tests: [
{
input: [null, -0.01],
expected: [{ path: 'environment.wind.directionMagnetic', value: null }]
}
]
}
}
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"name": "signalk-derived-data",
"version": "1.31.0",
"version": "1.33.0",
"description": "Plugin that derives signalk data from other signalk data",
"main": "index.js",
"scripts": {
"precommit": "lint-staged",
"format": "prettier-standard calcs/*.js index.js",
"changelog": "github-changes -o signalk -r signalk-derived-data -a --only-pulls --use-commit-body --data=pulls --tag-name=v$npm_package_version",
"create-release": "github-create-release --owner signalk --repository signalk-derived-data",
"release": "git tag -d v$npm_package_version ; git tag v$npm_package_version && git push --tags && git push && npm run create-release",
"test": "mocha"
},
"keywords": [
Expand Down Expand Up @@ -47,10 +44,8 @@
"suncalc": "^1.8.0"
},
"devDependencies": {
"@signalk/github-create-release": "^1.2.0",
"chai": "^4.2.0",
"chai-json-equal": "0.0.1",
"github-changes": "^1.0.4",
"husky": "^0.14.3",
"lint-staged": "^7.0.0",
"mocha": "^8.2.1",
Expand Down

0 comments on commit 753a810

Please sign in to comment.