atriusmaps-node-sdk
Version:
This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information
118 lines (99 loc) • 4 kB
JavaScript
;
var R = require('ramda');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
/**
* Visits all nodes (breadth-first) from the nodes2visit
* array, adding them to vnodes and adding their connected
* nodes to nodes2visit - until nodes2visit is empty.
* Nothing is returned - but the vnodes array will have been
* altered.
* @param {Object.<id:node>} nodes - the node pool you wish to scan
* @param {Node} startingNode - which node to start the scan
*/
function visitAll (nodes, startingNode) {
// initialize nodes2visit with the specified node to start
const nodes2visit = [startingNode];
const vnodes = new Set(); // visited nodes
while (nodes2visit.length) {
const node = nodes2visit.splice(0, 1)[0]; // next node to visit
if (node && !vnodes.has(node)) {
vnodes.add(node);
node.edges.forEach(edge => {
if (!vnodes.has(nodes[edge.dst]))
nodes2visit.push(nodes[edge.dst]);
});
}
}
return vnodes
}
/**
* @param {Object.<id:node>} nodes - the node pool you wish to scan
* @param {Node} [startingNode] - which node to start the scan (default: "first" node)
* @returns two arrays of nodes in an object, { orphaned, connected }
*/
function orphanTest (nodes, startingNode) {
const nodesArray = Object.values(nodes); // Convert to array
const vnodes = visitAll(nodes, startingNode || nodesArray[0]); // If no node is specified, use the first one we find
const onodes = nodesArray.filter(n => !vnodes.has(n));
console.log(`${onodes.length} Orphaned nodes found from ${nodesArray.length} total`);
return { orphaned: onodes, orphanedByFloor: R__namespace.groupBy(R__namespace.prop('floorId'), onodes), connected: Array.from(vnodes) }
}
const enrichDebugNavGraph = (nodes) => ({
nodes: toOrphanedNodesArray(nodes),
edges: getNavEdgeFeatures(nodes)
});
const transformNodes = isOrphaned =>
R__namespace.map(R__namespace.pipe(R__namespace.assoc('isOrphaned', isOrphaned), R__namespace.dissoc('edges')));
const toOrphanedNodesArray = R__namespace.pipe(
orphanTest,
R__namespace.pick(['connected', 'orphaned']),
R__namespace.evolve({
connected: transformNodes(false),
orphaned: transformNodes(true)
}),
R__namespace.values,
R__namespace.flatten
);
const getNavEdgeFeatures = nodes =>
Object.values(nodes).flatMap(node => node.edges)
.map(edge => mapEdge(edge, nodes));
const mapEdge = ({ src, dst, type, isDriveway }, nodeMap) => ({
startCoordinates: [nodeMap[src].lng, nodeMap[src].lat],
endCoordinates: [nodeMap[dst].lng, nodeMap[dst].lat],
isDriveway,
ordinal: nodeMap[src].ordinal,
category: getEdgeCategory(type),
defaultStrokeColor: getStrokeColorForMissingCategory(type)
});
const getStrokeColorForMissingCategory = R__namespace.cond([
[R__namespace.equals('Stairs'), R__namespace.always('#EFBC9B')],
[R__namespace.equals('Elevator'), R__namespace.always('#A491D3')],
[R__namespace.equals('Escalator'), R__namespace.always('#563F1B')],
[R__namespace.equals('Ramp'), R__namespace.always('#DBD053')],
[R__namespace.T, R__namespace.always('#FF0000')]
]);
const getEdgeCategory = R__namespace.cond([
[R__namespace.equals('Train'), R__namespace.always('nav.train')],
[R__namespace.equals('Bus'), R__namespace.always('nav.transit')],
[R__namespace.equals('Security Checkpoint'), R__namespace.always('nav.secure')],
[R__namespace.equals('Ground'), R__namespace.always('nav.primary')],
[R__namespace.T, R__namespace.always('')]
]);
exports.enrichDebugNavGraph = enrichDebugNavGraph;
exports.orphanTest = orphanTest;