annotate service/wifi/src/index.ts @ 675:9ae34280218b

kind of running with lit-element and polymer together. lots of data missing from table still Ignore-this: db24e7b633929b01430b0794c1a065dc
author drewp@bigasterisk.com
date Sun, 05 Jan 2020 23:18:27 -0800
parents 2b9865bf1737
children 4bd77a9548d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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";
2b9865bf1737 streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents: 673
diff changeset
3
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
4 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
5
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 import { Literal, Term, N3Store, Util } from "n3";
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
7 import { NamedNode, DataFactory } from "n3";
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 const { literal, quad, namedNode } = DataFactory;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
9
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 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
11 export { StreamedGraph } 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";
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
13
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
14 interface DevGroup {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
15 connectedToAp: NamedNode;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
16 wifiBand: NamedNode;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
17 devs: Array<Dev>;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
18 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
19 interface Dev {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
20 agoMin: number | undefined;
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 ipAddress: Literal;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
22 dhcpHostname: string;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
23 macAddress: Literal;
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 packetsPerSec: string; //number; todo
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
25 bytesPerSec: string; //number;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
26 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
27
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
28 // workaround for uris that don't have good labels in the 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
29 function 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
30 uri: 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
31 prefix: 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
32 tailsToLabels: any,
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
33 defaultLabel: 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
34 ) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
35 let label = defaultLabel === undefined ? uri.value : defaultLabel;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
36 Object.entries(tailsToLabels).forEach(([tail, useLabel]) => {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
37 if (uri.equals(namedNode(prefix + tail))) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
38 label = useLabel as 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
39 }
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 });
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
41 return 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
42 }
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
43
2b9865bf1737 streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents: 673
diff changeset
44 @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
45 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
46 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
47 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
48 }
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
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 @property({
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 type: Object,
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 // observer: WifiDisplay.prototype.onGraphChanged,
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 })
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
54 graph!: VersionedGraph;
673
f2215949c0c9 build adjustments. now seems to read streamedgraph correctly.
drewp@bigasterisk.com
parents:
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 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
57 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
58 console.log("wifidisplay connected");
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 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
60 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
61 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
62 console.log("wifidisplay got new graph", this.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
63 }) 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
64 }
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
65
675
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
66 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
67 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
68 }
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
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 @property({ type: Object }) //no longer a prop?
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 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
72
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
73 render() {
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 const grouped = this.graphView(this.graph.store!, false);
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
75
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
76 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
77 <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
78 report at graph version ${this.graph.version} 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
79 ${Array.from(grouped.entries()).length}
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 <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
81 ${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
82 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
83 })}
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 </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
85 </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
86 `;
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
87 }
673
f2215949c0c9 build adjustments. now seems to read streamedgraph correctly.
drewp@bigasterisk.com
parents:
diff changeset
88
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
89 onGraphChanged(val: VersionedGraph, old: 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
90 console.log("new graph value", this.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
91 this.grouped = this.graphView((val as VersionedGraph).store!, false);
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 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
93
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 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
95 let 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
96 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
97 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
98 } else {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
99 const glow = Math.max(0, 1 - dev.agoMin! / 60);
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
100 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
101 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
102 ? ` (${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
103 : "";
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 }
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 const glow = ""; //todo
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
106 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
107 <div class="dev" style="background: rgba(185, 5, 138, ${glow});">
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 <span class="mac">${dev.macAddress && dev.macAddress.value}</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
109 <span class="ip"
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 ><a href="http://${dev.ipAddress && dev.ipAddress.value}/"
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 >${dev.ipAddress && dev.ipAddress.value}</a
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 ></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
113 >
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 <span class="packets">${dev.packetsPerSec}</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
115 <span class="bytes">${dev.bytesPerSec}</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
116 <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
117 <span class="ago">${agoReport}</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
118 <span class="links">
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 <a
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 href="https://bigasterisk.com/ntop/lua/host_details.lua?ifid=17&amp;host=${dev.ipAddress &&
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 dev.ipAddress.value}&amp;page=flows"
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 >[flows]</a
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 >
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 </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
125 </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
126 `;
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
127 }
2b9865bf1737 streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents: 673
diff changeset
128
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
129 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
130 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
131 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
132 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
133 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
134 "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
135 {
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 "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
137 "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
138 "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
139 },
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
140 "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
141 );
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
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 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
144 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
145 "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
146 {
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 "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
148 "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
149 },
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
150 "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
151 );
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 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
153
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
154 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
155 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
156 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
157 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
158 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
159 return 0; //todo
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
160 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
161 });
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
162 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
163 <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
164 <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
165 <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
166 <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
167 ${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
168 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
169 })}
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
170 </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
171 </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
172 `;
2b9865bf1737 streamed-graph finally imports and builds. polymer bindings don't work in a <dom-bind> though
drewp@bigasterisk.com
parents: 673
diff changeset
173 }
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
174
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
175 graphView(store: N3Store, showGroups: boolean): Map<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
176 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
177 const room = "http://projects.bigasterisk.com/room/";
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
178 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
179 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
180 const devUri: NamedNode = q.subject as 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
181
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
182 const graphLiteral = (
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
183 store: N3Store,
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
184 devUri: 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
185 pred: 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
186 notFoundResult?: 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
187 ): Literal => {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
188 const keep: Array<Literal> = [];
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
189 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
190 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
191 if (!Util.isLiteral(q.object)) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
192 throw new Error("non literal found");
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
193 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
194 keep.push(q.object as Literal);
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
195 },
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
196 devUri,
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
197 namedNode(pred),
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
198 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
199 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
200 );
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
201 if (keep.length == 0) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
202 return literal(notFoundResult || "(missing)");
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
203 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
204 if (keep.length == 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
205 return keep[0];
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
206 }
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 throw new Error("found multiple matches for pred");
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 };
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
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 getAgoMin = (
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
211 connected: Literal | 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
212 ): number | 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
213 if (connected) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
214 const t = new Date(connected.value);
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 const agoMs = Date.now() - t.valueOf();
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 return agoMs / 1000 / 60;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
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 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
219 };
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
220
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
221 const asString = (x: Literal | undefined): 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
222 if (x && x.value) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
223 return x.value;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
224 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
225 return "(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
226 };
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
227 const row: 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
228 agoMin: getAgoMin(
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
229 literal("2020-01-01") // graphLiteral(store, devUri, room + "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
230 ),
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
231 ipAddress: graphLiteral(
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
232 store,
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
233 devUri,
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
234 room + "ipAddress",
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
235 "(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
236 ),
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
237 dhcpHostname: asString(
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
238 graphLiteral(store, devUri, room + "dhcpHostname")
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
239 ),
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
240 macAddress: graphLiteral(store, devUri, room + "macAddress"),
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
241 packetsPerSec:
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
242 graphLiteral(store, devUri, room + "packetsPerSec", "? ").value +
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
243 " P/s", //number; todo
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
244 bytesPerSec:
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
245 graphLiteral(store, devUri, room + "bytesPerSec", "? ").value +
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
246 "B/s", //number;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
247 };
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
248 if (row.dhcpHostname && (row.dhcpHostname as any).value) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
249 row.dhcpHostname = (row.dhcpHostname as any).value;
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
250 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
251 if (!showGroups || (row as any).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
252 const key = showGroups
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
253 ? `${(row as any).connectedToAp.toNT()}-${(row as any).wifiBand.toNT()}`
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
254 : "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
255 if (!grouped.has(key)) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
256 grouped.set(key, {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
257 connectedToAp: (row as any).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
258 wifiBand: (row as any).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
259 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
260 });
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
261 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
262 grouped.get(key)!.devs.push(row);
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
263 } else {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
264 console.log("lost row", row);
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
265 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
266
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
267 if (row.bytesPerSec) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
268 row.bytesPerSec = row.bytesPerSec.valueOf() + " B/s";
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
269 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
270 if (row.packetsPerSec) {
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
271 row.packetsPerSec = row.packetsPerSec.valueOf() + " p/s";
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
272 }
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
273 },
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
274 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
275 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
276 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
277 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
278 );
9ae34280218b kind of running with lit-element and polymer together. lots of data missing from table still
drewp@bigasterisk.com
parents: 674
diff changeset
279 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
280 }
673
f2215949c0c9 build adjustments. now seems to read streamedgraph correctly.
drewp@bigasterisk.com
parents:
diff changeset
281 }