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