Skip to content

Commit

Permalink
Breaking - I have no idea what I have done
Browse files Browse the repository at this point in the history
  • Loading branch information
Grabt234 committed Aug 4, 2024
1 parent 5eaa570 commit b622cea
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lib/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="/">Home</a>
<a href="/map">Map</a>
</nav>
<StatusText />

</section>
</div>

Expand Down
60 changes: 60 additions & 0 deletions src/lib/PolarPlot.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script>
import { WebglPlot, WebglPolar , ColorRGBA } from 'webgl-plot';
let bInitialised = false;
export let anAngles_deg;
export let strChartID;
let Chart = undefined;
let ChartLines = undefined;
let WebGLPlot = undefined;
let LineColor = undefined;
function InitCanvas() {
// Ensure HMTL is loaded in
if (!document.getElementById(strChartID)) {
return;
}
// Ensure we processed some data (therefore var set)
if (!anAngles_deg.length) {
return;
}
// Create the "class" wise context only once
if (!WebGLPlot) {
ChartLines = [];
Chart = document.getElementById(strChartID);
WebGLPlot = new WebglPlot(Chart);
}
bInitialised = true;
}
$: {
if (!bInitialised) {
InitCanvas();
}
if (WebGLPlot && ChartLines) {
WebGLPlot.removeDataLines()
for (let i = 0; i < anAngles_deg.length; i++) {
LineColor = new ColorRGBA(0, 0, 0, 1);
let line = new WebglPolar(LineColor, 10);
line.setRtheta(0, 0, 0);
line.setRtheta(1, anAngles_deg[i], 10)
WebGLPlot.addLine(line);
}
WebGLPlot.update();
}
}
</script>

<canvas class="canvas" id={strChartID} bind:this={Chart} />
26 changes: 23 additions & 3 deletions src/lib/SensorGroup.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
<script lang="ts" defer>
import { Badge } from '@svelteuidev/core';
import LineChart from '$lib/LineChart.svelte';
import PolarPlot from './PolarPlot.svelte';
// Define the props expected by SensorGroup
export let timeSampleRate = -1;
export let timeChunkSize = -1;
export let freqSampleRate = -1;
export let freqChunkSize = -1;
export let sourceIdentifier = '-';
export let sourceIdentifier = "";
export let aanTimeYValues: number[][] = [];
export let aanFreqYValues: number[][] = [];
export let anAngles_deg: number[][] = [];
</script>

