Fail (or ratchet) the release on a cruise_key that does not hold up
Source: R/keys.R
check_cruise_key_integrity.RdTen checks over cruise_key as it is actually used, not as it is assumed to
behave — see the WS-B design memo for the incidents each one guards against.
Checks 1-5 and 7 are hard failures from the first run (n must be exactly
0); check 6 is hard with known_outside_span as named exceptions (an
UNLISTED violator still fails); checks 8-10 are ratchets — the current count
must not exceed the allowance, which may only ever be lowered.
Usage
check_cruise_key_integrity(
con,
tolerance_days = 31L,
known_outside_span = character(),
manifest_ichthyo = NULL,
ratchets = list(span_overlaps_max = 2L, derived_max = 152L, key_null_max =
c(calcofi_dic = 3255L, `sio_pic-zooplankton` = 5087L, `cdfw_dungeness-crab` = 1639L,
calcofi_bottle = 49L)),
halt = TRUE,
sample_tbl = "sample",
obs_tbl = "obs",
cruise_tbl = "cruise",
ship_tbl = "ship"
)Arguments
- con
DBI connection holding
sample_tbl,obs_tbl,cruise_tbl,ship_tbl.- tolerance_days
Days a
'swfsc'cruise's span may be exceeded by one of its own events before check 6 flags it (default 31 — 99.97% of the 21,987 outside-span events measured at v2026.08.25 are within this).- known_outside_span
sample_keys exempt from check 6 (named or not; only the values are used) — an UNLISTED violator still fails.- manifest_ichthyo
A single integer: the ichthyo ingest's own
mismatches$cruise_uuidn_mismatchcount (frommanifest.json), orNULLif not supplied (check 7 then fails, naming the gap).- ratchets
A list with
span_overlaps_max,derived_max(both single integers) andkey_null_max(a named integer vector bydataset_key; an un-named dataset's allowance is 0, so a first NULL there fails).- halt
stop()on any failing hard check or exceeded ratchet (defaultTRUE).- sample_tbl, obs_tbl, cruise_tbl, ship_tbl
Table names.
Value
A tibble: check, dataset_key (or a table/scope label where the
check is not per-dataset), n, mode ("fail" | "ratchet"),
finding.
Details
cruise_keymatches^\\d{4}-(0[1-9]|1[0-2])-[A-Za-z0-9]{4}$oncruise_tbl,sample_tbl,obs_tbl.cruise.date_ym'sYYYY-MMequals the key's own.the key's NODC segment equals
ship.ship_nodcofcruise.ship_key.every non-NULL
sample.cruise_key/obs.cruise_keynames a realcruiserow (runcomplete_cruise_reference()first, or this is the 153,306-row finding it exists to close).cruise_key_method = 'swfsc'rows have a unique non-NULLcruise_uuid;'derived'rows have none.every event's date falls within
[date_min - tolerance_days, date_max + tolerance_days]of its cruise — for'swfsc'rows only (a'derived'row's span is its own events' min/max by construction, so it cannot be violated);known_outside_spannames exemptsample_keys.the ichthyo notebook's own
cruise_uuidvscruise_keycheck (manifest_ichthyo, itsmismatches$cruise_uuidcount) is 0, and every ichthyosite/tow/netrow has a non-NULLsource_uuid.(ratchet
span_overlaps_max) event spans of two cruises of one ship overlap by more than 3 days.(ratchet
derived_max)cruise_key_method = 'derived'row count.(ratchet
key_null_max, perdataset_key) root samples with aNULLcruise_key.