Mercurial > code > home > repos > homeauto
annotate service/wifi/src/index.ts @ 1679:f88ff1021ee0
checkpoint service/wifi
author | drewp@bigasterisk.com |
---|---|
date | Mon, 27 Sep 2021 23:02:33 -0700 |
parents | b267511ec4fc |
children |
rev | line source |
---|---|
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
1 // for the web page |
674
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
2 export { DomBind } from "@polymer/polymer/lib/elements/dom-bind.js"; |
678 | 3 export { StreamedGraph } from "streamed-graph"; |
674
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
4 |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
5 import { LitElement, property, html, customElement } from "lit-element"; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
6 |
679
6723f7ae8f34
refactor plain graph functions from lit-element
drewp@bigasterisk.com
parents:
678
diff
changeset
|
7 import { Literal, N3Store } from "n3"; |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
8 import { NamedNode, DataFactory } from "n3"; |
684
b39d24617a85
fixes for streamedgraph build and a surprise with multi-value wifiBands
drewp@bigasterisk.com
parents:
681
diff
changeset
|
9 const { namedNode, literal } = DataFactory; |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
10 |
744
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
11 import { VersionedGraph, labelFromUri, graphLiteral, graphUriValue } from "streamed-graph"; |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
12 import { style } from "./style"; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
13 |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
14 interface DevGroup { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
15 connectedToAp: NamedNode; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
16 wifiBand: NamedNode; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
17 devs: Array<Dev>; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
18 } |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
19 interface Dev { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
20 agoMin: number | undefined; |
677 | 21 ipAddress: Literal; // todo no one wants this literal. just make it string. |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
22 dhcpHostname: string; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
23 macAddress: Literal; |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
24 packetsPerSec: number; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
25 packetsPerSecDisplay: string; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
26 bytesPerSec: number; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
27 bytesPerSecDisplay: string; |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
28 } |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
29 const room = "http://projects.bigasterisk.com/room/"; |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
30 |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
31 function asString(x: Literal | undefined): string { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
32 if (x && x.value) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
33 return x.value; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
34 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
35 return "(unknown)"; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
36 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
37 |
674
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
38 @customElement("wifi-display") |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
39 class WifiDisplay extends LitElement { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
40 static get styles() { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
41 return [style]; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
42 } |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
43 |
677 | 44 @property({ type: Object }) |
674
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
45 graph!: VersionedGraph; |
673
f2215949c0c9
build adjustments. now seems to read streamedgraph correctly.
drewp@bigasterisk.com
parents:
diff
changeset
|
46 |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
47 connectedCallback() { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
48 super.connectedCallback(); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
49 const sg = this.ownerDocument!.querySelector("streamed-graph"); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
50 sg?.addEventListener("graph-changed", ((ev: CustomEvent) => { |
744
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
51 if (ev.detail!.value) { |
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
52 // todo: sometimes i get ev.detail.graph instead of ev.detail.value |
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
53 this.graph = ev.detail!.value as VersionedGraph; |
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
54 } |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
55 }) as EventListener); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
56 } |
674
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
57 |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
58 @property({ type: Boolean }) |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
59 showGroups = false; |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
60 |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
61 render() { |
744
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
62 if (!this.graph) { |
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
63 return html`loading...`; |
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
64 } |
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
65 const grouped = this.graphView(this.graph.store); |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
66 |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
67 return html` |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
68 <div class="report"> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
69 <table> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
70 ${Array.from(grouped.entries()).map((row: [string, DevGroup]) => { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
71 return this.renderGroup(row[0], row[1]); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
72 })} |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
73 </table> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
74 </div> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
75 `; |
674
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
76 } |
673
f2215949c0c9
build adjustments. now seems to read streamedgraph correctly.
drewp@bigasterisk.com
parents:
diff
changeset
|
77 |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
78 renderDevice(dev: Dev) { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
79 let agoReport = ""; |
680 | 80 let glow = 0; |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
81 if (dev.agoMin === undefined) { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
82 agoReport = "unknown"; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
83 } else { |
680 | 84 glow = Math.max(0, 1 - dev.agoMin! / 60); |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
85 agoReport = |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
86 dev.agoMin! < 360 |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
87 ? ` (${Math.ceil(dev.agoMin! * 10) / 10} minutes ago)` |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
88 : ""; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
89 } |
680 | 90 const ntopUrl = "https://bigasterisk.com/ntop/lua/host_details.lua"; |
91 const ntopLink = `${ntopUrl}?ifid=17&host=${dev.ipAddress.value}&page=flows`; | |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
92 return html` |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
93 <div class="dev" style="background: rgba(185, 5, 138, ${glow});"> |
677 | 94 <span class="mac">${dev.macAddress.value}</span> |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
95 <span class="ip" |
677 | 96 ><a href="http://${dev.ipAddress.value}/" |
97 >${dev.ipAddress.value}</a | |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
98 ></span |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
99 > |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
100 <span class="packets">${dev.packetsPerSecDisplay}</span> |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
101 <span class="bytes">${dev.bytesPerSecDisplay}</span> |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
102 <span class="hostname">${dev.dhcpHostname}</span> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
103 <span class="ago">${agoReport}</span> |
680 | 104 <span class="links"><a href="${ntopLink}">[flows]</a></span> |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
105 </div> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
106 `; |
674
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
107 } |
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
108 |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
109 renderGroup(key: string, group: DevGroup) { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
110 let label; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
111 if (key != "all") { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
112 label = labelFromUri( |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
113 group.connectedToAp, |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
114 "http://bigasterisk.com/mac/", |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
115 { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
116 "a0:40:a0:6f:96:d5": "Main router (d5)", |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
117 "8c:3b:ad:c4:8d:ce": "Downstairs satellite (ce)", |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
118 "a0:40:a0:6f:aa:f8": "Upstairs satellite (f8)", |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
119 }, |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
120 "unknown" |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
121 ); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
122 |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
123 label += labelFromUri( |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
124 group.wifiBand, |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
125 "http://projects.bigasterisk.com/room/wifiBand/", |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
126 { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
127 "5G": " 5G", |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
128 "2.4G": " 2.4G", |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
129 }, |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
130 "unknown" |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
131 ); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
132 } |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
133 |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
134 const devs = group.devs; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
135 function padIp(ip: string) { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
136 return ip.replace(/(\d+)/g, m => ("00" + m).slice(-3)); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
137 } |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
138 devs.sort((a, b) => { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
139 return padIp(a.ipAddress.value) > padIp(b.ipAddress.value) ? 1 : -1; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
140 }); |
674
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
141 return html` |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
142 <tr> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
143 <th>${label}</th> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
144 <td> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
145 <div>Devices:</div> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
146 ${devs.map(d => { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
147 return this.renderDevice(d); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
148 })} |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
149 </td> |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
150 </tr> |
674
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
151 `; |
2b9865bf1737
streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents:
673
diff
changeset
|
152 } |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
153 |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
154 addGroupedDev( |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
155 store: N3Store, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
156 grouped: Map<string, DevGroup>, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
157 devUri: NamedNode |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
158 ) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
159 const getAgoMin = (connected: Literal | undefined): number | undefined => { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
160 if (connected) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
161 const t = new Date(connected.value); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
162 const agoMs = Date.now() - t.valueOf(); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
163 return agoMs / 1000 / 60; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
164 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
165 return undefined; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
166 }; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
167 |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
168 const packetsPerSec = parseFloat( |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
169 graphLiteral(store, devUri, room + "packetsPerSec", "0").value |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
170 ); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
171 const bytesPerSec = parseFloat( |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
172 graphLiteral(store, devUri, room + "bytesPerSec", "0").value |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
173 ); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
174 |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
175 const row: Dev = { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
176 agoMin: getAgoMin(graphLiteral(store, devUri, room + "connected")), |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
177 ipAddress: graphLiteral(store, devUri, room + "ipAddress", "(unknown)"), |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
178 dhcpHostname: asString( |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
179 graphLiteral(store, devUri, room + "dhcpHostname") |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
180 ), |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
181 macAddress: graphLiteral(store, devUri, room + "macAddress"), |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
182 packetsPerSec: packetsPerSec, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
183 packetsPerSecDisplay: packetsPerSec + " P/s", |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
184 bytesPerSec: bytesPerSec, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
185 bytesPerSecDisplay: bytesPerSec + " B/s", |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
186 }; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
187 |
684
b39d24617a85
fixes for streamedgraph build and a surprise with multi-value wifiBands
drewp@bigasterisk.com
parents:
681
diff
changeset
|
188 let wifiBand; |
b39d24617a85
fixes for streamedgraph build and a surprise with multi-value wifiBands
drewp@bigasterisk.com
parents:
681
diff
changeset
|
189 try { |
b39d24617a85
fixes for streamedgraph build and a surprise with multi-value wifiBands
drewp@bigasterisk.com
parents:
681
diff
changeset
|
190 wifiBand = graphUriValue(store, devUri, room + "wifiBand"); |
b39d24617a85
fixes for streamedgraph build and a surprise with multi-value wifiBands
drewp@bigasterisk.com
parents:
681
diff
changeset
|
191 } catch (e) { |
b39d24617a85
fixes for streamedgraph build and a surprise with multi-value wifiBands
drewp@bigasterisk.com
parents:
681
diff
changeset
|
192 wifiBand = namedNode("multi"); // some have 5G and 2G? |
b39d24617a85
fixes for streamedgraph build and a surprise with multi-value wifiBands
drewp@bigasterisk.com
parents:
681
diff
changeset
|
193 } |
744
b267511ec4fc
fixes to TS and page build. remove some unused attempts at binding to <streamed-graph>
drewp@bigasterisk.com
parents:
684
diff
changeset
|
194 |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
195 const connectedToAp = graphUriValue(store, devUri, room + "connectedToAp"); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
196 if (!this.showGroups || connectedToAp) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
197 const key = this.showGroups |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
198 ? `${connectedToAp!.value}-${wifiBand!.value}` |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
199 : "all"; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
200 if (!grouped.has(key)) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
201 grouped.set(key, { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
202 connectedToAp: connectedToAp!, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
203 wifiBand: wifiBand!, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
204 devs: [], |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
205 }); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
206 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
207 grouped.get(key)!.devs.push(row); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
208 } else { |
681 | 209 console.log("row didn't get into any group:", row); |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
210 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
211 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
212 |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
213 graphView(store: N3Store): Map<string, DevGroup> { |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
214 const grouped: Map<string, DevGroup> = new Map(); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
215 store.forEach( |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
216 q => { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
217 const devUri: NamedNode = q.subject as NamedNode; |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
218 this.addGroupedDev(store, grouped, devUri); |
675
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
219 }, |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
220 null, |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
221 namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
222 namedNode(room + "NetworkedDevice"), |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
223 null |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
224 ); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
225 return grouped; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
226 } |
673
f2215949c0c9
build adjustments. now seems to read streamedgraph correctly.
drewp@bigasterisk.com
parents:
diff
changeset
|
227 } |