c98130cc08
* ui: Add the most basic workspace root in /ui * We already have a LICENSE file in the repository root * Change directory path in build scripts ui-v2 -> ui * Make yarn install flags configurable from elsewhere * Minimal workspace root makefile * Call the new docker specific target * Update yarn in the docker build image * Reconfigure the netlify target and move to the higher makefile * Move ui-v2 -> ui/packages/consul-ui * Change repo root to refleect new folder structure * Temporarily don't hoist consul-api-double * Fixup CI configuration * Fixup lint errors * Fixup Netlify target
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
// TODO: Istanbul is ignored for the moment as it's not mine,
|
|
// once I come here properly and 100% follow unignore
|
|
/* istanbul ignore file */
|
|
export default function(distance) {
|
|
return function(name, coordinates) {
|
|
var min = 999999999;
|
|
var max = -999999999;
|
|
var distances = [];
|
|
coordinates.forEach(function(node) {
|
|
if (name == node.Node) {
|
|
var segment = node.Segment;
|
|
coordinates.forEach(function(other) {
|
|
if (node.Node != other.Node && other.Segment == segment) {
|
|
var dist = distance(node, other);
|
|
distances.push({ node: other.Node, distance: dist, segment: segment });
|
|
if (dist < min) {
|
|
min = dist;
|
|
}
|
|
if (dist > max) {
|
|
max = dist;
|
|
}
|
|
}
|
|
});
|
|
distances.sort(function(a, b) {
|
|
return a.distance - b.distance;
|
|
});
|
|
}
|
|
});
|
|
var n = distances.length;
|
|
var halfN = Math.floor(n / 2);
|
|
var median;
|
|
|
|
if (n > 0) {
|
|
if (n % 2) {
|
|
// odd
|
|
median = distances[halfN].distance;
|
|
} else {
|
|
median = (distances[halfN - 1].distance + distances[halfN].distance) / 2;
|
|
}
|
|
} else {
|
|
median = 0;
|
|
min = 0;
|
|
max = 0;
|
|
}
|
|
return {
|
|
distances: distances,
|
|
min: parseInt(min * 100) / 100,
|
|
median: parseInt(median * 100) / 100,
|
|
max: parseInt(max * 100) / 100,
|
|
};
|
|
};
|
|
}
|