
peskas.mozambique.data.pipeline
R package for the Peskas Mozambique pipeline: two KoBo landing-survey chains (ADNAP, now DINAPA, and Lurio) plus PDS GPS trips, validated and exported to GCS, Mongo and the Peskas API. PDS ingestion, portal summaries and portal export are coasts:: functions called from the workflow with package = "peskas.mozambique.data.pipeline". The fleet estimate places each tracker by where its trips land (pds.fleet_location: landing, from coasts::describe_pds_tracks in the PDS job), not by the Airtable gaul 2 link. With fao.surveys set to the ADNAP validated file, it also raises catch and revenue with the FAO ARTFISH method (coasts >= 4.19.0). Ecosystem context (other repos, data flow, cross-repo contracts): loaded by the peskas Claude Code plugin (repo peskas-context).
Commands
- Load:
Rscript -e 'devtools::load_all()' - Docs:
Rscript -e 'devtools::document()' - Check:
Rscript -e 'devtools::check()' - There are no automated tests (the repo tracks no
tests/directory), sodevtools::test()proves nothing. Verify changes by running the function against thedefault(dev) profile, or by pushing a non-main branch. - Pipeline steps and their order:
.github/workflows/data-pipeline.yaml.
Architecture
- The
adnapchain is DINAPA’s survey (National Directorate of Fisheries and Aquaculture, which replaced ADNAP). Identifiers keepadnap; what is published says DINAPA (survey_organization = "DINAPA"), with no website or logo yet. - Two independent chains, one function per step, suffixed
_lurio/_adnap:ingest_landings_*(R/ingestion.R),preprocess_landings_*(R/preprocessing-surveys.R),validate_surveys_*(R/validation.R). -
Only ADNAP feeds downstream products:
merge_trips()(joins PDS trips to validated ADNAP landings),export_api_raw()/export_api_validated()(R/api.R), and through themcoasts::summarize_data()andcoasts::export_portal()(Mongoportal-*). Lurio ends inexport_lurio_landings(), which writes its own summaries to themozambique-*pipeline database. -
export_landings()(R/export.R) is not called by the workflow. - Catch weight: ADNAP uses
calculate_catch_adnap()(R/model-taxa.R), called fromprocess_version_data(); Lurio usescalculate_catch_lurio()(R/preprocessing-surveys.R). Both: length-weight coefficients first, bucket count (n_buckets * weight_bucket) as fallback. Octopus (OCZ,OQC) lengths are arm-span, divided by 5.5 to mantle length before the L-W formula. -
Fisher-estimate override (ADNAP only): where
count_method == "3"the fisher’s own weight replaces the calculatedcatch_kg(inprocess_version_data()). Lurio carries the same columns but does not apply it. - Length-weight coefficients come from
getLWCoeffs()(R/model-taxa.R) with FishBase/SeaLifeBase releases pinned inconf$metadata$fishbase.FLYuses a hand-set coefficient that replaces the FishBase row.assert_taxa_coverage()stops the run if a taxon has no coefficient. - Retired KoBo taxon codes are remapped on read in
preprocess_landings_lurio():TUN -> TUS,SKH -> CVX,CLP -> ANX. Old submissions keep the old codes, so the remap stays even after the form changes. - Metadata (“assets”: taxa, gear, vessels, sites, geo) comes from Airtable, filtered to the current form via
get_airtable_form_id()+form_id_pattern(), and joined bymap_surveys(). - Validation flags are inline
dplyr::case_when()blocks inside eachvalidate_surveys_*():- Stage 1, per catch/trip: flags 1-7 and 12-13, into
alert_flag. - Stage 2, composite: flags 8-11 (price per kg, CPUE, RPUE, zero fishers), computed only for submissions with no stage-1 flag.
- Thresholds live in
inst/config.ymlundervalidation.lurioandvalidation.adnap(e.g.price_kg_max,max_length_cm), read at the top of eachvalidate_surveys_*(). Tune them there, not in code. - A flagged submission is dropped from the validated file unless a reviewer approved it, and one a reviewer rejected is dropped even without a flag (decisions from
survey_review_decisions(), which wrapscoasts::review_decisions()); the flags are pushed byexport_validation_flags()to Mongovalidation-*assurveys_flags-<asset_id>/enumerators_stats-<asset_id>.
- Stage 1, per catch/trip: flags 1-7 and 12-13, into
- Config keys:
conf$ingestion$<chain>(KoBo),conf$surveys$<chain>$<stage>$file_prefix(GCS prefixes).
Rules
- Add a validation flag as the next free number (14, 15, …) in both
validate_surveys_lurio()andvalidate_surveys_adnap()where it applies. Existing numbers are read by peskas-validation. - A change to catch weight or flags usually belongs in both chains; check the sibling function and say if you left one alone on purpose.
- Call the coasts version of Airtable and KoBo validation-status helpers. R/airtable.R and
fetch_asset()/form_id_pattern()in R/preprocessing-surveys.R are local copies of coasts functions; flag them when you touch them rather than extending them. - Keep the taxon remap and the
FLYoverride unless the task is to change them; both protect published catch.
Gotchas
- Env vars (see
.env.exampleandinst/config.yml):- KoBo:
KOBO_ASSET_ID_LURIO,KOBO_ASSET_ID_ADNAP,KOBO_USERNAME,KOBO_PASSWORD,KOBO_TOKEN. - Mongo:
MONGODB_CONNECTION_STRING(pipeline + portal),MONGODB_CONNECTION_STRING_VALIDATION(validation db). - Other:
GCP_SA_KEY,PDS_TOKEN,PDS_SECRET,AIRTABLE_TOKEN,AIRTABLE_BASE_ID_FRAME.
- KoBo:
-
ingest_landings_adnap()authenticates with the Lurio username and password (conf$ingestion$lurio);conf$ingestion$adnaphas no password. -
GOOGLE_SHEET_ID/metadata$google_sheetsin config is read by no code in this repo or in coasts. - Config profiles are only
defaultandproduction.