FEPMN

Add PSH as a method code for certain vessels if method is null

Primary method is currently reported as null when PSH (precision seafood harvesting is being utilised)

MPI are forecasted to replace this with: - PRB for precision bottom trawl - PRM for precision midwater trawl

This check finds PSH events that are being reported as Null and replaces this with code PSH. We are only applying this to a set of vessels known to use PSH

-- © Copyright 2026 The Kahawai Collective
-- SPDX-License-Identifier: MIT
INSERT INTO grooming_rules
VALUES ('FEPMN', 'edw', 'effort', 'Fix', 'Add PSH as a method code for certain vessels if method is null');

CREATE OR REPLACE FUNCTION FEPMN()
RETURNS VOID AS $$

INSERT INTO groomed.checks (code, "table", "column", id, details, orig, new)
SELECT 'FEPMN', 'effort', 'primary_method', id, trip::TEXT, NULL, 'PSH'
FROM   groomed.effort e
WHERE primary_method IS NULL
AND   vessel_name IN ('Otakou', 'Aukaha', 'Corinthian', 'Tengawai', 'Ana',
        'Margaret Philippa', 'San Enterprise', 'Santy Maria', 'San Discovery',
        'Rehua', 'Galatea II', 'Jay Debra');

UPDATE groomed.effort SET checks = checks || '{FEPMN}', primary_method = 'PSH'
FROM   groomed.checks u
WHERE  u.code = 'FEPMN'
AND    groomed.effort.id = u.id;

$$ LANGUAGE SQL;
SELECT FEPMN();
Effects of grooming
Figure 1: The number of records affected by the FEPMN rule, by year and source.
Figure 2: The proportion of records affected by the FEPMN rule, by form type, for all form types where some records are groomed by the FEPMN rule.