diff --git a/src/Map.vue b/src/Map.vue index 3d5eb62..43744b2 100644 --- a/src/Map.vue +++ b/src/Map.vue @@ -8,21 +8,26 @@ + + + + - - + - + @@ -36,7 +41,9 @@ - + @@ -49,6 +56,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -98,16 +148,60 @@ export default { return new GPX(options); }, - packetsToPoints(packets) { + packetsToStationPathPoints(packets) { return packets.map(packet => [ packet.data.longitude, packet.data.latitude ]); + }, + + packetToPacketPathPoints(packet) { + return this.pathToString(packet.via).map((hop, index, hops) => { + if (this.digiPos[hop] === undefined) { + console.log(hop); + } + + // first point in path is originating station + let previous = + index === 0 + ? [packet.data.longitude, packet.data.latitude] + : this.digiPos[hops[index - 1]] || [0, 0]; + + return [[previous, this.digiPos[hop] || [0, 0]], hop]; + }); + }, + + pathToString(path) { + return path + .filter( + station => !station.call.match(/WIDE[12]|qA?|UV[123]|.*\*$|UNCAN/) + ) + .map(station => + station + .toString() + .trim() + .replace(/\*$/, "") + ); + }, + + groupByCall(acc, packet) { + let callsign = packet.from.toString().trim(); + if (!(callsign in acc)) acc[callsign] = []; + acc[callsign].push(packet); + return acc; + }, + + colorForDigi(digi) { + if (digi in this.digiColors) { + return this.digiColors[digi].hex(); + } else { + return "black"; + } } }, computed: { - paths() { + stationPaths() { return ( this.packets .filter( @@ -117,22 +211,55 @@ export default { ) // filter to just positional data .filter(packet => "data" in packet && "latitude" in packet.data) - // join into Arrays of points - .reduce((acc, packet) => { - let callsign = packet.from.toString().trim(); - if (!(callsign in acc)) acc[callsign] = []; - acc[callsign].push(packet); - return acc; - }, {}) + // group by callsign + .reduce(this.groupByCall, {}) ); }, + digis() { + let digiCalls = new Set( + this.packets + .map(packet => this.pathToString(packet.via)) + .reduce((acc, stations) => acc.concat(stations)) + ); + + return ( + this.packets + // filter to digis + .filter(packet => digiCalls.has(packet.from.toString().trim())) + // filter to just positional data + .filter(packet => "data" in packet && "latitude" in packet.data) + // group by call + .reduce(this.groupByCall, {}) + ); + }, + + digiPos() { + return Object.entries(this.digis).reduce((acc, [digi, packets]) => { + let lastPacket = packets[packets.length - 1]; + acc[digi] = [lastPacket.data.longitude, lastPacket.data.latitude]; + return acc; + }, {}); + }, + stationColors() { return distinctColors({ - count: Object.keys(this.paths).length, + count: Object.keys(this.stationPaths).length, lightMin: 20, lightMax: 80 }); + }, + + digiColors() { + let colors = distinctColors({ + count: Object.keys(this.digis).length, + lightMin: 20, + lightMax: 80 + }); + return Object.keys(this.digis).reduce((acc, callsign, index) => { + acc[callsign] = colors[index]; + return acc; + }, {}); } } };