Skip to content

Commit

Permalink
feature: add onlySelf config option
Browse files Browse the repository at this point in the history
Add support for storing data for only self vessel.
  • Loading branch information
tkurki committed Jun 17, 2023
1 parent 6dec9e9 commit 833014a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/influx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export interface SKInfluxConfig {
*/
bucket: string

/**
* @title Store only self data
* @default true
* @description Store data only for "self" data, not for example AIS targets' data
*/
onlySelf: boolean

writeOptions: Partial<WriteOptions>
}

Expand Down Expand Up @@ -80,12 +87,14 @@ export class SKInflux {
public failedLinesCount = 0
public lastWriteCallbackSucceeded = false
public url: string
private onlySelf: boolean
constructor(config: SKInfluxConfig, private logging: Logging, triggerStatusUpdate: () => void) {
const { org, bucket } = config
const { org, bucket, url, onlySelf } = config
this.influx = new InfluxDB(config)
this.org = org
this.bucket = bucket
this.url = config.url
this.url = url
this.onlySelf = onlySelf
this.writeApi = this.influx.getWriteApi(org, bucket, 'ms', {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
writeFailed: (_error, lines, _attempt, _expires) => {
Expand All @@ -107,10 +116,12 @@ export class SKInflux {
}

handleValue(context: SKContext, isSelf: boolean, source: string, pathValue: PathValue) {
const point = toPoint(context, isSelf, source, pathValue, this.logging.debug)
this.logging.debug(point)
if (point) {
this.writeApi.writePoint(point)
if (!this.onlySelf || isSelf) {
const point = toPoint(context, isSelf, source, pathValue, this.logging.debug)
this.logging.debug(point)
if (point) {
this.writeApi.writePoint(point)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('Plugin', () => {
token: 'signalk_token',
org: 'signalk_org',
bucket,
onlySelf: false,
writeOptions: {
batchSize: 1,
flushInterval: 10,
Expand Down

0 comments on commit 833014a

Please sign in to comment.