UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

33 lines 1.24 kB
import { RelativeDistance } from '../../data'; import { RelativePositionProcessing } from './RelativePositionProcessing'; /** * Cell identification processing node * @rdf {@link http://purl.org/poso/CellIdentification} * @category Processing node */ export class CellIdentificationNode extends RelativePositionProcessing { constructor(options) { super(RelativeDistance, options); this.options.maxDistance = this.options.maxDistance || 2; } processRelativePositions(dataObject, relativePositions, dataFrame) { return new Promise(resolve => { let spheres = []; relativePositions.forEach((object, relativePosition) => { if (object.getPosition()) { spheres.push([object.getPosition(), relativePosition.distance]); } }); // Order points and distances by distances spheres = spheres.sort((a, b) => a[1] - b[1]); if (spheres.length > 0 && spheres[0][1] <= this.options.maxDistance) { const position = spheres[0][0].clone(); position.timestamp = dataFrame.createdTimestamp; position.accuracy.value = spheres[0][1]; dataObject.setPosition(position); return resolve(dataObject); } resolve(dataObject); }); } }