-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
923ea14
commit 101cd8c
Showing
16 changed files
with
562 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.IO; | ||
using System.Text.Json; | ||
|
||
[ApiController] | ||
[Route("api/settings")] | ||
public class SettingsController : ControllerBase | ||
{ | ||
private const string SettingsFilePath = "settings.json"; | ||
|
||
[HttpGet] | ||
public ActionResult<Settings> GetSettings() | ||
{ | ||
if (!System.IO.File.Exists(SettingsFilePath)) | ||
{ | ||
return new Settings(); | ||
} | ||
|
||
var json = System.IO.File.ReadAllText(SettingsFilePath); | ||
return JsonSerializer.Deserialize<Settings>(json); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult SaveSettings([FromBody] Settings settings) | ||
{ | ||
var json = JsonSerializer.Serialize(settings); | ||
System.IO.File.WriteAllText(SettingsFilePath, json); | ||
return Ok(); | ||
} | ||
} | ||
|
||
public class Settings | ||
{ | ||
public Updating Updating { get; set; } | ||
public Scanning Scanning { get; set; } | ||
public Counting Counting { get; set; } | ||
public Filtering Filtering { get; set; } | ||
public Calibration Calibration { get; set; } | ||
} | ||
|
||
public class Updating | ||
{ | ||
public bool AutoUpdate { get; set; } | ||
public bool PreRelease { get; set; } | ||
} | ||
|
||
public class Scanning | ||
{ | ||
public int? ForgetAfterMs { get; set; } | ||
} | ||
|
||
public class Counting | ||
{ | ||
public string IdPrefixes { get; set; } | ||
public double? StartCountingDistance { get; set; } | ||
public double? StopCountingDistance { get; set; } | ||
public int? IncludeDevicesAge { get; set; } | ||
} | ||
|
||
public class Filtering | ||
{ | ||
public string IncludeIds { get; set; } | ||
public string ExcludeIds { get; set; } | ||
public double? MaxReportDistance { get; set; } | ||
public double? EarlyReportDistance { get; set; } | ||
public int? SkipReportAge { get; set; } | ||
} | ||
|
||
public class Calibration | ||
{ | ||
public int? RssiAt1m { get; set; } | ||
public int? RssiAdjustment { get; set; } | ||
public double? AbsorptionFactor { get; set; } | ||
public int? IBeaconRssiAt1m { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.IO; | ||
using System.Text.Json; | ||
|
||
[ApiController] | ||
[Route("api/settings")] | ||
public class SettingsController : ControllerBase | ||
{ | ||
private const string SettingsFilePath = "settings.json"; | ||
|
||
[HttpGet] | ||
public ActionResult<Settings> GetSettings() | ||
{ | ||
if (!System.IO.File.Exists(SettingsFilePath)) | ||
{ | ||
return new Settings(); | ||
} | ||
|
||
var json = System.IO.File.ReadAllText(SettingsFilePath); | ||
return JsonSerializer.Deserialize<Settings>(json); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult SaveSettings([FromBody] Settings settings) | ||
{ | ||
var json = JsonSerializer.Serialize(settings); | ||
System.IO.File.WriteAllText(SettingsFilePath, json); | ||
return Ok(); | ||
} | ||
} | ||
|
||
public class Settings | ||
{ | ||
public UpdatingSettings Updating { get; set; } = new UpdatingSettings(); | ||
public ScanningSettings Scanning { get; set; } = new ScanningSettings(); | ||
public CountingSettings Counting { get; set; } = new CountingSettings(); | ||
public FilteringSettings Filtering { get; set; } = new FilteringSettings(); | ||
public CalibrationSettings Calibration { get; set; } = new CalibrationSettings(); | ||
} | ||
|
||
public class UpdatingSettings | ||
{ | ||
public bool? AutoUpdate { get; set; } | ||
public bool? PreRelease { get; set; } | ||
} | ||
|
||
public class ScanningSettings | ||
{ | ||
public int? ForgetAfterMs { get; set; } | ||
} | ||
|
||
public class CountingSettings | ||
{ | ||
public string IdPrefixes { get; set; } | ||
public double? StartCountingDistance { get; set; } | ||
public double? StopCountingDistance { get; set; } | ||
public int? IncludeDevicesAge { get; set; } | ||
} | ||
|
||
public class FilteringSettings | ||
{ | ||
public string IncludeIds { get; set; } | ||
public string ExcludeIds { get; set; } | ||
public double? MaxReportDistance { get; set; } | ||
public double? EarlyReportDistance { get; set; } | ||
public int? SkipReportAge { get; set; } | ||
} | ||
|
||
public class CalibrationSettings | ||
{ | ||
public int? RssiAt1m { get; set; } | ||
public int? RssiAdjustment { get; set; } | ||
public double? AbsorptionFactor { get; set; } | ||
public int? IBeaconRssiAt1m { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<script lang="ts"> | ||
import { calibration } from '$lib/stores'; | ||
import { RadioGroup, RadioItem } from '@skeletonlabs/skeleton'; | ||
import { popup } from '@skeletonlabs/skeleton'; | ||
function coloring(percent: number) { | ||
if (percent == null) { | ||
return ''; | ||
} | ||
return 'background-color: hsl(' + (240 - Math.min(Math.max(percent * 120, 0), 240)) + ', 50%, 50%)'; | ||
} | ||
function value(n1: any, data_point: number) { | ||
if (data_point === 0) { | ||
return n1 ? Number(Math.round(n1.percent * 100)) + '%' : null; | ||
} else if (data_point >= 1 && data_point <= 5) { | ||
let num; | ||
switch (data_point) { | ||
case 1: | ||
num = n1?.err; | ||
break; | ||
case 2: | ||
num = n1?.absorption; | ||
break; | ||
case 3: | ||
num = n1?.rx_adj_rssi; | ||
break; | ||
case 4: | ||
num = n1?.tx_ref_rssi; | ||
break; | ||
case 5: | ||
num = n1?.var; | ||
break; | ||
} | ||
return num !== null && num !== undefined ? Number(num.toPrecision(3)) : 'n/a'; | ||
} | ||
} | ||
let rxColumns: Array<string> = []; | ||
$: { | ||
let rx = new Set(Object.keys($calibration?.matrix ?? {})); | ||
Object.entries($calibration?.matrix ?? {}) | ||
.flatMap(([key, value]) => Object.keys(value)) | ||
.forEach((key) => rx.add(key)); | ||
rxColumns = new Array(...rx); | ||
} | ||
let data_point: number = 0; | ||
</script> | ||
|
||
{#if $calibration?.matrix} | ||
{#each Object.entries($calibration?.matrix) as [id1, n1] (id1)} | ||
{#each rxColumns as id2 (id2)} | ||
<div class="card variant-filled-secondary p-4" data-popup={'popup-' + id1 + '-' + id2}> | ||
{#if n1[id2]} | ||
Expected {@html Number(n1[id2].expected?.toPrecision(3))} - Actual {@html Number(n1[id2]?.actual?.toPrecision(3))} = Error {@html Number(n1[id2]?.err?.toPrecision(3))} | ||
{:else} | ||
No beacon Received in last 30 seconds | ||
{/if} | ||
<div class="arrow variant-filled-secondary" /> | ||
</div> | ||
{/each} | ||
{/each} | ||
{/if} | ||
|
||
<div class="card p-2"> | ||
{#if $calibration?.matrix} | ||
<header> | ||
<div class="flex justify-center p-2"> | ||
<RadioGroup active="variant-filled-primary" hover="hover:variant-soft-primary"> | ||
<RadioItem bind:group={data_point} name="justify" value={0}>Error %</RadioItem> | ||
<RadioItem bind:group={data_point} name="justify" value={1}>Error (m)</RadioItem> | ||
<RadioItem bind:group={data_point} name="justify" value={2}>Absorption</RadioItem> | ||
<RadioItem bind:group={data_point} name="justify" value={3}>Rx Rssi Adj</RadioItem> | ||
<RadioItem bind:group={data_point} name="justify" value={4}>Tx Rssi Ref</RadioItem> | ||
<RadioItem bind:group={data_point} name="justify" value={5}>Variance (m)</RadioItem> | ||
</RadioGroup> | ||
</div> | ||
</header> | ||
<section class="p-4 pt-0"> | ||
<table class="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
{#each rxColumns as id} | ||
<th>Rx: {@html id}</th> | ||
{/each} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#each Object.entries($calibration.matrix) as [id1, n1] (id1)} | ||
<tr> | ||
<td>Tx: {@html id1}</td> | ||
{#each rxColumns as id2 (id2)} | ||
{#if n1[id2]} | ||
<td use:popup={{ event: 'hover', target: 'popup-' + id1 + '-' + id2, placement: 'top' }} style={coloring(n1[id2]?.percent)}>{@html value(n1[id2], data_point)}</td> | ||
{:else} | ||
<td /> | ||
{/if} | ||
{/each} | ||
</tr> | ||
{/each} | ||
</tbody> | ||
</table> | ||
</section> | ||
{:else} | ||
<p>Loading...</p> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.