Add stats track tests (failing)
This commit is contained in:
parent
bd2e89ef06
commit
7c8c71a3de
4 changed files with 66 additions and 8 deletions
|
|
@ -107,3 +107,10 @@ btools = {};
|
||||||
})((util = btools.util || (btools.util = {})));
|
})((util = btools.util || (btools.util = {})));
|
||||||
})(btools || (btools = {}));
|
})(btools || (btools = {}));
|
||||||
btools.util.CheapRuler.__static_initialize();
|
btools.util.CheapRuler.__static_initialize();
|
||||||
|
|
||||||
|
btools.util.CheapRuler.toIntegerLngLat = (coordinate) => {
|
||||||
|
const ilon = (coordinate[0] + 180) * 1e6;
|
||||||
|
const ilat = (coordinate[1] + 90) * 1e6;
|
||||||
|
|
||||||
|
return [ilon, ilat];
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
(function () {
|
(function () {
|
||||||
// Calculates time and energy stats
|
// Calculates time and energy stats
|
||||||
//
|
|
||||||
// from BRouter btools.router.StdPath
|
|
||||||
|
|
||||||
class BExpressionContextWay {
|
class BExpressionContextWay {
|
||||||
getMaxspeed() {
|
getMaxspeed() {
|
||||||
|
|
@ -18,6 +16,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from BRouter btools.router.RoutingContext
|
||||||
class RoutingContext {
|
class RoutingContext {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.expctxGlobal = new BExpressionContext();
|
this.expctxGlobal = new BExpressionContext();
|
||||||
|
|
@ -32,6 +31,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from BRouter btools.router.StdPath
|
||||||
class StdPath {
|
class StdPath {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.totalTime = 0;
|
this.totalTime = 0;
|
||||||
|
|
@ -143,4 +143,5 @@
|
||||||
StdPath.GRAVITY = 9.81;
|
StdPath.GRAVITY = 9.81;
|
||||||
|
|
||||||
BR.StdPath = StdPath;
|
BR.StdPath = StdPath;
|
||||||
|
BR.RoutingContext = RoutingContext;
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
require('../../js/util/CheapRuler.js');
|
require('../../js/util/CheapRuler.js');
|
||||||
|
const geoJson = require('../format/data/track.json');
|
||||||
|
|
||||||
test('distance', () => {
|
test('distance', () => {
|
||||||
// https://github.com/abrensch/brouter/issues/3#issuecomment-440375918
|
// https://github.com/abrensch/brouter/issues/3#issuecomment-440375918
|
||||||
const latlng1 = [48.8124, 2.3158];
|
const lngLat1 = [2.3158, 48.8124];
|
||||||
const latlng2 = [48.8204, 2.321];
|
const lngLat2 = [2.321, 48.8204];
|
||||||
|
|
||||||
const ilon1 = (latlng1[1] + 180) * 1e6;
|
const [ilon1, ilat1] = btools.util.CheapRuler.toIntegerLngLat(lngLat1);
|
||||||
const ilat1 = (latlng1[0] + 90) * 1e6;
|
const [ilon2, ilat2] = btools.util.CheapRuler.toIntegerLngLat(lngLat2);
|
||||||
const ilon2 = (latlng2[1] + 180) * 1e6;
|
|
||||||
const ilat2 = (latlng2[0] + 90) * 1e6;
|
|
||||||
|
|
||||||
const distance = btools.util.CheapRuler.distance(ilon1, ilat1, ilon2, ilat2);
|
const distance = btools.util.CheapRuler.distance(ilon1, ilat1, ilon2, ilat2);
|
||||||
|
|
||||||
|
|
@ -16,3 +15,24 @@ test('distance', () => {
|
||||||
// 968.0593622374572 - CheapRuler.java
|
// 968.0593622374572 - CheapRuler.java
|
||||||
expect(distance).toBeCloseTo(968.0593622374572);
|
expect(distance).toBeCloseTo(968.0593622374572);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('total distance', () => {
|
||||||
|
const coordinates = geoJson.features[0].geometry.coordinates;
|
||||||
|
const properties = geoJson.features[0].properties;
|
||||||
|
let totalDistance = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < coordinates.length; i++) {
|
||||||
|
if (i === 0) continue;
|
||||||
|
|
||||||
|
const coord1 = coordinates[i - 1];
|
||||||
|
const coord2 = coordinates[i];
|
||||||
|
|
||||||
|
const [ilon1, ilat1] = btools.util.CheapRuler.toIntegerLngLat(coord1);
|
||||||
|
const [ilon2, ilat2] = btools.util.CheapRuler.toIntegerLngLat(coord2);
|
||||||
|
|
||||||
|
const distance = btools.util.CheapRuler.distance(ilon1, ilat1, ilon2, ilat2);
|
||||||
|
totalDistance += distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(Math.round(totalDistance)).toEqual(+properties['track-length']);
|
||||||
|
});
|
||||||
|
|
|
||||||
30
tests/util/StdPath.test.js
Normal file
30
tests/util/StdPath.test.js
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
BR = {};
|
||||||
|
require('../../js/util/CheapRuler.js');
|
||||||
|
require('../../js/util/StdPath.js');
|
||||||
|
|
||||||
|
const geoJson = require('../format/data/track.json');
|
||||||
|
|
||||||
|
test('simple track', () => {
|
||||||
|
const coordinates = geoJson.features[0].geometry.coordinates;
|
||||||
|
const properties = geoJson.features[0].properties;
|
||||||
|
const rc = new BR.RoutingContext();
|
||||||
|
const stdPath = new BR.StdPath();
|
||||||
|
|
||||||
|
for (let i = 0; i < coordinates.length; i++) {
|
||||||
|
if (i === 0) continue;
|
||||||
|
|
||||||
|
const coord1 = coordinates[i - 1];
|
||||||
|
const coord2 = coordinates[i];
|
||||||
|
|
||||||
|
const [ilon1, ilat1] = btools.util.CheapRuler.toIntegerLngLat(coord1);
|
||||||
|
const [ilon2, ilat2] = btools.util.CheapRuler.toIntegerLngLat(coord2);
|
||||||
|
|
||||||
|
const distance = btools.util.CheapRuler.distance(ilon1, ilat1, ilon2, ilat2);
|
||||||
|
const deltaHeight = coord2[2] - coord1[2];
|
||||||
|
|
||||||
|
stdPath.computeKinematic(rc, distance, deltaHeight, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(Math.round(stdPath.getTotalEnergy())).toEqual(+properties['total-energy']);
|
||||||
|
expect(Math.round(stdPath.getTotalTime())).toEqual(+properties['total-time']);
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue