Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simsbiohub 496 bctw deployments script #1272

Merged
merged 18 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env: | setup ## Copies the default ./env_config/env.docker to ./.env

postgres: | close build-postgres run-postgres ## Performs all commands necessary to run the postgres project (db) in docker
backend: | close build-backend run-backend ## Performs all commands necessary to run all backend projects (db, api) in docker
web: | close build-web run-web ## Performs all commands necessary to run all backend+web projects (db, api, app) in docker
web: | close build-web check-env run-web ## Performs all commands necessary to run all backend+web projects (db, api, app) in docker

db-setup: | build-db-setup run-db-setup ## Performs all commands necessary to run the database migrations and seeding
db-migrate: | build-db-migrate run-db-migrate ## Performs all commands necessary to run the database migrations
Expand Down Expand Up @@ -62,6 +62,12 @@ prune: ## Deletes ALL docker artifacts (even those not associated to this projec
@docker system prune --all --volumes -f
@docker volume prune --all -f

check-env: ## Check for missing env vars
@echo "==============================================="
@echo "Make: check-env - check for missing env vars"
@echo "==============================================="
@awk_output=$$(awk -F= 'NR==FNR{a[$$1]; next} !($$1 in a)' .env env_config/env.docker); if [ -z "$$awk_output" ]; then echo "Up to date"; else echo "Missing ENV variables!\n$$awk_output"; fi

## ------------------------------------------------------------------------------
## Build/Run Postgres DB Commands
## - Builds all of the SIMS postgres db projects (db, db_setup)
Expand Down
5 changes: 5 additions & 0 deletions scripts/bctw-deployments/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore all files in this directory
files/*

!files/input.dev.json

104 changes: 104 additions & 0 deletions scripts/bctw-deployments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Generate SQL from existing BCTW Caribou deployments

## Purpose
SIMS needs to be updated to include existing BCTW deployments. This script combines BCTW deployments with
matching critters and injects Caribou region herd geometries.

## Pre requisites
1. BCTW SQL - Export valid telemetry collar deployments as JSON.
```sql
SELECT
deployment_id,
critter_id,
attachment_start
FROM collar_animal_assignment
WHERE bctw.is_valid(valid_to)
AND attachment_start IS NOT NULL;
```
2. Critterbase SQL - Export all caribou as JSON.
```sql
SELECT
c.critter_id,
u.unit_name
FROM
critter c
JOIN critter_collection_unit cc
ON
c.critter_id = cc.critter_id
JOIN xref_collection_unit u
ON
cc.collection_unit_id = u.collection_unit_id
WHERE
c.itis_tsn = 180701;
```
3. Create JSON file from previous outputs as single array.

- critter_deployments.json
```json
[
{
"critter_id": "A",
"unit_name": "Atlin"
},
{
"critter_id": "B",
"unit_name": "Atlin"
},
{
"deployment_id": "C",
"critter_id": "A",
"attachment_start": "2024-01-01",
},
{
"deployment_id": "D",
"critter_id": "B",
"attachment_start": "2024-01-01",
},
...
]

```

## How to run
1. Create input file.
2. Call run.sh with input file as argument.

```bash
./run.sh {input-filename}.json

# Dev example
./run.sh input.dev.json
```

## Requirements
- Ticket: [SIMSBIOHUB-496](https://apps.nrs.gov.bc.ca/int/jira/browse/SIMSBIOHUB-496)

As a biologist who had uploaded telemetry deployments to BCTW through the BCTW UI, I want to see those deployment IDs in a SIMS Survey.

When deciding what Survey to put a deployment ID in, group by deployment year and caribou herd.

For example,

- Telkwa herd 2021 would be a Survey
- Telkwa herd 2022 would be a Survey
- Porcupine herd 2022 would be a Survey

#### For every Survey, make a new Project with the following values:

- Name: Caribou herd name - telemetry
- Program: Wildlife
- Dates: Jan. 1 - Dec. 31 of {year}
- Objectives: Telemetry deployments for Caribou herd name in year.

#### For each Survey, include these values:

- Name: Caribou herd name - Year - telemetry
- Type: Monitoring
- Start date: Date of the earliest telemetry deployment in the Survey
- End date: Date of the last telemetry deployment in the Survey
- Species: Caribou
- Ecological Variables: Mortality, Distribution
- Site selection strategy: "Oportunistic" (have to add this as an option)
- Study area: Relevant herd's boundary


Loading
Loading