New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sparc-commons

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sparc-commons - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

libs/geocode.js

1

libs/geojsonutils.js

@@ -51,2 +51,3 @@ var es = exports,

}
var coordIdx = es.coordIdx = function coordIdx(lonLat, feature){

@@ -53,0 +54,0 @@ var idx = _.findIndex(feature.geometry.coordinates, function(coord){

103

libs/geoservice.js
/*jshint multistr: true */
var _ = require('lodash'),
log = require('./logger').logger('geo-service'),
h = require('highland'),
polyline = require('polyline'),
segmentDistance = require('./geojsonutils').segmentDistance,
resources = require('./resources');
segmentDistance = require('./geojsonutils').segmentDistance
function formatZULU(date){
// Return last coordinate point for given imei
var now = date.toISOString().slice(0, 19);
now += 'Z';
return now;
}
/**
* Prepare the GPX request
*
* @param {Array<Route>} routes
* @return {String} gpx request
*/
var prepareGPXRequest = exports.prepareGPXRequest = function prepareGPXRequest(routes){
//TODO: maybe using a template?
var gpxcontent= '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> \
<gpx version="1.1" creator="sparc-server http://www.beestar.eu" \
xmlns="http://www.topografix.com/GPX/1/1" \
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">';
gpxcontent = _.reduce(routes, function(gpx, route){
log.debug("Processing route " + route.properties.id);
gpx += _.reduce(route.properties.events, function(gpxElem, rp){
if(_.isString(rp.properties.timestamp)){
}
gpxElem += '<trkpt lat="' + rp.geometry.coordinates[1] + '" lon="' + rp.geometry.coordinates[0] + '"><time>' + formatZULU(rp.properties.timestamp) + '</time><name>' + rp.properties.id + '</name></trkpt>';
return gpxElem;
}, "<trk><name>" + route.properties.id + "</name><trkseg>");
gpx += "</trkseg></trk>";
return gpx;
}, gpxcontent) + "</gpx>";
return gpxcontent;
};
function isGeoJson(coords){

@@ -167,25 +126,2 @@ return _.isArray(_.get(coords, "geometry.coordinates"))

/**
* This function performs a reverse geocoding call to mapquest
*/
reverseGeocode: function reverseGeocode(lat, lon){
//TODO: throw the error and let the client decide what to do
// var stream = resources.jsonStreamRequest("mapquest", "reverse-geocoding", {data:{"location": lat + ',' + lon}});
debugger
return resources.requestResource("beestar", "reverse-geocoding", {data:{"lat": lat, "lon" : lon, "format": "json", "accept-language" : "en-GB" }})
.catch(function(err){
console.error(err)
})
.then(function(data){
var response = data;
//Right now we just log the reverse geocoding error, and will return an empty string.
if(_.get(JSON.parse(JSON.stringify(response)), 'type') === 'Buffer'){
//almost surely this is an error
// throw new SparcErr("The response is incomplete: " + JSON.stringify(response) , SparcErr.OPERATIONAL.RESOURCE_ERR);
log.error("The response is incomplete: " + JSON.stringify(response));
}
return response;
//return _.get(response, "address", {});
});
},

@@ -231,39 +167,4 @@ /**

return Math.round(reduction.dist)/1000; //return distance in Km
},
/**
* @param {Array<Number, Array<RoutePoint>>} routePointContainers An array of objects containing an array of routepoints
* @param {Number} routePointContainers._.id
* @param {Array<RoutePoint>} routePointContainers._.routePoints
*
* @return {Object} A JSON Object carrying the corrected routepoints
*
*/
correctRoutes: function correctRoutes(routePointContainers){
if(!routePointContainers){
throw Error("Routes passed to geoService.correctRoutes are undefined or empty");
}
var gpxRequest = prepareGPXRequest(routePointContainers);
var options = {
request: {
headers: {
'Content-Type': 'application/gpx+xml',
'Accept': 'application/json'
}
},
stream: h([gpxRequest]),
data : {
"output.groupByWays": "true",
"output.linkGeometries": "true",
"output.osmProjection": "false",
"output.linkMatchingError": "false",
"output.waypoints": "true",
"output.waypointsIds": "true"
}
};
return resources.requestResource("trackmatch", "correction-service", options);
}
};
}

@@ -270,0 +171,0 @@ exports.NMEAToEPSG3857 = function NMEAToEPSG3857(lat, lon) {

@@ -8,1 +8,2 @@ var _ = require('lodash')

_.merge(es, require('./logger'))
_.merge(es, require('./geocode'))
{
"name": "sparc-commons",
"version": "0.1.9",
"version": "0.1.10",
"description": "Library with all small time common stuff used across the SPARC echosystem",

@@ -31,5 +31,5 @@ "main": "index.js",

"moment": "^2.10.6",
"polyline": "^0.2.0",
"needle": "^0.11.0"
"needle": "^0.11.0",
"polyline": "^0.2.0"
}
}
var chai = require('chai'),
_ = require('lodash'),
log = require('../libs').log,
fs = require('fs'),
path = require('path'),
sinon = require('sinon'),
xml2js = require('xml2js'),
geo = require('../libs'),
polyline = require('polyline'),
resources = require('../libs').resources;
geocode = require('../libs/geocode').reverseGeocode,
resources = require('../libs').resources

@@ -17,123 +15,3 @@ var assert = chai.assert;

describe("[INFRASTRUCTURE]", function(){
it("Tests performing a request to trackmatch", function(done){
var rpDateOne = new Date(Date.now() - 20 * 60 * 1000);
var rpDateTwo = new Date(Date.now() - 20 * 59 * 1000);
var rpDateThree = new Date(Date.now() - 20 * 58 * 1000);
var routes = [{
properties:
{
id:69,
events: [{
properties: {
id:66,
timestamp: rpDateOne
},
geometry: {
coordinates: ["52.374833", "4.90435174"]
}
},{
properties: {
id:67,
timestamp: rpDateTwo
},
geometry: {
coordinates: ["52.374911", "4.90425011"]
}
},{
properties: {
id:68,
timestamp: rpDateThree
},
geometry: {
coordinates: ["52.37507482", "4.90394075"]
}
}]
}
}];
var gpx = geo.prepareGPXRequest(routes);
xml2js.parseString(gpx, {trim: true}, function(err, res){
var encoded = _.flatten(_.pluck(res, "trk"))[0];
assert.equal("69", encoded.name);
assert.equal("66", _.get(encoded, "trkseg[0].trkpt[0].name"));
assert.equal("67", _.get(encoded, "trkseg[0].trkpt[1].name"));
assert.equal("68", _.get(encoded, "trkseg[0].trkpt[2].name"));
done();
});
});
});
describe("[TRACKMATCH]", function(){
it("Testing correction service", function(done){
var rpDateOne = new Date(Date.now() - 20 * 60 * 1000);
var rpDateTwo = new Date(Date.now() - 20 * 59 * 1000);
var rpDateThree = new Date(Date.now() - 20 * 58 * 1000);
var routes = [{
properties:
{
id:69,
events: [{
properties: {
id:66,
timestamp: rpDateOne
},
geometry: {
coordinates: ["52.374833", "4.90435174"]
}
},{
properties: {
id:67,
timestamp: rpDateTwo
},
geometry: {
coordinates: ["52.374911", "4.90425011"]
}
},{
properties: {
id:68,
timestamp: rpDateThree
},
geometry: {
coordinates: ["52.37507482", "4.90394075"]
}
}]
}
}];
geo.geoService.correctRoutes(routes)
.then(function(corrections){
assert.isArray(_.get(corrections, 'diary.entries'));
done();
})
.catch(function(err){
log.fatal(err.stack);
done(err);
});
});
});
describe("[BEESTAR]", function(){
it("Testing reverse geocoding", function(done){
var rev = geo.geoService.reverseGeocode("52.374833", "4.90435174");
rev.then(function(data){
assert.equal(data.address.road, "Prins Hendrikkade");
done();
})
.catch(function(err){
log.error(err.stack);
done(err);
});
});
});
describe("[POLYLINE DISTANCE]", function(){

@@ -140,0 +18,0 @@ it("polylineDistance() should return the correct value", function(){

var log = require('..').log;
var path = require('path');
var fs = require('fs');
var nock = require('nock');

@@ -5,0 +3,0 @@ var assert = require('chai').assert;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc