You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: initdb/99_migrations_202412.sql
+275-5
Original file line number
Diff line number
Diff line change
@@ -838,7 +838,14 @@ BEGIN
838
838
valueAtTimestamp(points.trip_tws, getTimestamp(points.point)) AS truewindspeed,
839
839
valueAtTimestamp(points.trip_twd, getTimestamp(points.point)) AS truewinddirection,
840
840
valueAtTimestamp(points.trip_notes, getTimestamp(points.point)) AS notes,
841
-
valueAtTimestamp(points.trip_status, getTimestamp(points.point)) AS status
841
+
valueAtTimestamp(points.trip_status, getTimestamp(points.point)) AS status,
842
+
valueAtTimestamp(points.trip_depth, getTimestamp(points.point)) AS depth,
843
+
valueAtTimestamp(points.trip_batt_charge, getTimestamp(points.point)) AS stateofcharge,
844
+
valueAtTimestamp(points.trip_batt_voltage, getTimestamp(points.point)) AS voltage,
845
+
valueAtTimestamp(points.trip_temp_water, getTimestamp(points.point)) AS watertemperature,
846
+
valueAtTimestamp(points.trip_temp_out, getTimestamp(points.point)) AS outsidetemperature,
847
+
valueAtTimestamp(points.trip_pres_out, getTimestamp(points.point)) AS outsidepressure,
848
+
valueAtTimestamp(points.trip_hum_out, getTimestamp(points.point)) AS outsidehumidity
842
849
FROM (
843
850
SELECT unnest(instants(trip)) ASpoint,
844
851
trip_cog,
@@ -847,7 +854,14 @@ BEGIN
847
854
trip_tws,
848
855
trip_twd,
849
856
trip_notes,
850
-
trip_status
857
+
trip_status,
858
+
trip_depth,
859
+
trip_batt_charge,
860
+
trip_batt_voltage,
861
+
trip_temp_water,
862
+
trip_temp_out,
863
+
trip_pres_out,
864
+
trip_hum_out
851
865
FROMapi.logbook
852
866
WHERE id = _id
853
867
AND trip IS NOT NULL
@@ -914,7 +928,14 @@ BEGIN
914
928
valueAtTimestamp(points.trip_tws, getTimestamp(points.point)) AS truewindspeed,
915
929
valueAtTimestamp(points.trip_twd, getTimestamp(points.point)) AS truewinddirection,
916
930
valueAtTimestamp(points.trip_notes, getTimestamp(points.point)) AS notes,
917
-
valueAtTimestamp(points.trip_status, getTimestamp(points.point)) AS status
931
+
valueAtTimestamp(points.trip_status, getTimestamp(points.point)) AS status,
932
+
valueAtTimestamp(points.trip_depth, getTimestamp(points.point)) AS depth,
933
+
valueAtTimestamp(points.trip_batt_charge, getTimestamp(points.point)) AS stateofcharge,
934
+
valueAtTimestamp(points.trip_batt_voltage, getTimestamp(points.point)) AS voltage,
935
+
valueAtTimestamp(points.trip_temp_water, getTimestamp(points.point)) AS watertemperature,
936
+
valueAtTimestamp(points.trip_temp_out, getTimestamp(points.point)) AS outsidetemperature,
937
+
valueAtTimestamp(points.trip_pres_out, getTimestamp(points.point)) AS outsidepressure,
938
+
valueAtTimestamp(points.trip_hum_out, getTimestamp(points.point)) AS outsidehumidity
918
939
FROM
919
940
(
920
941
SELECT
@@ -925,7 +946,14 @@ BEGIN
925
946
trip_tws,
926
947
trip_twd,
927
948
trip_notes,
928
-
trip_status
949
+
trip_status,
950
+
trip_depth,
951
+
trip_batt_charge,
952
+
trip_batt_voltage,
953
+
trip_temp_water,
954
+
trip_temp_out,
955
+
trip_pres_out,
956
+
trip_hum_out
929
957
FROMapi.logbook
930
958
WHERE id = _id
931
959
) AS points
@@ -1814,15 +1842,257 @@ $function$
1814
1842
1815
1843
COMMENT ON FUNCTION public.qgis_bbox_trip_py_fn(in text, out text) IS 'Generate the BBOX base on trip extent and adapt extent to the image size for QGIS Server';
1816
1844
1845
+
-- DROP FUNCTION api.stats_stays_fn(in text, in text, out json);
1846
+
-- Update api.stats_stays_fn, due to reference_count and stay_duration columns removal
1847
+
CREATE OR REPLACEFUNCTIONapi.stats_stays_fn(start_date text DEFAULT NULL::text, end_date text DEFAULT NULL::text, OUT stats json)
1848
+
RETURNS json
1849
+
LANGUAGE plpgsql
1850
+
AS $function$
1851
+
DECLARE
1852
+
_start_date TIMESTAMPTZ DEFAULT '1970-01-01';
1853
+
_end_date TIMESTAMPTZ DEFAULT NOW();
1854
+
BEGIN
1855
+
IF start_date IS NOT NULLANDpublic.isdate(start_date::text) ANDpublic.isdate(end_date::text) THEN
1856
+
RAISE NOTICE '--> stats_stays_fn, custom filter result stats by date [%]', start_date;
selectcount(*) as home_ports fromapi.moorages m where home_flag is true
1879
+
),
1880
+
unique_moorages AS (
1881
+
selectcount(*) as unique_moorages fromapi.moorages m
1882
+
),
1883
+
time_at_home_ports AS (
1884
+
selectsum(m.stays_sum_duration) as time_at_home_ports fromapi.moorage_view m where home is true
1885
+
),
1886
+
sum_stay_duration AS (
1887
+
selectsum(m.stays_sum_duration) as sum_stay_duration fromapi.moorage_view m where home is false
1888
+
),
1889
+
time_spent_away_arr AS (
1890
+
selectm.default_stay_idas stay_code,sum(m.stays_sum_duration) as stay_duration fromapi.moorage_view m where home is false group bym.default_stay_idorder bym.default_stay_id
1891
+
),
1892
+
time_spent_arr as (
1893
+
select jsonb_agg(t.*) as time_spent_away_arr from time_spent_away_arr t
1894
+
),
1895
+
time_spent_away AS (
1896
+
selectsum(m.stays_sum_duration) as time_spent_away fromapi.moorage_view m where home is false
1897
+
),
1898
+
time_spent as (
1899
+
select jsonb_agg(t.*) as time_spent_away from time_spent_away t
0 commit comments