api.stats_logs_view
Description
Statistics Logs web view. Includes best_24h_distance_nm, best_24h_window_start,
best_24h_log_id (for deep-link to the logbook entry), and best_24h_route.
Table Definition
CREATE VIEW stats_logs_view AS (
WITH meta AS (
SELECT m_1.name
FROM api.metadata m_1
), last_metric AS (
SELECT m_1."time"
FROM api.metrics m_1
ORDER BY m_1."time" DESC
LIMIT 1
), first_metric AS (
SELECT m_1."time"
FROM api.metrics m_1
ORDER BY m_1."time"
LIMIT 1
), logbook AS (
SELECT count(*) AS number_of_log_entries,
max(l_1.max_speed) AS max_speed,
max(l_1.max_wind_speed) AS max_wind_speed,
sum(l_1.distance) AS total_distance,
sum(l_1.duration) AS total_time_underway,
concat(max(l_1.distance), ' NM, ', max(l_1.duration), ' hours') AS longest_nonstop_sail
FROM api.logbook l_1
WHERE ((l_1.vessel_id = current_setting('vessel.id'::text, true)) AND (l_1.active = false))
), best24h AS (
SELECT b_1.best_distance_nm,
b_1.window_start,
b_1.anchor_log_id,
b_1.route_summary
FROM best_24h_distance_fn(current_setting('vessel.id'::text, true)) b_1(best_distance_nm, window_start, window_end, anchor_log_id, anchor_log_name, contributing_log_ids, route_summary)
)
SELECT m.name,
fm."time" AS first,
lm."time" AS last,
l.number_of_log_entries,
l.max_speed,
l.max_wind_speed,
l.total_distance,
l.total_time_underway,
l.longest_nonstop_sail,
b.best_distance_nm AS best_24h_distance_nm,
b.window_start AS best_24h_window_start,
b.anchor_log_id AS best_24h_log_id,
b.route_summary AS best_24h_route
FROM first_metric fm,
last_metric lm,
logbook l,
meta m,
best24h b
)
Columns
| Name | Type | Default | Nullable |
|---|---|---|---|
| best_24h_distance_nm | numeric | true | |
| best_24h_log_id | integer | true | |
| best_24h_route | text | true | |
| best_24h_window_start | timestamp with time zone | true | |
| first | timestamp with time zone | true | |
| last | timestamp with time zone | true | |
| longest_nonstop_sail | text | true | |
| max_speed | double precision | true | |
| max_wind_speed | double precision | true | |
| name | text | true | |
| number_of_log_entries | bigint | true | |
| total_distance | numeric | true | |
| total_time_underway | interval | true |
Referenced Tables
| Name | Columns | Comment | Type |
|---|---|---|---|
| api.metadata | 18 | Stores metadata received from vessel, aka signalk plugin. single-row-per-vessel store | BASE TABLE |
| api.metrics | 11 | Stores metrics from vessel | BASE TABLE |
| api.logbook | 43 | The logbook table stores vessel navigation entries with timestamps, locations, and trip metrics. RLS policies filter by vessel_id automatically. These indexes optimize different query patterns while minimizing storage. | BASE TABLE |
| best_24h_distance_fn | 0 | ||
| public.first_metric | 11 | VIEW |
Relations
erDiagram
"api.stats_logs_view" {
numeric best_24h_distance_nm ""
integer best_24h_log_id ""
text best_24h_route ""
timestamp_with_time_zone best_24h_window_start ""
timestamp_with_time_zone first ""
timestamp_with_time_zone last ""
text longest_nonstop_sail ""
double_precision max_speed ""
double_precision max_wind_speed ""
text name ""
bigint number_of_log_entries ""
numeric total_distance ""
interval total_time_underway ""
}
Generated by tbls