(data)
| 3028 | + `<p class="sub" style="margin-top:6px">Generated by Ragnar's AI assistant from the scan above. Advisory only.</p>`; |
| 3029 | } |
| 3030 | |
| 3031 | function wifiExportReport() { |
| 3032 | const d = _wifiState.data; |
| 3033 | // Coverage stats from the current heatmap metric. |
| 3034 | const samples = (_wifiHm.data && _wifiHm.data.samples) || []; |
| 3035 | const vals = samples.map(_wifiHmValue).filter(v => v != null); |
| 3036 | const mName = (_WIFI_HM_METRICS[_wifiHm.metric] || {}).unit || ''; |
| 3037 | let cov = ''; |
| 3038 | if (vals.length) { |
| 3039 | const mn = Math.min(...vals), mx = Math.max(...vals), av = vals.reduce((a, b) => a + b, 0) / vals.length; |
| 3040 | cov = `<p><b>${samples.length}</b> survey points · ${_wifiHm.metric.toUpperCase()} min <b>${mn.toFixed(1)}</b> / avg <b>${av.toFixed(1)}</b> / max <b>${mx.toFixed(1)}</b> ${mName}</p>`; |
| 3041 | } |
| 3042 | // Design / build plan summary (walls, columns, planned mesh nodes). |
| 3043 | let plan = ''; |
| 3044 | const pWalls = _wifiHm.walls || [], pCols = _wifiHm.columns || [], pAps = _wifiHm.predictAps || []; |
| 3045 | if (pWalls.length || pCols.length || pAps.length) { |
| 3046 | const tally = (arr) => { |
| 3047 | const m = {}; arr.forEach(o => { const k = o.material || 'wall'; m[k] = (m[k] || 0) + 1; }); |
| 3048 | return Object.keys(m).map(k => `${m[k]}× ${_esc(k)}`).join(', '); |
| 3049 | }; |
| 3050 | plan = '<ul>'; |
| 3051 | if (pAps.length) plan += `<li><b>${pAps.length}</b> planned AP node${pAps.length > 1 ? 's' : ''} (predictive mesh)</li>`; |
| 3052 | if (pWalls.length) plan += `<li><b>${pWalls.length}</b> wall${pWalls.length > 1 ? 's' : ''}: ${tally(pWalls)}</li>`; |
| 3053 | if (pCols.length) plan += `<li><b>${pCols.length}</b> column${pCols.length > 1 ? 's' : ''}: ${tally(pCols)}</li>`; |
| 3054 | plan += '</ul>'; |
| 3055 | } |
| 3056 | // Heatmap image, if drawn. |
| 3057 | let img = ''; |
| 3058 | try { |
| 3059 | const cv = document.getElementById('wifi-heatmap'); |
| 3060 | if (cv && (samples.length || _wifiHm.floorplan)) img = `<img src="${cv.toDataURL('image/png')}" style="max-width:100%;border:1px solid #ccc;border-radius:6px">`; |
| 3061 | } catch (e) { /* tainted canvas (cross-origin floorplan) — skip image */ } |
| 3062 | // Band summary. |
| 3063 | let bands = ''; |
| 3064 | if (d && d.spectrum) { |
| 3065 | bands = '<ul>' + Object.keys(d.spectrum).sort().map(b => { |
| 3066 | const s = d.spectrum[b]; |
| 3067 | return `<li><b>${b} GHz</b>: ${s.ap_count} APs · ${_esc(s.rating)} · best ch ${(s.recommend || []).join(', ')}</li>`; |
| 3068 | }).join('') + '</ul>'; |
| 3069 | } |
| 3070 | // Interference. |
| 3071 | let intf = ''; |
| 3072 | if (d && d.interference) { |
| 3073 | const co = d.interference.co_channel || [], ov = d.interference.adjacent_overlap || []; |
| 3074 | if (co.length) intf += '<p><b>Co-channel:</b> ' + co.slice(0, 8).map(g => `${g.band}GHz ch${g.channel} (${g.count} APs)`).join(', ') + '</p>'; |
| 3075 | if (ov.length) intf += `<p><b>2.4 GHz overlap:</b> ${ov.length} overlapping pair(s) — use ch 1/6/11.</p>`; |
| 3076 | if (!intf) intf = '<p>No significant co-/adjacent-channel interference.</p>'; |
| 3077 | } |
| 3078 | // AP inventory table. |
| 3079 | const aps = (d && d.aps) || []; |
| 3080 | const rows = aps.map(a => `<tr><td>${_esc(a.ssid) || '<i>hidden</i>'}</td><td class="mono">${_esc(a.bssid)}</td><td>${_esc(a.vendor) || '—'}</td><td>${a.band}</td><td>${a.channel}</td><td>${a.width}M</td><td>${a.signal}</td><td>${a.snr == null ? '—' : a.snr}</td><td>${_esc(a.security)}</td></tr>`).join(''); |
| 3081 | const now = new Date(); |
| 3082 | const issues = aps.filter(a => a.security_findings && a.security_findings.length); |
| 3083 | // 2.4 GHz coexistence overlays + the AI read (only when active / run). |
| 3084 | const btHtml = _wifiReportBtHtml(); |
| 3085 | const zbHtml = _wifiReportZbHtml(); |
| 3086 | const aiHtml = _wifiReportAIHtml(); |
| 3087 | const html = `<!doctype html><html><head><meta charset="utf-8"><title>WiFi Survey Report</title> |
no test coverage detected