Checkpoint
Some checks failed
Test and build / Test and lint (push) Failing after 36s
Test and build / Build collector (push) Failing after 43s
Test and build / Build receiver (push) Failing after 42s

This commit is contained in:
2026-03-05 15:38:18 +01:00
parent 3106b2cf45
commit 13afa08e8a
108 changed files with 19509 additions and 729 deletions

107
sql.go
View File

@@ -1,5 +1,31 @@
package hamview
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
type JSONB map[string]any
func (v JSONB) Value() (driver.Value, error) {
return json.Marshal(v)
}
func (v *JSONB) Scan(value any) error {
if value == nil {
*v = nil
return nil
}
b, ok := value.([]byte)
if !ok {
return fmt.Errorf("type assertion to []byte failed, got %T", value)
}
return json.Unmarshal(b, &v)
}
/*
const (
sqlCreateRadio = `
CREATE TABLE IF NOT EXISTS radio (
@@ -16,20 +42,56 @@ const (
latitude NUMERIC(10, 8), -- GPS latitude in decimal degrees
longitude NUMERIC(11, 8), -- GPS longitude in decimal degrees
altitude REAL, -- Altitude in meters
frequency DOUBLE PRECISION,
bandwidth DOUBLE PRECISION,
frequency DOUBLE PRECISION NOT NULL,
bandwidth DOUBLE PRECISION NOT NULL,
rx_frequency DOUBLE PRECISION,
tx_frequency DOUBLE PRECISION,
power REAL,
gain REAL,
lora_sf SMALLINT,
lora_cr SMALLINT,
extra JSONB
extra JSONB,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
`
sqlIndexRadioName = `CREATE INDEX IF NOT EXISTS idx_radio_name ON radio(name);`
sqlIndexRadioProtocol = `CREATE INDEX IF NOT EXISTS idx_radio_protocol ON radio(protocol);`
sqlGeometryRadioPosition = `SELECT AddGeometryColumn('public', 'radio', 'position', 4326, 'POINT', 2);`
sqlSelectRadios = `
SELECT
name,
is_online,
device,
manufacturer,
firmware_date,
firmware_version,
antenna,
modulation,
protocol,
latitude,
longitude,
altitude,
frequency,
bandwidth,
rx_frequency,
tx_frequency,
power,
gain,
lora_sf,
lora_cr,
extra
FROM radio
WHERE
protocol LIKE $1
AND (
is_online
OR
updated_at BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW()
)
ORDER BY
protocol, name
`
)
const (
@@ -74,6 +136,38 @@ const (
`
sqlIndexMeshCorePacketHash = `CREATE INDEX IF NOT EXISTS idx_meshcore_packet_hash ON meshcore_packet(hash);`
sqlIndexMeshCorePacketPayloadType = `CREATE INDEX IF NOT EXISTS idx_meshcore_packet_payload_type ON meshcore_packet(payload_type);`
sqlSelectMeshCoreTextStats = `
SELECT
COUNT(id)
FROM
meshcore_packet
WHERE
received_at BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW()
AND
payload_type IN (2, 5)
`
sqlSelectMeshCorePacketStatsOverTime = `
WITH time_buckets AS (
SELECT
time_bucket,
COUNT(*) as packet_count
FROM (
SELECT
date_trunc('minute', received_at) - INTERVAL '1 minute' * (EXTRACT(minute FROM received_at)::int % 5) AS time_bucket
FROM
meshcore_packet
WHERE
received_at >= NOW() - INTERVAL '24 hours'
) AS bucketed
GROUP BY time_bucket
ORDER BY time_bucket DESC
)
SELECT
time_bucket,
packet_count
FROM
time_buckets;
`
)
const (
@@ -105,6 +199,12 @@ const (
ELSE NULL
END
) STORED;`
sqlSelectMeshCoreNodeStats = `
SELECT
COUNT(id)
FROM
meshcore_node
`
)
const (
@@ -234,3 +334,4 @@ const (
);
`
)
*/