@globalfishingwatch/data-transforms
Advanced tools
Comparing version 1.2.2 to 1.3.0
# @globalfishingwatch/data-transforms | ||
## 1.3.0 | ||
### Minor Changes | ||
- b3f3ca64: Sync valueArray decoding with encoding in api-vessels-service | ||
## 1.2.2 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
export{c as checkRecordValidity,a as csvToTrackSegments,g as guessColumns}from"../guessColumns-f3e40d02.js"; | ||
export{c as checkRecordValidity,a as csvToTrackSegments,g as guessColumns}from"../guessColumns-134bc34b.js";import"lodash"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
export{D as DEFAULT_NULL_VALUE,F as Field,T as TRACK_FIELDS,t as trackValueArrayToSegments}from"./track-value-array-to-segments-682cc8f2.js";export{f as filterSegmentsByTimerange,g as geoJSONToSegments,a as segmentsToBbox,s as segmentsToGeoJSON}from"./segments-to-geojson-3a5bd3f1.js";export{c as checkRecordValidity,a as csvToTrackSegments,g as guessColumns}from"./guessColumns-f3e40d02.js"; | ||
export{D as DEFAULT_NULL_VALUE,F as Field,T as TRACK_FIELDS,t as trackValueArrayToSegments}from"./track-value-array-to-segments-834c4373.js";export{f as filterSegmentsByTimerange,g as geoJSONToSegments,a as segmentsToBbox,s as segmentsToGeoJSON}from"./segments-to-geojson-3a5bd3f1.js";export{c as checkRecordValidity,a as csvToTrackSegments,g as guessColumns}from"./guessColumns-134bc34b.js";import"lodash"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
export{D as DEFAULT_NULL_VALUE,F as Field,T as TRACK_FIELDS,t as trackValueArrayToSegments}from"../track-value-array-to-segments-682cc8f2.js"; | ||
export{D as DEFAULT_NULL_VALUE,F as Field,T as TRACK_FIELDS,t as trackValueArrayToSegments}from"../track-value-array-to-segments-834c4373.js"; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@globalfishingwatch/data-transforms", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Utils to decode various data formats", | ||
@@ -30,2 +30,5 @@ "main": "dist/index.js", | ||
}, | ||
"peerDependencies": { | ||
"lodash": "^4.17.21" | ||
}, | ||
"publishConfig": { | ||
@@ -37,3 +40,3 @@ "access": "public" | ||
}, | ||
"gitHead": "fc7e545437bb4f5270ee8e27f780c5f15e7e0c7a" | ||
"gitHead": "8cb56ccf3ccc862e5070e009f9630d9542202cb4" | ||
} |
@@ -1,2 +0,2 @@ | ||
import groupBy from 'lodash/groupBy' | ||
import { groupBy } from 'lodash' | ||
import { Segment } from '../track-value-array-to-segments' | ||
@@ -3,0 +3,0 @@ import { Columns } from './types' |
@@ -6,2 +6,26 @@ import { Field, Segment, Point } from './types' | ||
/** | ||
* Transformer functions to be applied on every valueArray field | ||
* to convert the received value (Int32) to the actual value (Float) | ||
* depending on its precision. | ||
* This transformations should be the inverse of the formatterValueArray | ||
* property of every field defined in: | ||
* https://github.com/GlobalFishingWatch/api-vessels-service/blob/develop/src/modules/api/v1/vessels/modules/tracks/services/feature.service.ts | ||
*/ | ||
const transformerByField: Partial<Record<Field, (value: number) => number>> = { | ||
[Field.course]: (value: number) => value / Math.pow(10, 6), | ||
[Field.distanceFromPort]: (value: number) => value, | ||
// Uncomment when added to new package version | ||
// [Field.distanceFromShore]: (value: number) => value, | ||
[Field.elevation]: (value: number) => value, | ||
// Uncomment when added to new package version | ||
// [Field.encounter]: (value: number) => value, | ||
[Field.latitude]: (value: number) => value / Math.pow(10, 6), | ||
[Field.longitude]: (value: number) => value / Math.pow(10, 6), | ||
[Field.fishing]: (value: number) => value, | ||
[Field.night]: (value: number) => value, | ||
[Field.speed]: (value: number) => value / Math.pow(10, 6), | ||
[Field.timestamp]: (value: number) => value * Math.pow(10, 3), | ||
} | ||
export const trackValueArrayToSegments = (valueArray: number[], fields_: Field[]) => { | ||
@@ -12,3 +36,3 @@ if (!fields_.length) { | ||
const fields = fields_ | ||
const fields: Field[] = [...fields_] | ||
if (fields.includes(Field.lonlat)) { | ||
@@ -68,9 +92,8 @@ const llIndex = fields.indexOf(Field.lonlat) | ||
const field: Field = fields[currentPointFieldIndex] | ||
const transformer = transformerByField[field] | ||
// values by default must be / 1000000 in order to convert ints to floats | ||
// except for timestamp that mmust be converted from s to ms | ||
if (value === nullValue) { | ||
if (value === nullValue || transformer === undefined) { | ||
currentPoint[field] = null | ||
} else { | ||
currentPoint[field] = field === Field.timestamp ? value * 1000 : value / 1000000 | ||
currentPoint[field] = transformer(value) | ||
} | ||
@@ -77,0 +100,0 @@ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
68
521
0
1290186
2