Mercurial > code > home > repos > homeauto
annotate service/wifi/src/index.ts @ 1481:b3ef0886d16c
fix glow
Ignore-this: 6f374683408f724d42abf3aaf7570e2b
darcs-hash:28dcc6f183715a865367974607abe390fa83c9db
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Mon, 06 Jan 2020 22:43:48 -0800 |
parents | ae023bba2104 |
children | 1c04c7dfbae6 |
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"; |
1480
ae023bba2104
refactor plain graph functions from lit-element
drewp <drewp@bigasterisk.com>
parents:
1479
diff
changeset
|
9 const { namedNode } = 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 console.log("wifidisplay connected"); |
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 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
|
52 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
|
53 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
|
54 console.log("wifidisplay got new graph", this.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
|
55 }) 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
|
56 } |
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
|
57 |
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
|
58 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
|
59 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
|
60 } |
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
|
61 |
1477
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
62 @property({ type: Boolean }) |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
63 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
|
64 |
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 render() { |
1477
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
66 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
|
67 |
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 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
|
69 <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
|
70 report at graph version ${this.graph.version} 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
|
71 ${Array.from(grouped.entries()).length} |
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 ${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
|
74 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
|
75 })} |
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
|
76 </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
|
77 </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
|
78 `; |
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
|
79 } |
1474
f91ba30b4f75
build adjustments. now seems to read streamedgraph correctly.
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
80 |
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
|
81 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
|
82 let agoReport = ""; |
1481 | 83 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
|
84 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
|
85 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
|
86 } else { |
1481 | 87 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
|
88 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
|
89 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
|
90 ? ` (${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
|
91 : ""; |
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 } |
1481 | 93 const ntopUrl = "https://bigasterisk.com/ntop/lua/host_details.lua"; |
94 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
|
95 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
|
96 <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
|
97 <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
|
98 <span class="ip" |
1478
2832e5c14c74
some type notes and cleanups
drewp <drewp@bigasterisk.com>
parents:
1477
diff
changeset
|
99 ><a href="http://${dev.ipAddress.value}/" |
2832e5c14c74
some type notes and cleanups
drewp <drewp@bigasterisk.com>
parents:
1477
diff
changeset
|
100 >${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
|
101 ></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 > |
1477
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
103 <span class="packets">${dev.packetsPerSecDisplay}</span> |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
104 <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
|
105 <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
|
106 <span class="ago">${agoReport}</span> |
1481 | 107 <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
|
108 </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
|
109 `; |
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
|
110 } |
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
|
111 |
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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 "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
|
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 "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
|
120 "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
|
121 "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
|
122 }, |
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 "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
|
124 ); |
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 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
|
127 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
|
128 "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
|
129 { |
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 "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
|
131 "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
|
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 "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
|
134 ); |
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 } |
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 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
|
138 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
|
139 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
|
140 } |
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 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
|
142 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
|
143 }); |
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
|
144 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
|
145 <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
|
146 <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
|
147 <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
|
148 <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
|
149 ${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
|
150 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
|
151 })} |
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 </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
|
153 </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
|
154 `; |
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
|
155 } |
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
|
156 |
1477
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
157 addGroupedDev( |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
158 store: N3Store, |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
159 grouped: Map<string, DevGroup>, |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
160 devUri: NamedNode |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
161 ) { |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
162 const getAgoMin = (connected: Literal | undefined): number | undefined => { |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
163 if (connected) { |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
164 const t = new Date(connected.value); |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
165 const agoMs = Date.now() - t.valueOf(); |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
166 return agoMs / 1000 / 60; |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
167 } |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
168 return undefined; |
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 |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
171 const packetsPerSec = parseFloat( |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
172 graphLiteral(store, devUri, room + "packetsPerSec", "0").value |
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 bytesPerSec = parseFloat( |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
175 graphLiteral(store, devUri, room + "bytesPerSec", "0").value |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
176 ); |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
177 |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
178 const row: Dev = { |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
179 agoMin: getAgoMin(graphLiteral(store, devUri, room + "connected")), |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
180 ipAddress: graphLiteral(store, devUri, room + "ipAddress", "(unknown)"), |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
181 dhcpHostname: asString( |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
182 graphLiteral(store, devUri, room + "dhcpHostname") |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
183 ), |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
184 macAddress: graphLiteral(store, devUri, room + "macAddress"), |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
185 packetsPerSec: packetsPerSec, |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
186 packetsPerSecDisplay: packetsPerSec + " P/s", |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
187 bytesPerSec: bytesPerSec, |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
188 bytesPerSecDisplay: bytesPerSec + " B/s", |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
189 }; |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
190 |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
191 const wifiBand = graphUriValue(store, devUri, room + "wifiBand"); |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
192 const connectedToAp = graphUriValue(store, devUri, room + "connectedToAp"); |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
193 if (!this.showGroups || connectedToAp) { |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
194 const key = this.showGroups |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
195 ? `${connectedToAp!.value}-${wifiBand!.value}` |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
196 : "all"; |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
197 if (!grouped.has(key)) { |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
198 grouped.set(key, { |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
199 connectedToAp: connectedToAp!, |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
200 wifiBand: wifiBand!, |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
201 devs: [], |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
202 }); |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
203 } |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
204 grouped.get(key)!.devs.push(row); |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
205 } else { |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
206 console.log("lost row", row); |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
207 } |
383e32841b35
now roughly works. shows updates. only some workarounds.
drewp <drewp@bigasterisk.com>
parents:
1476
diff
changeset
|
208 } |
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 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 }, |
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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 ); |
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 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
|
223 } |
1474
f91ba30b4f75
build adjustments. now seems to read streamedgraph correctly.
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
224 } |