Mercurial > code > home > repos > homeauto
annotate service/wifi/src/index.ts @ 681:1c04c7dfbae6
logging cleanup
Ignore-this: 1d6636766a8496f285d9d3578e9ba331
author | drewp@bigasterisk.com |
---|---|
date | Mon, 06 Jan 2020 22:46:02 -0800 |
parents | 8a49457a9737 |
children | b39d24617a85 |
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"; |
679
6723f7ae8f34
refactor plain graph functions from lit-element
drewp@bigasterisk.com
parents:
678
diff
changeset
|
9 const { namedNode } = 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 |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
11 import { VersionedGraph } from "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
|
12 import { style } from "./style"; |
679
6723f7ae8f34
refactor plain graph functions from lit-element
drewp@bigasterisk.com
parents:
678
diff
changeset
|
13 import { labelFromUri, graphLiteral, graphUriValue } from "./graph_access"; |
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
|
14 |
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 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
|
16 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
|
17 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
|
18 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
|
19 } |
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 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
|
21 agoMin: number | undefined; |
677 | 22 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
|
23 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
|
24 macAddress: Literal; |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
25 packetsPerSec: number; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
26 packetsPerSecDisplay: string; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
27 bytesPerSec: number; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
28 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
|
29 } |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
30 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
|
31 |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
32 function asString(x: Literal | undefined): string { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
33 if (x && x.value) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
34 return x.value; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
35 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
36 return "(unknown)"; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
37 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
38 |
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
|
39 @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
|
40 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
|
41 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
|
42 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
|
43 } |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
44 |
677 | 45 @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
|
46 graph!: VersionedGraph; |
673
f2215949c0c9
build adjustments. now seems to read streamedgraph correctly.
drewp@bigasterisk.com
parents:
diff
changeset
|
47 |
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
|
48 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 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
|
50 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
|
51 sg?.addEventListener("graph-changed", ((ev: CustomEvent) => { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
52 this.graph = ev.detail!.value as VersionedGraph; |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
53 }) 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
|
54 } |
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
|
55 |
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
|
56 static get observers() { |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
57 return ["onGraphChanged(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
|
58 } |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
59 |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
60 @property({ type: Boolean }) |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
61 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
|
62 |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
63 render() { |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
64 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
|
65 |
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 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
|
67 <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
|
68 <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
|
69 ${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
|
70 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
|
71 })} |
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 </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
|
73 </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
|
74 `; |
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
|
75 } |
673
f2215949c0c9
build adjustments. now seems to read streamedgraph correctly.
drewp@bigasterisk.com
parents:
diff
changeset
|
76 |
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
|
77 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
|
78 let agoReport = ""; |
680 | 79 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
|
80 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
|
81 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
|
82 } else { |
680 | 83 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
|
84 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
|
85 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
|
86 ? ` (${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
|
87 : ""; |
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 } |
680 | 89 const ntopUrl = "https://bigasterisk.com/ntop/lua/host_details.lua"; |
90 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
|
91 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
|
92 <div class="dev" style="background: rgba(185, 5, 138, ${glow});"> |
677 | 93 <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
|
94 <span class="ip" |
677 | 95 ><a href="http://${dev.ipAddress.value}/" |
96 >${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
|
97 ></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
|
98 > |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
99 <span class="packets">${dev.packetsPerSecDisplay}</span> |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
100 <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
|
101 <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
|
102 <span class="ago">${agoReport}</span> |
680 | 103 <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
|
104 </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
|
105 `; |
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
|
106 } |
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 |
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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 "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
|
114 { |
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 "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
|
116 "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
|
117 "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
|
118 }, |
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 "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
|
120 ); |
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 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
|
123 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
|
124 "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
|
125 { |
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 "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
|
127 "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
|
128 }, |
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 "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
|
130 ); |
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 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
|
134 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
|
135 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
|
136 } |
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 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
|
138 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
|
139 }); |
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
|
140 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
|
141 <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
|
142 <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
|
143 <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
|
144 <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
|
145 ${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
|
146 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
|
147 })} |
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 </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
|
149 </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
|
150 `; |
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 } |
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
|
152 |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
153 addGroupedDev( |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
154 store: N3Store, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
155 grouped: Map<string, DevGroup>, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
156 devUri: NamedNode |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
157 ) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
158 const getAgoMin = (connected: Literal | undefined): number | undefined => { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
159 if (connected) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
160 const t = new Date(connected.value); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
161 const agoMs = Date.now() - t.valueOf(); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
162 return agoMs / 1000 / 60; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
163 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
164 return undefined; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
165 }; |
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 const packetsPerSec = parseFloat( |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
168 graphLiteral(store, devUri, room + "packetsPerSec", "0").value |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
169 ); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
170 const bytesPerSec = parseFloat( |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
171 graphLiteral(store, devUri, room + "bytesPerSec", "0").value |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
172 ); |
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 const row: Dev = { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
175 agoMin: getAgoMin(graphLiteral(store, devUri, room + "connected")), |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
176 ipAddress: graphLiteral(store, devUri, room + "ipAddress", "(unknown)"), |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
177 dhcpHostname: asString( |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
178 graphLiteral(store, devUri, room + "dhcpHostname") |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
179 ), |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
180 macAddress: graphLiteral(store, devUri, room + "macAddress"), |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
181 packetsPerSec: packetsPerSec, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
182 packetsPerSecDisplay: packetsPerSec + " P/s", |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
183 bytesPerSec: bytesPerSec, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
184 bytesPerSecDisplay: bytesPerSec + " B/s", |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
185 }; |
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 const wifiBand = graphUriValue(store, devUri, room + "wifiBand"); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
188 const connectedToAp = graphUriValue(store, devUri, room + "connectedToAp"); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
189 if (!this.showGroups || connectedToAp) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
190 const key = this.showGroups |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
191 ? `${connectedToAp!.value}-${wifiBand!.value}` |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
192 : "all"; |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
193 if (!grouped.has(key)) { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
194 grouped.set(key, { |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
195 connectedToAp: connectedToAp!, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
196 wifiBand: wifiBand!, |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
197 devs: [], |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
198 }); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
199 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
200 grouped.get(key)!.devs.push(row); |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
201 } else { |
681 | 202 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
|
203 } |
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
204 } |
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 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
|
207 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
|
208 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
|
209 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
|
210 const devUri: NamedNode = q.subject as NamedNode; |
676
4bd77a9548d6
now roughly works. shows updates. only some workarounds.
drewp@bigasterisk.com
parents:
675
diff
changeset
|
211 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
|
212 }, |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 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
|
217 ); |
9ae34280218b
kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents:
674
diff
changeset
|
218 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
|
219 } |
673
f2215949c0c9
build adjustments. now seems to read streamedgraph correctly.
drewp@bigasterisk.com
parents:
diff
changeset
|
220 } |