Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
satellitestudiodesign committed Apr 18, 2024
1 parent 23997f8 commit 2a39f00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
17 changes: 15 additions & 2 deletions libs/deck-loaders/src/vessels/lib/parse-tracks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TrackField } from '@globalfishingwatch/api-types'
import { VesselTrackData } from './types'
import { deckTrackDecoder } from './vessel-track-proto'
import { DeckTrack } from './vessel-track-proto'

export const DEFAULT_NULL_VALUE = -Math.pow(2, 31)

Expand Down Expand Up @@ -98,5 +98,18 @@ export const trackValueArrayToSegments = (valueArray: number[], fields_: TrackFi
}

export const parseTrack = (arrayBuffer: ArrayBuffer): VesselTrackData => {
return deckTrackDecoder(arrayBuffer)
const track = DeckTrack.decode(new Uint8Array(arrayBuffer)) as any
return {
...track,
attributes: {
getPath: {
value: new Float32Array(track.attributes.getPath.value),
size: track.attributes.getPath.size,
},
getTimestamp: {
value: new Float32Array(track.attributes.getTimestamp.value),
size: track.attributes.getTimestamp.size,
},
},
} as VesselTrackData
}
29 changes: 3 additions & 26 deletions libs/deck-loaders/src/vessels/lib/vessel-track-proto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import protobuf from 'protobufjs'
import { VesselTrackData } from './types'
import { parse } from 'protobufjs'

export const proto = `
const proto = `
syntax = "proto3";
package vessels;
Expand All @@ -25,26 +24,4 @@ message DeckTrack {
}
`

const root = protobuf.parse(proto).root
const DeckTrack = root.lookupType('DeckTrack')

function deckTrackDecoder(arrayBuffer: ArrayBuffer) {
const track = DeckTrack.decode(new Uint8Array(arrayBuffer)) as any
return {
...track,
attributes: {
getPath: {
value: new Float32Array(track.attributes.getPath.value),
size: track.attributes.getPath.size,
},
getTimestamp: {
value: new Float32Array(track.attributes.getTimestamp.value),
size: track.attributes.getTimestamp.size,
},
},
} as VesselTrackData
}

export { deckTrackDecoder }

export { DeckTrack }
export const DeckTrack = parse(proto).root.lookupType('DeckTrack')
6 changes: 3 additions & 3 deletions libs/deck-loaders/src/vessels/tracks-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PATH_BASENAME } from '../loaders.config'
import { parseTrack } from './lib/parse-tracks'

/**
* Worker loader for the Vessel Track int array format
* Worker loader for the Vessel Track DECKGL format
*/

export const VesselTrackWorkerLoader: Loader = {
Expand All @@ -15,7 +15,7 @@ export const VesselTrackWorkerLoader: Loader = {
version: packageJson?.version,
extensions: ['pbf'],
mimeTypes: ['application/x-protobuf', 'application/octet-stream', 'application/protobuf'],
worker: false,
worker: true,
options: {
'vessel-tracks': {
workerUrl: `${PATH_BASENAME}/workers/vessel-tracks-worker.js`,
Expand All @@ -24,7 +24,7 @@ export const VesselTrackWorkerLoader: Loader = {
}

/**
* Loader for the Vessel Track int array format
* Loader for the Vessel Track DECKGL format
*/
export const VesselTrackLoader: LoaderWithParser = {
...VesselTrackWorkerLoader,
Expand Down

0 comments on commit 2a39f00

Please sign in to comment.