@meri-imperiumi/signalk-triplogger 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/index.js +44 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -6,6 +6,8 @@ The plugin monitors vessel `navigation.state` as set by the [signalk-autostate](
6
6
 
7
7
  ## Changes
8
8
 
9
+ * 1.2.0 (April 27th 2023)
10
+ - Added support for populating `navigation.log` for totals
9
11
  * 1.1.1 (February 28th 2023)
10
12
  - Fix issue when `navigation.position` doesn't contain coordinates
11
13
  * 1.1.0 (March 4th 2022)
package/index.js CHANGED
@@ -16,6 +16,7 @@ module.exports = (app) => {
16
16
  const dateString = new Date().toISOString();
17
17
  return [
18
18
  'current', // Current trip
19
+ 'total', // Total log
19
20
  dateString.substr(0, 4), // Annual log
20
21
  dateString.substr(0, 7), // Monthly log
21
22
  dateString.substr(0, 10), // Daily log
@@ -74,6 +75,24 @@ module.exports = (app) => {
74
75
  function resetTrip() {
75
76
  logs.current.reset();
76
77
  const resetTime = logs.current.log.started;
78
+ const values = [
79
+ {
80
+ path: 'navigation.trip.log',
81
+ value: logs.current.log.total,
82
+ },
83
+ {
84
+ path: 'navigation.trip.lastReset',
85
+ value: resetTime,
86
+ },
87
+ ];
88
+ if (options.totals) {
89
+ const base = options.totals_base || 0;
90
+ values.push({
91
+ path: 'navigation.log',
92
+ value: logs.total.log.total + base,
93
+ });
94
+ }
95
+
77
96
  app.handleMessage(plugin.id, {
78
97
  context: `vessels.${app.selfId}`,
79
98
  updates: [
@@ -82,16 +101,7 @@ module.exports = (app) => {
82
101
  label: plugin.id,
83
102
  },
84
103
  timestamp: (new Date().toISOString()),
85
- values: [
86
- {
87
- path: 'navigation.trip.log',
88
- value: logs.current.log.total,
89
- },
90
- {
91
- path: 'navigation.trip.lastReset',
92
- value: resetTime,
93
- },
94
- ],
104
+ values,
95
105
  },
96
106
  ],
97
107
  });
@@ -106,6 +116,19 @@ module.exports = (app) => {
106
116
  return logs[logName].save();
107
117
  })))
108
118
  .then(() => {
119
+ const values = [
120
+ {
121
+ path: 'navigation.trip.log',
122
+ value: logs.current.log.total,
123
+ },
124
+ ];
125
+ if (options.totals) {
126
+ const base = options.totals_base || 0;
127
+ values.push({
128
+ path: 'navigation.log',
129
+ value: logs.total.log.total + base,
130
+ });
131
+ }
109
132
  app.handleMessage(plugin.id, {
110
133
  context: `vessels.${app.selfId}`,
111
134
  updates: [
@@ -114,12 +137,7 @@ module.exports = (app) => {
114
137
  label: plugin.id,
115
138
  },
116
139
  timestamp: (new Date().toISOString()),
117
- values: [
118
- {
119
- path: 'navigation.trip.log',
120
- value: logs.current.log.total,
121
- },
122
- ],
140
+ values,
123
141
  },
124
142
  ],
125
143
  });
@@ -202,6 +220,16 @@ module.exports = (app) => {
202
220
  default: 10000,
203
221
  title: 'How often to update log, in milliseconds',
204
222
  },
223
+ totals: {
224
+ type: 'boolean',
225
+ default: true,
226
+ title: 'Publish a total number in navigation.log',
227
+ },
228
+ totals_base: {
229
+ type: 'number',
230
+ default: 0,
231
+ title: 'Add this number to the totals (in meters)',
232
+ },
205
233
  },
206
234
  };
207
235
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meri-imperiumi/signalk-triplogger",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Log the length of the current trip",
5
5
  "main": "index.js",
6
6
  "scripts": {