бекгроунд

This commit is contained in:
timur 2026-09-01 16:14:15 +05:00
parent df40e99a82
commit 127b4591da
8 changed files with 54 additions and 5 deletions

BIN
background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 KiB

View File

@ -1 +0,0 @@
,timur,timur-MS-7E26,31.08.2026 20:09,file:///home/timur/.config/libreoffice/4;

View File

@ -1 +0,0 @@
,timur,timur-MS-7E26,31.08.2026 20:28,file:///home/timur/.config/libreoffice/4;

View File

@ -30,9 +30,15 @@ fieldset { border: 1px solid #31465f; border-radius: 8px; padding: 10px; min-wid
.filter-error { color: #ff9a9f; }
.check { display: flex; align-items: center; gap: 7px; }
.access-points-toggle { color: #d8f3ff; }
.background-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.background-controls legend { grid-column: 1 / -1; }
.background-controls label { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.background-controls label:last-child { grid-column: 1 / -1; }
.workspace { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.canvas-wrap { position: relative; min-height: 420px; overflow: hidden; background: #09111c; }
canvas { display: block; width: 100%; min-height: 420px; }
#background-layer { position: absolute; inset: 0; z-index: 0; min-height: 0; pointer-events: none; }
#heatmap { position: relative; z-index: 1; }
#access-points-layer { position: absolute; inset: 0; z-index: 2; min-height: 0; pointer-events: none; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: #74879d; pointer-events: none; }
.map-tooltip { position: absolute; z-index: 3; pointer-events: none; padding: 7px 9px; border: 1px solid #53779c; border-radius: 6px; background: #07101ded; color: #edf5ff; font-size: 12px; white-space: nowrap; box-shadow: 0 5px 16px #0008; }

View File

@ -6,6 +6,9 @@ const state = {
const $ = id => document.getElementById(id);
const canvas = $('heatmap');
const ctx = canvas.getContext('2d');
const backgroundCanvas = $('background-layer');
const backgroundCtx = backgroundCanvas.getContext('2d');
const backgroundImage = new Image();
const accessPointsCanvas = $('access-points-layer');
const accessPointsCtx = accessPointsCanvas.getContext('2d');
@ -105,6 +108,7 @@ function switchView(view) {
function draw() {
resizeCanvas(); ctx.clearRect(0, 0, canvas.width, canvas.height);
drawBackground();
accessPointsCtx.clearRect(0, 0, accessPointsCanvas.width, accessPointsCanvas.height);
state.hitCells = []; state.hitAccessPoints = [];
const points = state.points;
@ -120,7 +124,7 @@ function draw() {
drawGrid(minX, maxX + 1, minY, maxY + 1, originX, originY, plotWidth, plotHeight);
points.forEach(point => {
const x = originX + (point.x - minX) * cellSize, y = originY + (maxY - point.y) * cellSize;
ctx.fillStyle = signalColor(point.signal); ctx.fillRect(x, y, Math.max(1, cellSize), Math.max(1, cellSize));
ctx.fillStyle = signalColor(point.signal); ctx.globalAlpha = 0.72; ctx.fillRect(x, y, Math.max(1, cellSize), Math.max(1, cellSize)); ctx.globalAlpha = 1;
state.hitCells.push({ x, y, size: Math.max(1, cellSize), point });
if (cellSize >= 5) { ctx.strokeStyle = '#07101d66'; ctx.strokeRect(x, y, cellSize, cellSize); }
});
@ -137,6 +141,20 @@ function draw() {
$('samples-count').textContent = `${points.reduce((sum, point) => sum + point.samples, 0)} измерений`;
}
function drawBackground() {
backgroundCtx.clearRect(0, 0, backgroundCanvas.width, backgroundCanvas.height);
if (!backgroundImage.complete || !backgroundImage.naturalWidth) return;
const x = Number($('background-x').value);
const y = Number($('background-y').value);
const scale = Number($('background-scale').value);
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(scale) || scale <= 0) return;
backgroundCtx.drawImage(
backgroundImage, x, y,
backgroundImage.naturalWidth * scale,
backgroundImage.naturalHeight * scale
);
}
function drawGrid(minX, maxX, minY, maxY, originX, originY, width, height) {
ctx.strokeStyle = '#1d3045'; ctx.fillStyle = '#688097'; ctx.font = '11px system-ui'; ctx.lineWidth = 1;
for (let i = 0; i <= 5; i++) {
@ -186,6 +204,9 @@ function resizeCanvas() {
height = Math.max(420, Math.min(900, Math.round(Math.max(1, containerWidth - 110) * cellsY / cellsX + 110)));
}
canvas.style.height = `${height}px`; canvas.width = Math.round(containerWidth); canvas.height = height;
backgroundCanvas.style.height = `${height}px`;
backgroundCanvas.width = Math.round(containerWidth);
backgroundCanvas.height = height;
accessPointsCanvas.style.height = `${height}px`;
accessPointsCanvas.width = Math.round(containerWidth);
accessPointsCanvas.height = height;
@ -202,10 +223,13 @@ $('filter-list').addEventListener('change', event => {
if (state.view === 'points' && event.target.matches('input[type="radio"]')) loadHeatmap();
});
$('show-access-points').addEventListener('change', draw);
['background-x', 'background-y', 'background-scale'].forEach(id => $(id).addEventListener('input', drawBackground));
document.querySelectorAll('.tab').forEach(tab => tab.addEventListener('click', () => switchView(tab.dataset.view)));
canvas.addEventListener('mousemove', showMapTooltip);
canvas.addEventListener('mouseleave', () => { $('map-tooltip').hidden = true; });
window.addEventListener('resize', draw);
backgroundImage.addEventListener('load', drawBackground);
backgroundImage.src = document.body.dataset.backgroundUrl;
initializeDates();
initializeBounds();
loadFilters();

View File

@ -8,7 +8,8 @@
</head>
<body data-default-date-range="{{ default_date_range }}"
data-map-min-x="{{ map_min_x }}" data-map-max-x="{{ map_max_x }}"
data-map-min-y="{{ map_min_y }}" data-map-max-y="{{ map_max_y }}">
data-map-min-y="{{ map_min_y }}" data-map-max-y="{{ map_max_y }}"
data-background-url="{{ url_for('map_background') }}">
<header class="page-header">
<div class="brand">
<h1>Тепловая карта Wi-Fi</h1>
@ -41,6 +42,12 @@
<main>
<aside class="panel controls">
<label class="check access-points-toggle"><input id="show-access-points" type="checkbox" checked> Отображать точки доступа</label>
<fieldset class="background-controls">
<legend>Фоновое изображение</legend>
<label>background_x<input id="background-x" type="number" step="1" value="0"></label>
<label>background_y<input id="background-y" type="number" step="1" value="0"></label>
<label>background_scale<input id="background-scale" type="number" step="0.01" min="0.01" value="0.2"></label>
</fieldset>
<fieldset class="filter-fieldset">
<legend id="filter-title">BSSID</legend>
<div class="filter-actions"><button id="select-all" type="button">Все</button><button id="select-none" type="button">Сбросить</button></div>
@ -51,6 +58,7 @@
<section class="workspace">
<div class="panel canvas-wrap">
<canvas id="background-layer" aria-hidden="true"></canvas>
<canvas id="heatmap"></canvas>
<canvas id="access-points-layer" aria-hidden="true"></canvas>
<div id="empty" class="empty">За выбранный период данных нет</div>

View File

@ -25,6 +25,15 @@ class WebAppTest(unittest.TestCase):
self.assertIn('≥ −70 dBm'.encode(), response.data)
self.assertIn('id="show-access-points"'.encode(), response.data)
self.assertIn("Отображать точки доступа".encode(), response.data)
self.assertIn('id="background-x"'.encode(), response.data)
self.assertIn('id="background-y"'.encode(), response.data)
self.assertIn('id="background-scale"'.encode(), response.data)
def test_background_image_is_available(self):
response = self.client.get("/background.png")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, "image/png")
response.close()
def test_web_server_listens_on_all_interfaces_by_default(self):
self.assertEqual(Settings().web_host, "0.0.0.0")

View File

@ -7,7 +7,7 @@ from datetime import datetime
from typing import Any
import psycopg
from flask import Flask, jsonify, render_template, request
from flask import Flask, jsonify, render_template, request, send_from_directory
from settings import SETTINGS, Settings
@ -30,6 +30,10 @@ def create_app(settings: Settings = SETTINGS) -> Flask:
map_max_y=settings.web_map_max_y,
)
@app.get("/background.png")
def map_background():
return send_from_directory(app.root_path, "background.png")
@app.get("/health")
def health():
try: