Add/apply .prettierrc and .editorconfig

This commit is contained in:
Adam Goldsmith 2020-05-04 02:04:44 -04:00
parent dcb034dc10
commit 6f0a537a06
8 changed files with 111 additions and 104 deletions

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
# EditorConfig is awesome: https://EditorConfig.org
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 2

3
.prettierrc Normal file
View File

@ -0,0 +1,3 @@
trailingComma: es5
singleQuote: true
jsxBracketSameLine: true

View File

@ -83,32 +83,32 @@
</template> </template>
<script> <script>
import Vue from "vue"; import Vue from 'vue';
import { APRSParser } from "aprs-parser"; import { APRSParser } from 'aprs-parser';
import distinctColors from "distinct-colors"; import distinctColors from 'distinct-colors';
import VueLayers from "vuelayers"; import VueLayers from 'vuelayers';
import { createStyle, createLineGeom } from "vuelayers/lib/ol-ext"; import { createStyle, createLineGeom } from 'vuelayers/lib/ol-ext';
import { Control } from "ol/control"; import { Control } from 'ol/control';
import { GPX } from "ol/format"; import { GPX } from 'ol/format';
import "vuelayers/lib/style.css"; import 'vuelayers/lib/style.css';
Vue.use(VueLayers); Vue.use(VueLayers);
import route_data from "gpx/*.gpx"; import route_data from 'gpx/*.gpx';
import { readFileSync } from "fs"; import { readFileSync } from 'fs';
const packetLog = readFileSync(__dirname + "/../IS_packets.txt", "utf-8"); const packetLog = readFileSync(__dirname + '/../IS_packets.txt', 'utf-8');
function parsePackets(packetLog) { function parsePackets(packetLog) {
let parser = new APRSParser(); let parser = new APRSParser();
return ( return (
packetLog packetLog
.trim() .trim()
.split("\n") .split('\n')
// parse to Date and APRS packet // parse to Date and APRS packet
.map(line => { .map((line) => {
let packet = parser.parse(line.slice(29)); let packet = parser.parse(line.slice(29));
packet.date = new Date(line.slice(0, 18)); packet.date = new Date(line.slice(0, 18));
return packet; return packet;
@ -120,7 +120,7 @@ export default {
data() { data() {
return { return {
packets: parsePackets(packetLog), packets: parsePackets(packetLog),
routes: route_data routes: route_data,
}; };
}, },
@ -130,23 +130,18 @@ export default {
}, },
packetsToStationPathPoints(packets) { packetsToStationPathPoints(packets) {
return packets.map(packet => [ return packets.map((packet) => [
packet.data.longitude, packet.data.longitude,
packet.data.latitude packet.data.latitude,
]); ]);
}, },
pathToString(path) { pathToString(path) {
return path return path
.filter( .filter(
station => !station.call.match(/WIDE[12]|qA?|UV[123]|.*\*$|UNCAN/) (station) => !station.call.match(/WIDE[12]|qA?|UV[123]|.*\*$|UNCAN/)
) )
.map(station => .map((station) => station.toString().trim().replace(/\*$/, ''));
station
.toString()
.trim()
.replace(/\*$/, "")
);
}, },
groupByCall(acc, packet) { groupByCall(acc, packet) {
@ -160,7 +155,7 @@ export default {
if (digi in this.digiColors) { if (digi in this.digiColors) {
return this.digiColors[digi].hex(); return this.digiColors[digi].hex();
} else { } else {
return "#000000"; return '#000000';
} }
}, },
@ -171,7 +166,7 @@ export default {
feature feature
.getGeometry() .getGeometry()
.getLineStrings() .getLineStrings()
.forEach(ls => { .forEach((ls) => {
let path = paths.shift().slice(0); let path = paths.shift().slice(0);
ls.forEachSegment((start, end) => { ls.forEachSegment((start, end) => {
let color = this.colorForDigi(path.shift()); let color = this.colorForDigi(path.shift());
@ -180,14 +175,14 @@ export default {
createStyle({ createStyle({
geom: createLineGeom([start, end]), geom: createLineGeom([start, end]),
strokeColor: color, strokeColor: color,
strokeWidth: 2 strokeWidth: 2,
}) })
); );
}); });
}); });
return styles; return styles;
} },
}, },
computed: { computed: {
@ -195,12 +190,12 @@ export default {
return ( return (
this.packets this.packets
.filter( .filter(
packet => (packet) =>
packet.date > new Date("2018-07-13") && packet.date > new Date('2018-07-13') &&
packet.date < new Date("2018-07-14") packet.date < new Date('2018-07-14')
) )
// filter to just positional data // filter to just positional data
.filter(packet => "data" in packet && "latitude" in packet.data) .filter((packet) => 'data' in packet && 'latitude' in packet.data)
); );
}, },
@ -212,16 +207,16 @@ export default {
digis() { digis() {
let digiCalls = new Set( let digiCalls = new Set(
this.packets this.packets
.map(packet => this.pathToString(packet.via)) .map((packet) => this.pathToString(packet.via))
.reduce((acc, stations) => acc.concat(stations)) .reduce((acc, stations) => acc.concat(stations))
); );
return ( return (
this.packets this.packets
// filter to digis // filter to digis
.filter(packet => digiCalls.has(packet.from.toString().trim())) .filter((packet) => digiCalls.has(packet.from.toString().trim()))
// filter to just positional data // filter to just positional data
.filter(packet => "data" in packet && "latitude" in packet.data) .filter((packet) => 'data' in packet && 'latitude' in packet.data)
// group by call // group by call
.reduce(this.groupByCall, {}) .reduce(this.groupByCall, {})
); );
@ -238,26 +233,26 @@ export default {
packetPathsGeoJSON() { packetPathsGeoJSON() {
let digiPos = { ...this.digiPos }; // localize for performance let digiPos = { ...this.digiPos }; // localize for performance
return Object.entries(this.stationPaths).map(([station, packets]) => { return Object.entries(this.stationPaths).map(([station, packets]) => {
let lines = packets.map(packet => { let lines = packets.map((packet) => {
let path = this.pathToString(packet.via); let path = this.pathToString(packet.via);
return { return {
// first point in path is originating station // first point in path is originating station
coords: [ coords: [
[packet.data.longitude, packet.data.latitude], [packet.data.longitude, packet.data.latitude],
...path.map(hop => digiPos[hop] || [0, 0]) ...path.map((hop) => digiPos[hop] || [0, 0]),
], ],
path: path path: path,
}; };
}); });
return { return {
type: "Feature", type: 'Feature',
id: station, id: station,
geometry: { geometry: {
type: "MultiLineString", type: 'MultiLineString',
coordinates: lines.map(p => p.coords) coordinates: lines.map((p) => p.coords),
}, },
properties: { paths: lines.map(p => p.path) } properties: { paths: lines.map((p) => p.path) },
}; };
}); });
}, },
@ -266,7 +261,7 @@ export default {
return distinctColors({ return distinctColors({
count: Object.keys(this.stationPaths).length, count: Object.keys(this.stationPaths).length,
lightMin: 20, lightMin: 20,
lightMax: 80 lightMax: 80,
}); });
}, },
@ -274,14 +269,14 @@ export default {
let colors = distinctColors({ let colors = distinctColors({
count: Object.keys(this.digis).length, count: Object.keys(this.digis).length,
lightMin: 20, lightMin: 20,
lightMax: 80 lightMax: 80,
}); });
return Object.keys(this.digis).reduce((acc, callsign, index) => { return Object.keys(this.digis).reduce((acc, callsign, index) => {
acc[callsign] = colors[index]; acc[callsign] = colors[index];
return acc; return acc;
}, {}); }, {});
} },
} },
}; };
</script> </script>
@ -325,11 +320,11 @@ body {
} }
.expand + span::before { .expand + span::before {
content: "\25B6"; content: '\25B6';
} }
.expand:checked + span::before { .expand:checked + span::before {
content: "\25BC"; content: '\25BC';
} }
.expand ~ .collapsible-content { .expand ~ .collapsible-content {

View File

@ -6,8 +6,8 @@
<td>{{ formatTime(now - status.lastHeard, true) }}</td> <td>{{ formatTime(now - status.lastHeard, true) }}</td>
<td>{{ formatTime(Math.round(status.avgDelta), true) }}</td> <td>{{ formatTime(Math.round(status.avgDelta), true) }}</td>
<td>{{ status.lastMicE }}</td> <td>{{ status.lastMicE }}</td>
<td>{{ status.lastVoltage || "" }}</td> <td>{{ status.lastVoltage || '' }}</td>
<td>{{ status.lastTemperature || "" }}</td> <td>{{ status.lastTemperature || '' }}</td>
<td>{{ status.lastComment }}</td> <td>{{ status.lastComment }}</td>
</template> </template>
<template v-else> <template v-else>
@ -23,10 +23,10 @@
</template> </template>
<script> <script>
import config from "./status_config.yaml"; import config from './status_config.yaml';
export default { export default {
name: "StationRow", name: 'StationRow',
props: { callsign: String, tactical: String, messages: Array, now: Date }, props: { callsign: String, tactical: String, messages: Array, now: Date },
data() { data() {
@ -35,8 +35,8 @@ export default {
lastHeard: null, lastHeard: null,
delta: null, delta: null,
lastVoltage: null, lastVoltage: null,
lastTemperature: null lastTemperature: null,
} },
}; };
}, },
@ -47,8 +47,8 @@ export default {
formatTime(time, isDuration = false) { formatTime(time, isDuration = false) {
return new Date(time).toLocaleTimeString( return new Date(time).toLocaleTimeString(
"en-GB", 'en-GB',
isDuration ? { timeZone: "UTC" } : {} isDuration ? { timeZone: 'UTC' } : {}
); );
}, },
@ -59,13 +59,13 @@ export default {
hours: date.getUTCHours(), hours: date.getUTCHours(),
minutes: date.getUTCMinutes(), minutes: date.getUTCMinutes(),
seconds: date.getUTCSeconds(), seconds: date.getUTCSeconds(),
milliseconds: date.getUTCMilliseconds() milliseconds: date.getUTCMilliseconds(),
}) }),
] ]
.filter(([suffix, num]) => num > 0) .filter(([suffix, num]) => num > 0)
.map(([suffix, num]) => num + " " + suffix) .map(([suffix, num]) => num + ' ' + suffix)
.join(" "); .join(' ');
} },
}, },
watch: { watch: {
@ -80,8 +80,8 @@ export default {
let delta = message.date.getTime() - arr[idx - 1].date.getTime(); let delta = message.date.getTime() - arr[idx - 1].date.getTime();
acc.avgDelta = (acc.avgDelta * (idx - 1) + delta) / idx; acc.avgDelta = (acc.avgDelta * (idx - 1) + delta) / idx;
} }
if ("data" in message) { if ('data' in message) {
if ("analog" in message.data) { if ('analog' in message.data) {
acc.lastVoltage = message.data.analog[0] / 10; acc.lastVoltage = message.data.analog[0] / 10;
acc.lastTemperature = message.data.analog[1]; acc.lastTemperature = message.data.analog[1];
} }
@ -115,7 +115,7 @@ export default {
)} (${this.prettyDuration(this.now - this.status.lastHeard)} ago!)` )} (${this.prettyDuration(this.now - this.status.lastHeard)} ago!)`
); );
} }
} },
}, },
computed: { computed: {
@ -138,8 +138,8 @@ export default {
return ( return (
this.status.lastVoltage && this.status.lastVoltage < config.lowVoltage this.status.lastVoltage && this.status.lastVoltage < config.lowVoltage
); );
} },
} },
}; };
</script> </script>

