changeset 2422:62dc1b3644a0

collector client uses rdf types, not strings
author drewp@bigasterisk.com
date Tue, 21 May 2024 16:11:28 -0700
parents ac55319a2eac
children 4a5b37acd1f0
files web/calibrate/Light9Calibrate.ts web/collector/CollectorClient.ts
diffstat 2 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/web/calibrate/Light9Calibrate.ts	Tue May 21 16:10:39 2024 -0700
+++ b/web/calibrate/Light9Calibrate.ts	Tue May 21 16:11:28 2024 -0700
@@ -7,6 +7,8 @@
 import { FindSafeExposure } from "./FindSafeExposure";
 import { Light9Camera } from "./Light9Camera";
 import { XyPlot } from "./XyPlot";
+import { NamedNode } from "n3";
+import { showRoot } from "../show_specific";
 export { RdfdbSyncedGraph } from "../RdfdbSyncedGraph";
 export { Light9Camera } from "./Light9Camera";
 export { XyPlot } from "./XyPlot";
@@ -32,12 +34,16 @@
   collector: CollectorClient = new CollectorClient("calibrate");
   @query("light9-camera", true) cam?: Light9Camera;
   @query("xy-plot", true) plot?: XyPlot;
-  @state() device: string;
+  @state() device?: NamedNode;
+  @state() calibrationSession?: NamedNode;
   constructor() {
     super();
-    this.device = "http://light9.bigasterisk.com/theater/vet/device/parR3";
     getTopGraph().then((g) => {
       this.graph = g;
+      const U = this.graph.U();
+      this.calibrationSession = U(showRoot + "/calibration/session1");
+      this.device = U("dev:parR3");
+      this.graph.patchObject(this.calibrationSession, U("rdf:type"), U(":CalibrationSession"), this.calibrationSession);
     });
   }
 
@@ -46,7 +52,8 @@
       <h1>Calibrate</h1>
       <light9-camera></light9-camera>
 
-      <p>Device to calibrate: [ ${this.device} ]</p>
+      <p>Calibration session; [ ${this.calibrationSession?.value} ]</p>
+      <p>Device to calibrate: [ ${this.device?.value} ]</p>
 
       <ol>
         <li><button @click=${this.setToFull}>Set to full</button></li>
@@ -68,12 +75,14 @@
       btn.disabled = false;
     }
   }
+
   async setToFull(ev: MouseEvent) {
+    const U = this.graph.U();
     await this.withButtonSpinner(ev, async () => {
       this.collector.updateSettings([
         /// device,attr,value
-        [this.device, "http://light9.bigasterisk.com/color", "#ffffff"],
-        [this.device, "http://light9.bigasterisk.com/white", 1],
+        [this.device!, U(":color"), this.graph.Literal("#ffffff")],
+        [this.device!, U(":white"), this.graph.LiteralRoundedFloat(1)],
       ]);
     });
   }
@@ -84,17 +93,21 @@
       const expo = await algo.run();
     });
   }
+
   async setToZero(ev: MouseEvent) {
+    const U = this.graph.U();
     await this.withButtonSpinner(ev, async () => {
       this.collector.updateSettings([
-        [this.device, "http://light9.bigasterisk.com/color", "#000000"],
-        [this.device, "http://light9.bigasterisk.com/white", 0],
+        [this.device!, U(":color"), this.graph.Literal("#000000")],
+        [this.device!, U(":white"), this.graph.LiteralRoundedFloat(0)],
       ]);
     });
   }
+
   async markTare(ev: MouseEvent) {
     await this.withButtonSpinner(ev, async () => {});
   }
+
   async calibrateLoop(ev: MouseEvent) {
     await this.withButtonSpinner(ev, async () => {});
   }
--- a/web/collector/CollectorClient.ts	Tue May 21 16:10:39 2024 -0700
+++ b/web/collector/CollectorClient.ts	Tue May 21 16:11:28 2024 -0700
@@ -1,4 +1,6 @@
-type Settings = Array<[string,string,string|number]>;
+import { Literal, NamedNode } from "n3";
+
+type Settings = Array<[NamedNode,NamedNode,Literal]>;
 
 export class CollectorClient {
   private settings: Settings;
@@ -13,13 +15,14 @@
     }, 1000);
   }
   private async put() {
+    // todo: WS
     await fetch("/service/collector/attrs", {
       method: "PUT",
       body: JSON.stringify({
         client: this.clientName,
         clientSession: "unused",
         sendTime: Date.now() / 1000,
-        settings: this.settings,
+        settings: this.settings.map(([d,da,v]) => [d.value,da.value,v.value])
       }),
     });
   }