<div class-="sensorGroup">
<Badge color="gray" radius="md" size="xl">Sensor ID: {sourceIdentifier}</Badge>
<div class="graphSuperGroup">
{#if aanTimeYValues.length !== 0}
<div class="graphGroup">
<Badge color="gray">Time Domain</Badge>
<div class="parameterContainer">
<Badge color="gray">Sample Rate: {timeSampleRate}</Badge>
<Badge color="gray">Chunk Size: {timeChunkSize}</Badge>
Expand All @@ -29,7 +33,10 @@
/>
</div>
</div>
{/if}
{#if aanFreqYValues.length !== 0}
<div class="graphGroup">
<Badge color="gray">Frequency Domain</Badge>
<div class="parameterContainer">
<Badge color="gray">Sample Rate: {freqSampleRate}</Badge>
<Badge color="gray">Chunk Size: {freqChunkSize}</Badge>
Expand All @@ -38,10 +45,23 @@
<LineChart
strChartID={sourceIdentifier + '-freq'}
aanYValues={aanFreqYValues}
YScale={0.00025}
YScale={0.000025}
/>
</div>
</div>
{/if}
{#if anAngles_deg.length !== 0}
<div class="graphGroup">
<Badge color="gray">Polar (Angle of Arrival)</Badge>
<div class="parameterContainer">

</div>
<PolarPlot
strChartID={sourceIdentifier + '-polar'}
anAngles_deg={anAngles_deg}
/>
</div>
{/if}
</div>
</div>

Expand All @@ -55,7 +75,7 @@
.graphGroup {
height: 100%;
width: 50%;
width: 33%;
padding: 10px;
}
.canvas {
Expand Down
9 changes: 8 additions & 1 deletion src/lib/StatusText.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { Button, Badge, Stack } from '@svelteuidev/core';

Check failure on line 3 in src/lib/StatusText.svelte

View workflow job for this annotation

GitHub Actions / lint

'Button' is defined but never used

Check failure on line 3 in src/lib/StatusText.svelte

View workflow job for this annotation

GitHub Actions / lint

'Stack' is defined but never used
var mapData = [];
$: Text = '';

Check failure on line 6 in src/lib/StatusText.svelte

View workflow job for this annotation

GitHub Actions / lint

'Text' is assigned a value but never used
Expand Down Expand Up @@ -106,5 +107,11 @@
</script>

<div>
{Text}
<Badge radius="md" size="xl" color="gray">Processing Queue Stats</Badge>
{#each mapData as value}
<!-- {#if data.display} -->
<Badge color="gray">{JSON.stringify(value.value.SystemInfo)}</Badge>
<!-- {/if} -->
{/each}
</div>

24 changes: 23 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { dev, browser } from '$app/environment';
import { inject } from '@vercel/analytics';
import StatusText from '$lib/StatusText.svelte';
// util
import { webVitals } from '$lib/vitals';
Expand Down Expand Up @@ -40,6 +41,27 @@

<main>
<Navbar />

<!-- +page.svelte is rendered in this <slot> -->
<slot />
<div class="left">
<slot />
</div>
<div class="right">
<StatusText />
</div>
</main>

<style>
.left {
flex-direction: row;
width: 80%;
height: 100%;
}
.right {
flex-direction: row;
width: 20%;
height: 100%;
}
</style>
43 changes: 40 additions & 3 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
let timeParsedData = null;
let TimeDatasets = [];
TimeWebSocket.addEventListener('message', async (event) => {
TimeWebSocket.addEventListener('message', async (event) => {
//console.log(endTime - startTime)
timeParsedData = JSON.parse(event.data);
// If a plot is not active do not process its data to save time
Expand Down Expand Up @@ -118,12 +118,12 @@
FreqWebSocket.addEventListener('close', (event) => {
console.log('WebSocket closed', event);
setTimeout(ConnectFreqWebSocket, 5000); // Attempt to reconnect after 1 second
});
FreqWebSocket.addEventListener('error', (error) => {
console.log('WebSocket error', error);
FreqWebSocket.close();
setTimeout(ConnectFreqWebSocket, 1000); // Attempt to reconnect after 1 second
});
let FreqParsedData = null;
Expand Down Expand Up @@ -151,13 +151,49 @@
});
}
let DirectionChunkSocket = null;
function ConnectDirectionChunkSocket() {
DirectionChunkSocket = new WebSocket('ws://localhost:10100/DataTypes/DirectionBinChunk');
DirectionChunkSocket.addEventListener('open', () => {
console.log('DirectionChunkSocket WebSocket connected');
});
DirectionChunkSocket.addEventListener('close', (event) => {
console.log('WebSocket closed', event);
});
DirectionChunkSocket.addEventListener('error', (error) => {
console.log('WebSocket error', error);
DirectionChunkSocket.close();
});
let PolarParsedData = null;
DirectionChunkSocket.addEventListener('message', async (event) => {
PolarParsedData = JSON.parse(event.data);
//If a plot is not active do not process its data to save time
if (!IsPlotActive(PolarParsedData['DirectionBinChunk']['SourceIdentifier'])) {
return;
}
updateItemInMap(PolarParsedData['DirectionBinChunk']['SourceIdentifier'], {
anAngles_deg: PolarParsedData['DirectionBinChunk']['DetectionAngles_deg'],
sourceIdentifier: PolarParsedData['DirectionBinChunk']['SourceIdentifier']
});
});
}
function closeWebSockets() {
if (TimeWebSocket) {
TimeWebSocket.close();
}
if (FreqWebSocket) {
FreqWebSocket.close();
}
if (DirectionChunkSocket) {
FreqWebSocket.close();
}
}
onDestroy(() => {
Expand All @@ -167,6 +203,7 @@
onMount(() => {
ConnectTimeWebSocket(); // Initial connection
ConnectFreqWebSocket(); // Initial connection
ConnectDirectionChunkSocket();
});
</script>

Expand Down Expand Up @@ -197,7 +234,7 @@
<div class="container">
<div class="spacer">
<Stack align="center" spacing="xs">
<Badge color="gray" size="xl" radius="lg">Device ID</Badge>
<Badge color="gray" size="xl" radius="lg">Active Sensors</Badge>
{#each mapData as data, i}
<div class="Button">
<Button
Expand Down

0 comments on commit b622cea

Please sign in to comment.