LAGWI

Estimate missing greenweights

Starr (2007) suggests “Check for missing data in the unit_num and unit_weight fields. Drop records where greenweight=0 or =NULL and either unit_num and unit_weight is missing. Missing greenweight can be estimated”

-- © Copyright 2026 The Kahawai Collective
-- SPDX-License-Identifier: MIT
INSERT INTO grooming_rules
VALUES ('LAGWI', 'edw', 'landings', 'Fix', 'Estimate missing greenweights');

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

INSERT INTO groomed.checks(code, "table", "column", id, orig, new, details)
SELECT 'LAGWI', 'landings', 'green_weight', id, green_weight::TEXT,
       CASE WHEN conv_factor IS NOT NULL THEN conv_factor * unit_num * unit_weight
            ELSE unit_num * unit_weight
       END::TEXT,
       CASE WHEN conv_factor IS NOT NULL THEN '1' ELSE '2' END
FROM   groomed.landings
WHERE  (green_weight = 0 OR green_weight IS NULL)
AND    unit_num IS NOT NULL
AND    unit_weight IS NOT NULL;

UPDATE groomed.landings
SET    checks = array_append(checks, 'LAGWI'), green_weight = x.new::NUMERIC
FROM   groomed.checks x
WHERE  x.code = 'LAGWI'
AND    x.id = groomed.landings.id;

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