View File

@ -26,14 +26,14 @@
</template> </template>
<script> <script>
import aprs from "aprs-parser"; import aprs from 'aprs-parser';
import StationRow from "./StationRow.vue"; import StationRow from './StationRow.vue';
import config from "./status_config.yaml"; import config from './status_config.yaml';
export default { export default {
name: "StationStatus", name: 'StationStatus',
components: { StationRow }, components: { StationRow },
data() { data() {
return { return {
@ -42,16 +42,16 @@ export default {
messages: [], messages: [],
messagesFromStation: {}, messagesFromStation: {},
now: new Date(), now: new Date(),
trackedStations: config.trackedStations trackedStations: config.trackedStations,
}; };
}, },
mounted() { mounted() {
// request notification permissions // request notification permissions
if (Notification.permission !== "granted") { if (Notification.permission !== 'granted') {
Notification.requestPermission(permission => { Notification.requestPermission((permission) => {
if (permission === "granted") { if (permission === 'granted') {
new Notification("Test notification", { body: "whatever" }); new Notification('Test notification', { body: 'whatever' });
} }
}); });
} }
@ -65,7 +65,7 @@ export default {
methods: { methods: {
connectToStream() { connectToStream() {
this.aprsStream = new WebSocket("ws://localhost:4321"); this.aprsStream = new WebSocket('ws://localhost:4321');
this.aprsStream.onclose = () => { this.aprsStream.onclose = () => {
// Try to reconnect every 5 seconds // Try to reconnect every 5 seconds
let interval = window.setTimeout(() => { let interval = window.setTimeout(() => {
@ -73,7 +73,7 @@ export default {
this.connectToStream(); this.connectToStream();
}, 5000); }, 5000);
}; };
this.aprsStream.onmessage = event => this.aprsStream.onmessage = (event) =>
this.handleMessage(JSON.parse(event.data)); this.handleMessage(JSON.parse(event.data));
}, },
@ -95,11 +95,11 @@ export default {
if ( if (
message.data && message.data &&
message.data.addressee && message.data.addressee &&
message.data.addressee.call === "TACTICAL" && message.data.addressee.call === 'TACTICAL' &&
config.TACTICAL_whitelist.includes(message.from.toString()) config.TACTICAL_whitelist.includes(message.from.toString())
) { ) {
message.data.text.split(";").map(tac_assoc => { message.data.text.split(';').map((tac_assoc) => {
let [call, tac] = tac_assoc.split("=", 2); let [call, tac] = tac_assoc.split('=', 2);
if (tac) { if (tac) {
this.trackedStations[call] = tac; this.trackedStations[call] = tac;
} else { } else {
@ -107,8 +107,8 @@ export default {
} }
}); });
} }
} },
} },
}; };
</script> </script>
@ -132,7 +132,7 @@ table th {
/* border magic for sticky header */ /* border magic for sticky header */
/* https://stackoverflow.com/questions/50361698/border-style-do-not-work-with-sticky-position-element */ /* https://stackoverflow.com/questions/50361698/border-style-do-not-work-with-sticky-position-element */
th::before { th::before {
content: ""; content: '';
position: absolute; position: absolute;
left: 0; left: 0;
width: 100%; width: 100%;
@ -142,7 +142,7 @@ th::before {
top: 1px; top: 1px;
} }
th::after { th::after {
content: ""; content: '';
position: absolute; position: absolute;
left: 0; left: 0;
width: 100%; width: 100%;

View File

@ -1,5 +1,5 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -3,5 +3,5 @@ import App from './StatusScreen.vue';
new Vue({ new Vue({
el: '#app', el: '#app',
render: h => h(App), render: (h) => h(App),
}); });

View File

@ -1,41 +1,41 @@
const WebSocket = require("ws"); const WebSocket = require('ws');
const net = require("net"); const net = require('net');
const fs = require("fs"); const fs = require('fs');
const client = new net.Socket(); const client = new net.Socket();
const wss = new WebSocket.Server({ host: "127.0.0.1", port: 4321 }); const wss = new WebSocket.Server({ host: '127.0.0.1', port: 4321 });
wss.broadcast = function (data) { wss.broadcast = function (data) {
wss.clients.forEach(client => { wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) { if (client.readyState === WebSocket.OPEN) {
client.send(data); client.send(data);
} }
}); });
}; };
client.connect(14580, "rotate.aprs2.net", () => client.connect(14580, 'rotate.aprs2.net', () =>
client.write("user KC1GDW pass -1 filter r/43.90/-72.15/75\r\n") client.write('user KC1GDW pass -1 filter r/43.90/-72.15/75\r\n')
); );
function datestamp(date) { function datestamp(date) {
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
} }
client.on("data", function(data) { client.on('data', function (data) {
let str = data.toString("utf8").replace(/^\s+|\s+$/g, ""); let str = data.toString('utf8').replace(/^\s+|\s+$/g, '');
console.log(str); console.log(str);
// strip whitespace, then handle multiple APRS packets per TCP packet // strip whitespace, then handle multiple APRS packets per TCP packet
str.split("\r\n").forEach(packet => { str.split('\r\n').forEach((packet) => {
if (!packet.startsWith("#")) { if (!packet.startsWith('#')) {
// ignore comments // ignore comments
let date = new Date(); let date = new Date();
// create log dir if it doesn't exist // create log dir if it doesn't exist
if (!fs.existsSync("log")) fs.mkdirSync("log"); if (!fs.existsSync('log')) fs.mkdirSync('log');
fs.appendFile( fs.appendFile(
`log/log${datestamp(date)}.json`, `log/log${datestamp(date)}.json`,
JSON.stringify([date, packet]) + "\n", JSON.stringify([date, packet]) + '\n',
err => { (err) => {
if (err) throw err; if (err) throw err;
} }
); );
@ -44,14 +44,14 @@ client.on("data", function(data) {
}); });
}); });
wss.on("connection", ws => { wss.on('connection', (ws) => {
let date = new Date(); let date = new Date();
let filename = `log/log${datestamp(date)}.json`; let filename = `log/log${datestamp(date)}.json`;
if (fs.existsSync(filename)) { if (fs.existsSync(filename)) {
fs.readFileSync(filename) fs.readFileSync(filename)
.toString() .toString()
.split("\n") .split('\n')
.forEach(line => ws.send(line)); .forEach((line) => ws.send(line));
} }
}); });