This commit is contained in:
parent
ffd08e2111
commit
5647af6c3a
|
|
@ -44,13 +44,15 @@ fi
|
|||
install -d -o root -g root -m 0755 "$APP_DIR"
|
||||
install -d -o root -g root -m 0755 "$APP_DIR/templates"
|
||||
install -d -o root -g root -m 0755 "$APP_DIR/static"
|
||||
install -d -o root -g root -m 0755 "$APP_DIR/doc"
|
||||
install -d -o root -g "$APP_USER" -m 0750 "$CONFIG_DIR"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/wifi_spool.py" "$APP_DIR/wifi_spool.py"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/settings.py" "$APP_DIR/settings.py"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/web_app.py" "$APP_DIR/web_app.py"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/gunicorn.conf.py" "$APP_DIR/gunicorn.conf.py"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/access_point_coordinates.csv" "$APP_DIR/access_point_coordinates.csv"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/background.png" "$APP_DIR/background.png"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/doc/object_blue_crossed_rectangles.csv" "$APP_DIR/doc/object_blue_crossed_rectangles.csv"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/doc/object_red_crossed_circles_labels.csv" "$APP_DIR/doc/object_red_crossed_circles_labels.csv"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/templates/dashboard.html" "$APP_DIR/templates/dashboard.html"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/static/dashboard.css" "$APP_DIR/static/dashboard.css"
|
||||
install -o root -g root -m 0644 "$SOURCE_DIR/static/dashboard.js" "$APP_DIR/static/dashboard.js"
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,36 @@
|
|||
name,y,x
|
||||
ШК6.3.4-5.7,82.670,-130.159
|
||||
ШК6.3.4-5.23,46.869,-130.112
|
||||
ШК6.3.4-6.10,33.248,-128.658
|
||||
ШК6.1.2-2.14,103.366,-126.510
|
||||
ШК6.3.4-6.9,65.297,-125.908
|
||||
ШК6.3.4-5.21,30.599,-113.657
|
||||
ШК6.1.2-2.11,72.688,-113.653
|
||||
ШК6.3.4-5.22,47.168,-113.610
|
||||
ШК6.3.4-5.8,58.356,-113.308
|
||||
ШК6.1.2-2.1,95.430,-113.031
|
||||
ШК6.1.2-2.10,67.279,-108.605
|
||||
ШC6.1-3.6,53.407,-100.889
|
||||
ШC6.1.2-2.9,88.142,-100.084
|
||||
ШК6.1.2-1.24,105.634,-97.482
|
||||
ШC6.1.2-2.8,72.233,-96.750
|
||||
ШC6.1-3.5,38.239,-96.323
|
||||
ШC6.1-3.4,58.044,-94.034
|
||||
ШC6.1-3.8,30.276,-88.849
|
||||
ШК6.1.2-2.7,81.918,-88.615
|
||||
ШК6.1.2-2.13,110.151,-88.483
|
||||
ШC6.1-3.3,47.186,-84.093
|
||||
ШК6.1.2-2.2,95.336,-84.037
|
||||
ШC6.1.2-2.6,67.009,-79.983
|
||||
ШК6.1-3.2,53.147,-76.725
|
||||
ШC6.1.2-2.3,88.397,-76.004
|
||||
ШК6.1.2-1.23,105.634,-73.541
|
||||
ШC6.1.2-2.5,73.202,-73.013
|
||||
ШC6.1-3.1,38.203,-72.887
|
||||
ШК6.1.2-2.4,81.862,-67.422
|
||||
ШC6.1-2.24,57.214,-65.439
|
||||
ШК6.1.2-1.12,111.926,-61.887
|
||||
ШК6.1.2-1.22,95.482,-60.590
|
||||
ШC6.1-2.23,47.168,-60.259
|
||||
ШC6.1-2.22,29.886,-58.017
|
||||
ШК6.1.1-2.9,66.920,-55.449
|
||||
|
|
|
@ -38,7 +38,7 @@ fieldset { border: 1px solid #31465f; border-radius: 8px; padding: 10px; min-wid
|
|||
.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; }
|
||||
#objects-layer { position: absolute; inset: 0; z-index: 0; min-height: 0; pointer-events: none; }
|
||||
#heatmap { position: relative; z-index: 1; cursor: grab; touch-action: none; }
|
||||
#heatmap.dragging-background { cursor: grabbing; }
|
||||
#access-points-layer { position: absolute; inset: 0; z-index: 2; min-height: 0; pointer-events: none; }
|
||||
|
|
|
|||
|
|
@ -1,20 +1,32 @@
|
|||
const state = {
|
||||
points: [], accessPoints: [], bounds: null, view: 'maximum', hitCells: [], hitAccessPoints: [],
|
||||
bssids: [], agents: [],
|
||||
bssids: [], agents: [], mapObjects: [],
|
||||
filters: { bssids: { loaded: false, error: '' }, agents: { loaded: false, error: '' } }
|
||||
};
|
||||
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 objectsCanvas = $('objects-layer');
|
||||
const objectsCtx = objectsCanvas.getContext('2d');
|
||||
const BACKGROUND_REFERENCE_WIDTH = 1000;
|
||||
let backgroundDrag = null;
|
||||
let resizeFrame = null;
|
||||
const accessPointsCanvas = $('access-points-layer');
|
||||
const accessPointsCtx = accessPointsCanvas.getContext('2d');
|
||||
|
||||
async function loadMapObjects() {
|
||||
try {
|
||||
const response = await fetch('/api/map-objects');
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const objects = await response.json();
|
||||
if (!Array.isArray(objects)) throw new Error('Некорректный ответ сервера');
|
||||
state.mapObjects = objects;
|
||||
drawBackground();
|
||||
} catch (error) {
|
||||
showError(`Не удалось загрузить объекты плана: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function initializeDates() {
|
||||
const dateTo = new Date();
|
||||
const rangeMinutes = Number(document.body.dataset.defaultDateRange) || 60;
|
||||
|
|
@ -145,18 +157,43 @@ function draw() {
|
|||
}
|
||||
|
||||
function drawBackground() {
|
||||
backgroundCtx.clearRect(0, 0, backgroundCanvas.width, backgroundCanvas.height);
|
||||
if (!backgroundImage.complete || !backgroundImage.naturalWidth) return;
|
||||
objectsCtx.clearRect(0, 0, objectsCanvas.width, objectsCanvas.height);
|
||||
if (!state.bounds || !state.mapObjects?.length) 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;
|
||||
const responsiveScale = backgroundCanvas.width / BACKGROUND_REFERENCE_WIDTH;
|
||||
backgroundCtx.drawImage(
|
||||
backgroundImage, x * responsiveScale, y * responsiveScale,
|
||||
backgroundImage.naturalWidth * scale * responsiveScale,
|
||||
backgroundImage.naturalHeight * scale * responsiveScale
|
||||
);
|
||||
const {min_x: minX, max_x: maxX, min_y: minY, max_y: maxY} = state.bounds;
|
||||
const padding = 55, availableWidth = objectsCanvas.width - padding * 2, availableHeight = objectsCanvas.height - padding * 2;
|
||||
const cellSize = Math.min(availableWidth / (maxX - minX + 1), availableHeight / (maxY - minY + 1));
|
||||
const plotWidth = cellSize * (maxX - minX + 1), plotHeight = cellSize * (maxY - minY + 1);
|
||||
const originX = padding + (availableWidth - plotWidth) / 2;
|
||||
const originY = padding + (availableHeight - plotHeight) / 2;
|
||||
const responsiveScale = objectsCanvas.width / BACKGROUND_REFERENCE_WIDTH;
|
||||
const offsetX = x * responsiveScale, offsetY = y * responsiveScale;
|
||||
objectsCtx.lineWidth = 1.5;
|
||||
objectsCtx.font = '10px system-ui';
|
||||
state.mapObjects.forEach(object => {
|
||||
const objectX = originX + (object.x - minX) * cellSize * scale + offsetX;
|
||||
const objectY = originY + (maxY + 1 - object.y) * cellSize * scale + offsetY;
|
||||
if (object.shape === 'rectangle') {
|
||||
const width = object.width * cellSize * scale;
|
||||
const height = object.height * cellSize * scale;
|
||||
objectsCtx.fillStyle = '#2787c844';
|
||||
objectsCtx.strokeStyle = '#49aef0';
|
||||
objectsCtx.fillRect(objectX, objectY - height, width, height);
|
||||
objectsCtx.strokeRect(objectX, objectY - height, width, height);
|
||||
} else {
|
||||
const radius = Math.max(3, 3.5 * scale);
|
||||
objectsCtx.beginPath(); objectsCtx.arc(objectX, objectY, radius, 0, Math.PI * 2);
|
||||
objectsCtx.fillStyle = '#e34b55'; objectsCtx.fill();
|
||||
objectsCtx.strokeStyle = '#ffadb2'; objectsCtx.stroke();
|
||||
if (object.name) {
|
||||
objectsCtx.fillStyle = '#e8edf4';
|
||||
objectsCtx.fillText(object.name, objectX + radius + 3, objectY + 3);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function canvasPointerPosition(event) {
|
||||
|
|
@ -168,7 +205,7 @@ function canvasPointerPosition(event) {
|
|||
}
|
||||
|
||||
function startBackgroundDrag(event) {
|
||||
if (event.button !== 0 || !backgroundImage.naturalWidth) return;
|
||||
if (event.button !== 0 || !state.mapObjects?.length) return;
|
||||
const pointer = canvasPointerPosition(event);
|
||||
backgroundDrag = {
|
||||
pointerId: event.pointerId,
|
||||
|
|
@ -249,9 +286,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;
|
||||
objectsCanvas.style.height = `${height}px`;
|
||||
objectsCanvas.width = Math.round(containerWidth);
|
||||
objectsCanvas.height = height;
|
||||
accessPointsCanvas.style.height = `${height}px`;
|
||||
accessPointsCanvas.width = Math.round(containerWidth);
|
||||
accessPointsCanvas.height = height;
|
||||
|
|
@ -281,10 +318,8 @@ const mapResizeObserver = new ResizeObserver(() => {
|
|||
resizeFrame = requestAnimationFrame(draw);
|
||||
});
|
||||
mapResizeObserver.observe(canvas.parentElement);
|
||||
backgroundImage.addEventListener('load', drawBackground);
|
||||
backgroundImage.addEventListener('error', () => showError('Не удалось загрузить фоновое изображение background.png'));
|
||||
backgroundImage.src = document.body.dataset.backgroundUrl;
|
||||
initializeDates();
|
||||
initializeBounds();
|
||||
loadMapObjects();
|
||||
loadFilters();
|
||||
loadHeatmap();
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@
|
|||
</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-background-url="{{ url_for('map_background') }}">
|
||||
data-map-min-y="{{ map_min_y }}" data-map-max-y="{{ map_max_y }}">
|
||||
<header class="page-header">
|
||||
<div class="brand">
|
||||
<h1>Тепловая карта Wi-Fi</h1>
|
||||
|
|
@ -43,11 +42,11 @@
|
|||
<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="236"></label>
|
||||
<label>background_y<input id="background-y" type="number" step="1" value="49"></label>
|
||||
<label>background_scale<input id="background-scale" type="number" step="0.001" min="0.001" value="0.192"></label>
|
||||
<small class="background-hint">Фон можно перемещать мышью на карте</small>
|
||||
<legend>Объекты плана</legend>
|
||||
<label>Смещение X<input id="background-x" type="number" step="1" value="0"></label>
|
||||
<label>Смещение Y<input id="background-y" type="number" step="1" value="0"></label>
|
||||
<label>Масштаб<input id="background-scale" type="number" step="0.01" min="0.01" value="1"></label>
|
||||
<small class="background-hint">Все объекты можно перемещать мышью на карте</small>
|
||||
</fieldset>
|
||||
<fieldset class="filter-fieldset">
|
||||
<legend id="filter-title">BSSID</legend>
|
||||
|
|
@ -59,7 +58,7 @@
|
|||
|
||||
<section class="workspace">
|
||||
<div class="panel canvas-wrap">
|
||||
<canvas id="background-layer" aria-hidden="true"></canvas>
|
||||
<canvas id="objects-layer" aria-hidden="true"></canvas>
|
||||
<canvas id="heatmap"></canvas>
|
||||
<canvas id="access-points-layer" aria-hidden="true"></canvas>
|
||||
<div id="empty" class="empty">За выбранный период данных нет</div>
|
||||
|
|
|
|||
|
|
@ -30,15 +30,21 @@ class WebAppTest(unittest.TestCase):
|
|||
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")
|
||||
def test_map_objects_are_available(self):
|
||||
response = self.client.get("/api/map-objects")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.mimetype, "image/png")
|
||||
response.close()
|
||||
objects = response.get_json()
|
||||
self.assertGreater(len(objects), 1000)
|
||||
rectangle = next(item for item in objects if item["shape"] == "rectangle")
|
||||
circle = next(item for item in objects if item["shape"] == "circle")
|
||||
self.assertIn("width", rectangle)
|
||||
self.assertIn("height", rectangle)
|
||||
self.assertIn("name", circle)
|
||||
|
||||
def test_installer_copies_background_image(self):
|
||||
def test_installer_copies_map_objects(self):
|
||||
installer = Path("deploy/install.sh").read_text(encoding="utf-8")
|
||||
self.assertIn('"$SOURCE_DIR/background.png" "$APP_DIR/background.png"', installer)
|
||||
self.assertIn("object_blue_crossed_rectangles.csv", installer)
|
||||
self.assertIn("object_red_crossed_circles_labels.csv", installer)
|
||||
|
||||
def test_web_server_listens_on_all_interfaces_by_default(self):
|
||||
self.assertEqual(Settings().web_host, "0.0.0.0")
|
||||
|
|
|
|||
31
web_app.py
31
web_app.py
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import csv
|
||||
from collections.abc import Sequence
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import psycopg
|
||||
from flask import Flask, jsonify, render_template, request, send_from_directory
|
||||
from flask import Flask, jsonify, render_template, request
|
||||
|
||||
from settings import SETTINGS, Settings
|
||||
|
||||
|
|
@ -30,9 +32,30 @@ 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("/api/map-objects")
|
||||
def map_objects():
|
||||
"""Return all map primitives stored in doc/object_*.csv."""
|
||||
objects: list[dict[str, Any]] = []
|
||||
for path in sorted(Path(app.root_path, "doc").glob("object_*.csv")):
|
||||
with path.open(encoding="utf-8-sig", newline="") as source:
|
||||
for row in csv.DictReader(source):
|
||||
try:
|
||||
item: dict[str, Any] = {
|
||||
"x": float(row["x"]),
|
||||
"y": float(row["y"]),
|
||||
}
|
||||
if row.get("width") and row.get("height"):
|
||||
item.update(
|
||||
width=float(row["width"]),
|
||||
height=float(row["height"]),
|
||||
shape="rectangle",
|
||||
)
|
||||
else:
|
||||
item.update(shape="circle", name=row.get("name", ""))
|
||||
except (KeyError, TypeError, ValueError):
|
||||
continue
|
||||
objects.append(item)
|
||||
return jsonify(objects)
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
|
|
|
|||
Loading…
Reference in New Issue