Skip to content

Commit dd2680e

Browse files
authored
Merge pull request #15 from nolze/update/bssid
Use BSSID
2 parents 3123056 + 51a861b commit dd2680e

4 files changed

Lines changed: 66 additions & 21 deletions

File tree

tests/test_series.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import types
2-
31
import tiny_wifi_analyzer.series as series
42

53

6-
def make_net(ssid: str, rssi: int, band: int, ch: int, width: int):
7-
ch_obj = types.SimpleNamespace(
8-
channel_band=band, channel_number=ch, channel_width=width
9-
)
10-
return types.SimpleNamespace(ssid=ssid, rssi=rssi, channel=ch_obj)
4+
def make_net(ssid: str, bssid: str, rssi: int, band: int, ch: int, width: int):
5+
ch_obj = series._Chan(channel_band=band, channel_number=ch, channel_width=width)
6+
return series._Net(ssid=ssid, bssid=bssid, rssi=rssi, channel=ch_obj)
117

128

139
def test_channel_half_span_for_width():
@@ -20,20 +16,20 @@ def test_channel_half_span_for_width():
2016

2117

2218
def test_to_series_24ghz_basic_triangle():
23-
nw = make_net("Test", -50, series.CHANNEL_BAND_24, 6, 20)
19+
nw = make_net("Test", "ff:ff:ff:ff", -50, series.CHANNEL_BAND_24, 6, 20)
2420
s = series.to_series([nw])
2521
assert len(s) == 1
2622
name = s[0]["name"]
2723
pts = s[0]["data"]
28-
assert name == "Test"
24+
assert name == "ff:ff:ff:ff"
2925
# left, apex, right
3026
assert pts[0] == [4, -100]
3127
assert pts[1] == [6, -50]
3228
assert pts[2] == [8, -100]
3329

3430

3531
def test_to_series_24ghz_clamped():
36-
nw = make_net("Edge", -40, series.CHANNEL_BAND_24, 1, 40)
32+
nw = make_net("Edge", "ff:ff:ff:ff", -40, series.CHANNEL_BAND_24, 1, 40)
3733
s = series.to_series([nw])
3834
pts = s[0]["data"]
3935
# 40 MHz => half span 4, but left clamps to 1
@@ -43,7 +39,7 @@ def test_to_series_24ghz_clamped():
4339

4440

4541
def test_to_series_5ghz_width_mapping():
46-
nw = make_net("W80", -60, series.CHANNEL_BAND_5, 100, 80)
42+
nw = make_net("W80", "ff:ff:ff:ff", -60, series.CHANNEL_BAND_5, 100, 80)
4743
s = series.to_series([nw])
4844
pts = s[0]["data"]
4945
# 80 MHz => half span 8
@@ -53,7 +49,7 @@ def test_to_series_5ghz_width_mapping():
5349

5450

5551
def test_to_series_6ghz_clamped_right():
56-
nw = make_net("Big", -55, series.CHANNEL_BAND_6, 230, 160)
52+
nw = make_net("Big", "ff:ff:ff:ff", -55, series.CHANNEL_BAND_6, 230, 160)
5753
s = series.to_series([nw])
5854
pts = s[0]["data"]
5955
# 160 MHz => half 16; right clamps to max (233)

tiny_wifi_analyzer/__main__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,26 @@ def update(window, supported_bands):
141141
nws24 = sorted(nws24, key=lambda x: x.channel.channel_number)
142142
series24 = to_series(nws24)
143143
series_json24 = json.dumps(series24)
144-
window.evaluate_js("window.chart24.updateSeries({})".format(series_json24))
144+
# window.evaluate_js("window.chart24.updateSeries({})".format(series_json24))
145+
window.evaluate_js(
146+
"window.updateChart('{}',{})".format("24", series_json24)
147+
)
145148

146149
if supported_bands["5"]:
147150
nws5 = filter(lambda x: x.channel.channel_band == CHANNEL_BAND_5, nws)
148151
nws5 = sorted(nws5, key=lambda x: x.channel.channel_number)
149152
series5 = to_series(nws5)
150153
series_json5 = json.dumps(series5)
151-
window.evaluate_js("window.chart5.updateSeries({})".format(series_json5))
154+
# window.evaluate_js("window.chart5.updateSeries({})".format(series_json5))
155+
window.evaluate_js("window.updateChart('{}',{})".format("5", series_json5))
152156

153157
if supported_bands["6"]:
154158
nws6 = filter(lambda x: x.channel.channel_band == CHANNEL_BAND_6, nws)
155159
nws6 = sorted(nws6, key=lambda x: x.channel.channel_number)
156160
series6 = to_series(nws6)
157161
series_json6 = json.dumps(series6)
158-
window.evaluate_js("window.chart6.updateSeries({})".format(series_json6))
162+
# window.evaluate_js("window.chart6.updateSeries({})".format(series_json6))
163+
window.evaluate_js("window.updateChart('{}',{})".format("6", series_json6))
159164

160165
except queue.Empty:
161166
# nothing to do this tick

tiny_wifi_analyzer/series.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ class _Chan:
5252
@dataclass
5353
class _Net:
5454
ssid: str
55+
bssid: str
5556
rssi: int
5657
channel: _Chan
5758

5859

59-
def to_series(nws: List[object]) -> List[dict]:
60+
def to_series(nws: List[_Net]) -> List[dict]:
6061
"""Convert networks to ApexCharts series data with correct spans.
6162
6263
Expects items resembling PyNetwork:
6364
- .ssid: str
65+
_ .bssid: str
6466
- .rssi: int
6567
- .channel.channel_band: int
6668
- .channel.channel_number: int
@@ -77,7 +79,10 @@ def to_series(nws: List[object]) -> List[dict]:
7779
right = _clamp_channel(center + half, band)
7880
series.append(
7981
{
80-
"name": nw.ssid,
82+
# "name": nw.ssid,
83+
# "bssid": nw.bssid,
84+
"name": nw.bssid,
85+
"ssid": nw.ssid,
8186
"data": [[left, -100], [center, int(nw.rssi)], [right, -100]],
8287
}
8388
)

view-src/index.html

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@
3030
.annotation {
3131
font-family: sans-serif;
3232
}
33+
34+
rect.legend-mouseover-inactive,
35+
.legend-mouseover-inactive rect,
36+
.legend-mouseover-inactive path,
37+
.legend-mouseover-inactive circle,
38+
.legend-mouseover-inactive line,
39+
.legend-mouseover-inactive text.apexcharts-yaxis-title-text,
40+
.legend-mouseover-inactive text.apexcharts-yaxis-label {
41+
transition: 0.15s ease all;
42+
opacity: 0.1 !important;
43+
}
44+
45+
.legend-mouseover-inactive .apexcharts-data-labels {
46+
opacity: 0 !important;
47+
}
3348
</style>
3449
</head>
3550

@@ -46,9 +61,10 @@
4661
const CHANNEL_NUMBER_MAX_5 = 170;
4762
const CHANNEL_NUMBER_MAX_6 = 233;
4863

64+
let rawSeriesData = {};
4965
let lastZoom = {};
5066

51-
function makeOptions(bandName, channels) {
67+
function makeOptions(bandId, bandName, channels) {
5268
const options = {
5369
series: [],
5470
chart: {
@@ -161,10 +177,17 @@
161177
formatter: (seriesName, { seriesIndex, w }) => {
162178
const yValue = w.config.series[seriesIndex].data[1][1];
163179
const xValue = w.config.series[seriesIndex].data[1][0];
180+
let ssid = rawSeriesData[bandId][seriesIndex].ssid;
181+
if (ssid === null) ssid = "n/a";
182+
const bssid = rawSeriesData[bandId][seriesIndex].name;
164183
return [
165184
`Channel: ${xValue} RSSI: ${yValue}dBm`,
166185
"<br>",
167-
`<b>${seriesName}</b>`,
186+
ssid != "n/a"
187+
? `<b>${ssid}</b>`
188+
: `<b style="color:#888;">${ssid}</b>`,
189+
"<br>",
190+
`<span style="font-size:0.9em;color:#888;">${bssid}</span>`,
168191
];
169192
},
170193
},
@@ -211,9 +234,11 @@
211234
enabled: true,
212235
formatter: (val, { seriesIndex, dataPointIndex, w }) => {
213236
if (val === -100) return "";
214-
const name = w.config.series[seriesIndex].name;
237+
// const ssid = w.config.series[seriesIndex].ssid;
238+
const ssid = rawSeriesData[bandId][seriesIndex].ssid;
215239
const ch = w.config.series[seriesIndex].data[1][0];
216-
return `${ch} ${name}`;
240+
if (ssid === null) return `${ch} n/a`;
241+
return `${ch} ${ssid}`;
217242
},
218243
},
219244
markers: {
@@ -274,6 +299,7 @@
274299

275300
if (bands["24"]) {
276301
const options24 = makeOptions(
302+
"24",
277303
"2.4GHz",
278304
[...Array(CHANNEL_NUMBER_MAX_24).keys()].map((v) => v + 1),
279305
);
@@ -287,6 +313,7 @@
287313

288314
if (bands["5"]) {
289315
const options5 = makeOptions(
316+
"5",
290317
"5GHz",
291318
[...Array(CHANNEL_NUMBER_MAX_5).keys()].map((v) => v + 1),
292319
);
@@ -300,6 +327,7 @@
300327

301328
if (bands["6"]) {
302329
const options6 = makeOptions(
330+
"6",
303331
"6GHz",
304332
[...Array(CHANNEL_NUMBER_MAX_6).keys()].map((v) => v + 1),
305333
);
@@ -311,6 +339,17 @@
311339
chart6.render();
312340
}
313341
};
342+
343+
window.updateChart = (bandId, series) => {
344+
if (window[`chart${bandId}`]) {
345+
rawSeriesData[bandId] = series;
346+
try {
347+
window[`chart${bandId}`].updateSeries(series);
348+
} catch (e) {
349+
console.error("Failed to update series", e);
350+
}
351+
}
352+
};
314353
</script>
315354
</body>
316355
</html>

0 commit comments

Comments
 (0)