Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

NameTypeDefaultNullable
best_24h_distance_nmnumerictrue
best_24h_log_idintegertrue
best_24h_routetexttrue
best_24h_window_starttimestamp with time zonetrue
firsttimestamp with time zonetrue
lasttimestamp with time zonetrue
longest_nonstop_sailtexttrue
max_speeddouble precisiontrue
max_wind_speeddouble precisiontrue
nametexttrue
number_of_log_entriesbiginttrue
total_distancenumerictrue
total_time_underwayintervaltrue

Referenced Tables

NameColumnsCommentType
api.metadata18Stores metadata received from vessel, aka signalk plugin. single-row-per-vessel storeBASE TABLE
api.metrics11Stores metrics from vesselBASE TABLE
api.logbook43The 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_fn0
public.first_metric11VIEW

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