OpenFn / wcs-wildmeat

Wildlife Conservation Society ConSocSci Project
1 stars 0 forks source link

Update Offtake and Urban Consumption jobs to to ensure wildmeat_id is always unique #35

Closed daissatou2 closed 2 years ago

daissatou2 commented 2 years ago

Background, context, and business value

@lakhassane added this code to the Market job to make sure the wildmeat_id on tbl_wildmeat_market is always unique. Let's make a similar change to the other 2 jobs to ensure the wildmeat_id is always unique and to resolve this error: https://www.openfn.org/projects/p5yaxp/runs/0616ed56-cc8d-72cf-b796-58faa59b7b7b.

The specific request, in as few words as possible

  1. In the Offtake job, update wildmeat_id on tbl_wildmeat_hunter to map to animal['animal_details/species_id'] & the position of the animal item in the array. For example, in this state, the first entry for wildmeat_id would be 12601.

  2. In the Urban Consumption job, update wildmeat_id on tbl_wildmeat_urban to map to domeat_consumption/domeat_species & the position of the item in the string. For example, say we get this in state: "domeat_consumption/domeat_species": "100089 100086" The first entry would be 1000891 & the second one would be 1000862.

You can test your changes for Offtake by rerunning this transaction: https://www.openfn.org/projects/p5yaxp/runs/0616ed56-cc8d-72cf-b796-58faa59b7b7b.

state.json

Offtake: https://www.openfn.org/projects/p5yaxp/messages/0616ed56-b782-7182-8151-bfbb6b738a87 Urban Consumption: https://www.openfn.org/projects/p5yaxp/messages/0616db01-ca53-7b83-bdaf-26ca8be4c50b Postgres DB: See LP Wildmeat Postgres Transitional DB (WCS)

expression.js

Urban Consumption: https://github.com/OpenFn/wcs-wildmeat/blob/master/jobs/2.a.consommationUrbaine.js Offtake: https://github.com/OpenFn/wcs-wildmeat/blob/master/jobs/2.d.Offtake.js

lakhassane commented 2 years ago

@daissatou2 made the change to alway add the position for wildmeat_id