From 3cf8b71cac12578c81fad8d976b42fbd4bd9700c Mon Sep 17 00:00:00 2001 From: Andrew <105487051+LouisThedroux@users.noreply.github.com> Date: Fri, 30 Aug 2024 16:32:15 -0700 Subject: [PATCH 01/12] added new migration file and initial statements --- .../20240830000011_method_lookup_updates.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 database/src/migrations/20240830000011_method_lookup_updates.ts diff --git a/database/src/migrations/20240830000011_method_lookup_updates.ts b/database/src/migrations/20240830000011_method_lookup_updates.ts new file mode 100644 index 0000000000..42f939adf2 --- /dev/null +++ b/database/src/migrations/20240830000011_method_lookup_updates.ts @@ -0,0 +1,47 @@ +import { Knex } from 'knex'; + +/** + * Update method_lookup vlaues and associated attributes to accomodate spi-migration data and for other future data. + * + * This migration file updates values into method lookup table, technique attribute qual and quant tables, + * method lookup quant and qual and qualitative options and attractants + * + * @export + * @param {Knex} knex + * @return {*} {Promise} + */ +export async function up(knex: Knex): Promise { + await knex.raw(` + SET SEARCH_PATH=biohub, public; + +---------------------------------------------------------------------------------------- + --Adding more values to the method lookup table. +---------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------- +---------------------------------- TO DO LIST------------------------------------------- + +-- Include Update to Radio, adding variables such as device type with handheld or tower being qual options +-- Include Flight altitude to drone quant +-- Include Drone model and camera type to qualitative +-- Include Quant types for hair snag, height of snag, number of snags, Qual = Trap type (barbed wire, adhesive strips, brush station), substrate type, soil, rock, vegetation, -- -- material. +---------------------------------------------------------------------------------------- + INSERT into method_lookup (name, description) + VALUES + ( + 'Drone', + 'Using drones for ecological data collection involves capturing high-resolution imagery and spatial data to monitor wildlife and habitats efficiently and non-invasively' + ), + ( + 'Hair snag', + 'Hair snag involves collecting hair samples from wildlife using specially designed devices to non-invasively monitor species presence, genetic diversity, and health.' + ), + ( + 'Undetermined', + 'Method of data collection not specified or insufficient data to determine the method' + ) + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(``); +} From a3b31ebd7af3ff59f33aa39750ff9050a641aa67 Mon Sep 17 00:00:00 2001 From: Andrew <105487051+LouisThedroux@users.noreply.github.com> Date: Tue, 3 Sep 2024 14:54:04 -0700 Subject: [PATCH 02/12] initial commit, currently working. Needs tidying --- .../20240830000011_method_lookup_updates.ts | 380 +++++++++++++++++- 1 file changed, 361 insertions(+), 19 deletions(-) diff --git a/database/src/migrations/20240830000011_method_lookup_updates.ts b/database/src/migrations/20240830000011_method_lookup_updates.ts index 42f939adf2..e763d9ce3a 100644 --- a/database/src/migrations/20240830000011_method_lookup_updates.ts +++ b/database/src/migrations/20240830000011_method_lookup_updates.ts @@ -14,32 +14,374 @@ export async function up(knex: Knex): Promise { await knex.raw(` SET SEARCH_PATH=biohub, public; + ---------------------------------------------------------------------------------------- - --Adding more values to the method lookup table. +---------------------------------- TO DO LIST------------------------------------------- + ---------------------------------------------------------------------------------------- +---------------------------------Insert new values-------------------------------------- ---------------------------------------------------------------------------------------- ----------------------------------- TO DO LIST------------------------------------------- - --- Include Update to Radio, adding variables such as device type with handheld or tower being qual options --- Include Flight altitude to drone quant --- Include Drone model and camera type to qualitative --- Include Quant types for hair snag, height of snag, number of snags, Qual = Trap type (barbed wire, adhesive strips, brush station), substrate type, soil, rock, vegetation, -- -- material. +-- In this sesction. I have inserted the method lookup values for drone , hair snag and undetermined. +-- along with all the appropriate attributes and units. ---------------------------------------------------------------------------------------- - INSERT into method_lookup (name, description) - VALUES + +-- Insert into method_lookup table +INSERT INTO method_lookup (name, description) +VALUES + ('Drone', 'Using drones for ecological data collection involves capturing high-resolution imagery and spatial data to monitor wildlife and habitats efficiently and non-invasively.'), + ('Hair snag', 'Hair snag involves collecting hair samples from wildlife using specially designed devices to non-invasively monitor species presence, genetic diversity, and health.'), + ('Undetermined', 'Method of data collection not specified or insufficient data to determine the method.'); + +-- Insert into technique_attribute_quantitative table +INSERT INTO technique_attribute_quantitative (name, description) +VALUES + ('Altitude', 'The elevation above sea level at which ecological data is collected, influencing environmental conditions and species distribution.'), + ('Height of snag', 'The vertical distance from the ground to the placement of the hair snagging device, which can influence the likelihood of collecting hair samples from different species.'), + ('Number of snags', 'The total count of hair snagging devices deployed within a study area, used to estimate sampling effort and potential data coverage.'); + + +INSERT INTO method_lookup_attribute_quantitative (technique_attribute_quantitative_id, method_lookup_id, min, max, unit) +VALUES + ( + (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Altitude'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Drone'), + 0, 10000, 'meter' + ), + ( + (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Height of snag'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag'), + 0, 1000, 'centimeter' + ), + ( + (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Number of snags'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag'), + 0, 100, 'count' + ); + +-- Insert into technique_attribute_qualitative table +INSERT INTO technique_attribute_qualitative (name, description) +VALUES + ('Drone model', 'The specific make and model of the drone used in ecological studies, important for documenting the capabilities and limitations of the equipment.'), + ('Drone camera type', 'The type of camera mounted on the drone, such as RGB, thermal, or multispectral, which determines the kind of data captured during ecological surveys.'), + ('Hair snag trap type', 'The specific design or material of the hair snagging device, including options like barbed wire, adhesive strips, or brush stations, which influence the effectiveness of sample collection.'), + ('Hair snag substrate type', 'The type of surface or material on which the hair snag device is placed, such as soil, rock, or vegetation, affecting the likelihood of successful sample collection.'), + ('Hair snag material', 'Material the snag is comprised of.'); + +-- Insert into method_lookup_attribute_qualitative table +INSERT INTO method_lookup_attribute_qualitative (technique_attribute_qualitative_id, method_lookup_id) +VALUES + ( + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Drone model'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Drone') + ), + ( + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Drone camera type'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Drone') + ), ( - 'Drone', - 'Using drones for ecological data collection involves capturing high-resolution imagery and spatial data to monitor wildlife and habitats efficiently and non-invasively' + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Hair snag trap type'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag') ), - ( - 'Hair snag', - 'Hair snag involves collecting hair samples from wildlife using specially designed devices to non-invasively monitor species presence, genetic diversity, and health.' + ( + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Hair snag substrate type'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag') + ), + ( + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Hair snag material'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag') + ); + + +-- Insert options for Drone model +INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) +VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone model' AND ml.name = 'Drone' + ), + 'DJI', + 'A leading Chinese manufacturer known for consumer and professional drones like the Phantom, Mavic, and Matrice series.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone model' AND ml.name = 'Drone' + ), + 'Parrot', + 'A French company known for its Bebop and Anafi drone models.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone model' AND ml.name = 'Drone' + ), + 'Yuneec', + 'A Chinese company that offers drones such as the Typhoon and H520 models.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone model' AND ml.name = 'Drone' + ), + 'Autel Robotics', + 'An American company known for the EVO series drones.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone model' AND ml.name = 'Drone' + ), + 'Skydio', + 'An American manufacturer recognized for its autonomous drones like the Skydio 2.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone model' AND ml.name = 'Drone' + ), + 'Other', + 'Other Manufacturer that is not listed. Please consider recording the manufacturer details in the technique description.' + ); + + +INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) +VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone camera type' AND ml.name = 'Drone' + ), + 'RGB camera', + 'A standard color camera that captures high-resolution images and videos in the visible light spectrum, commonly used for general photography and videography.' ), - ( - 'Undetermined', - 'Method of data collection not specified or insufficient data to determine the method' - ) - `); + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone camera type' AND ml.name = 'Drone' + ), + 'Thermal camera', + 'A camera that detects infrared radiation and captures temperature variations, useful for monitoring wildlife, detecting heat sources, and conducting search and rescue operations.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone camera type' AND ml.name = 'Drone' + ), + 'Multispectral camera', + 'A camera that captures data across multiple wavelengths, including visible and near-infrared, enabling detailed analysis of vegetation health, water quality, and land use.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Drone camera type' AND ml.name = 'Drone' + ), + 'LiDAR', + 'A remote sensing technology that uses laser pulses to create precise 3D models of landscapes, vegetation, and structures, often used in topographic mapping and forestry.' + ); +-- Insert qualitative options for Hair snag trap type +INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) +VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Hair snag trap type' AND ml.name = 'Hair snag' + ), + 'Barbed wire', + 'A trap type using strands of barbed wire to snag hair samples from passing animals, commonly used in large mammal studies.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Hair snag trap type' AND ml.name = 'Hair snag' + ), + 'Adhesive Strips', + 'Sticky strips placed strategically to capture hair samples from animals as they brush against them, useful for small to medium-sized mammals.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Hair snag trap type' AND ml.name = 'Hair snag' + ), + 'Brush Station', + 'A trap setup involving brushes that collect hair samples as animals rub against them, often used for non-invasive sampling of species.' + ); +-- Insert qualitative options for Hair snag substrate type +INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) +VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Hair snag substrate type' AND ml.name = 'Hair snag' + ), + 'Soil', + 'The trap is placed on or near the soil surface, targeting ground-dwelling species and those with low-ranging movements.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Hair snag substrate type' AND ml.name = 'Hair snag' + ), + 'Rock', + 'The trap is set on or near rocky terrain, suitable for species that inhabit or traverse rocky landscapes.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Hair snag substrate type' AND ml.name = 'Hair snag' + ), + 'Vegetation', + 'The trap is situated within or near vegetation, ideal for capturing samples from species that frequent wooded or bushy areas.' + ); + + -- Insert qualitative options for Hair snag material +INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) +VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Hair snag material' AND ml.name = 'Hair snag' + ), + 'Metal', + 'The trap or snagging device is made of metal, providing durability and resistance to environmental conditions.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Hair snag material' AND ml.name = 'Hair snag' + ), + 'Plastic', + 'The trap is constructed from plastic, offering a lightweight and often more affordable option for various ecological studies.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Hair snag material' AND ml.name = 'Hair snag' + ), + 'Natural Fiber', + 'The trap is made from natural fibers, blending into the environment and minimizing impact on the ecosystem.' + ); + + + + +---------------------------------------------------------------------------------------- +------------------------------Update Radar Tower Entry.--------------------------------- +---------------------------------------------------------------------------------------- +--In this section, I updated the previous value of radio signal tower to incorporate handheld radios +--Broadening the higher classifaction and creating attributes for the user to refine their modality as an attribute +---------------------------------------------------------------------------------------- + UPDATE method_lookup + SET name = 'Radio', + description = 'The use of radio waves as a method to track, monitor, or communicate with tagged animals or devices, including handheld and other radio wave-based equipment.' + WHERE name = 'Radio signal tower'; + + UPDATE technique_attribute_quantitative + SET description = 'Frequency refers to the specific radio wave band at which the transmitter on the animal and the receiver communicate to ensure accurate tracking and data transmission.' + WHERE name = 'Radio frequency'; + + INSERT INTO technique_attribute_qualitative + (name, description) + VALUES + ('Modality', 'The form which radio technology is utilized for recording ecological data, such as handheld radios or radio towers.'); + + + INSERT INTO method_lookup_attribute_qualitative + (technique_attribute_qualitative_id, method_lookup_id) + VALUES + ( + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Modality'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radio')); + + INSERT INTO method_lookup_attribute_qualitative_option + (method_lookup_attribute_qualitative_id, name, description) + VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Modality' AND ml.name = 'Radio' + ), + 'Handheld radio', + 'A portable, handheld radio device used for communication and data transmission in ecological studies.' + ); + + + INSERT INTO method_lookup_attribute_qualitative_option + (method_lookup_attribute_qualitative_id, name, description) + VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Modality' AND ml.name = 'Radio' + ), + 'Radio tower', + 'A stationary structure equipped with a radio transmitter and receiver used for long-range data communication in ecological monitoring.' + ); + + `); } export async function down(knex: Knex): Promise { From 923dfc7911daba4b5a01beb958df211a782b1989 Mon Sep 17 00:00:00 2001 From: Andrew <105487051+LouisThedroux@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:53:32 -0700 Subject: [PATCH 03/12] adding audio encounter and tidying --- .../20240830000011_method_lookup_updates.ts | 82 ++++++++++++++++--- 1 file changed, 69 insertions(+), 13 deletions(-) diff --git a/database/src/migrations/20240830000011_method_lookup_updates.ts b/database/src/migrations/20240830000011_method_lookup_updates.ts index e763d9ce3a..a1fa0f5cfa 100644 --- a/database/src/migrations/20240830000011_method_lookup_updates.ts +++ b/database/src/migrations/20240830000011_method_lookup_updates.ts @@ -14,12 +14,8 @@ export async function up(knex: Knex): Promise { await knex.raw(` SET SEARCH_PATH=biohub, public; - ----------------------------------------------------------------------------------------- ----------------------------------- TO DO LIST------------------------------------------- - ---------------------------------------------------------------------------------------- ----------------------------------Insert new values-------------------------------------- +---------------------------------Insert new ml values-------------------------------------- ---------------------------------------------------------------------------------------- -- In this sesction. I have inserted the method lookup values for drone , hair snag and undetermined. -- along with all the appropriate attributes and units. @@ -30,14 +26,20 @@ INSERT INTO method_lookup (name, description) VALUES ('Drone', 'Using drones for ecological data collection involves capturing high-resolution imagery and spatial data to monitor wildlife and habitats efficiently and non-invasively.'), ('Hair snag', 'Hair snag involves collecting hair samples from wildlife using specially designed devices to non-invasively monitor species presence, genetic diversity, and health.'), - ('Undetermined', 'Method of data collection not specified or insufficient data to determine the method.'); + ('Undetermined', 'Method of data collection not specified or insufficient data to determine the method.'), + ('Audio encounter', 'A method of collecting ecological data by recording or listening to sounds in the environment to monitor and identify species presence, behavior, and interactions.'); -- Insert into technique_attribute_quantitative table INSERT INTO technique_attribute_quantitative (name, description) VALUES ('Altitude', 'The elevation above sea level at which ecological data is collected, influencing environmental conditions and species distribution.'), ('Height of snag', 'The vertical distance from the ground to the placement of the hair snagging device, which can influence the likelihood of collecting hair samples from different species.'), - ('Number of snags', 'The total count of hair snagging devices deployed within a study area, used to estimate sampling effort and potential data coverage.'); + ('Number of snags', 'The total count of hair snagging devices deployed within a study area, used to estimate sampling effort and potential data coverage.'), + ('Audio frequency range','The range of frequencies captured during the audio encounter, important for detecting different species vocalizations, from low-frequency calls to high-pitched signals.'); + +---------------------------------------------------------------------------------------- +--Inserting quant attributtes for all the above. +---------------------------------------------------------------------------------------- INSERT INTO method_lookup_attribute_quantitative (technique_attribute_quantitative_id, method_lookup_id, min, max, unit) @@ -56,16 +58,22 @@ VALUES (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Number of snags'), (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag'), 0, 100, 'count' + ), + ( + (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Audio frequency range'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Audio encounter'), + 0, 20000, 'Hz' ); --- Insert into technique_attribute_qualitative table + INSERT INTO technique_attribute_qualitative (name, description) VALUES ('Drone model', 'The specific make and model of the drone used in ecological studies, important for documenting the capabilities and limitations of the equipment.'), ('Drone camera type', 'The type of camera mounted on the drone, such as RGB, thermal, or multispectral, which determines the kind of data captured during ecological surveys.'), ('Hair snag trap type', 'The specific design or material of the hair snagging device, including options like barbed wire, adhesive strips, or brush stations, which influence the effectiveness of sample collection.'), ('Hair snag substrate type', 'The type of surface or material on which the hair snag device is placed, such as soil, rock, or vegetation, affecting the likelihood of successful sample collection.'), - ('Hair snag material', 'Material the snag is comprised of.'); + ('Hair snag material', 'Material the snag is comprised of.'), + ('Audio device type', 'The specific tool or equipment used to capture or detect sounds during an audio encounter, including handheld recorders, fixed microphones, parabolic microphones, or unaided human listening.'); -- Insert into method_lookup_attribute_qualitative table INSERT INTO method_lookup_attribute_qualitative (technique_attribute_qualitative_id, method_lookup_id) @@ -89,10 +97,13 @@ VALUES ( (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Hair snag material'), (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag') + ), + ( + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Audio device type'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Audio encounter') ); --- Insert options for Drone model INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) VALUES ( @@ -319,15 +330,60 @@ VALUES 'The trap is made from natural fibers, blending into the environment and minimizing impact on the ecosystem.' ); - - + INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) +VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Audio device type' AND ml.name = 'Audio encounter' + ), + 'Handheld Recorder', + 'A portable device used for capturing audio in the field, offering flexibility but potentially influenced by the operators movements.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Audio device type' AND ml.name = 'Audio encounter' + ), + 'Fixed Microphone', + 'A stationary microphone placed in a specific location to continuously capture audio, often used for long-term monitoring.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Audio device type' AND ml.name = 'Audio encounter' + ), + 'Parabolic Microphone', + 'A specialized microphone that uses a parabolic reflector to capture distant sounds with high directionality, ideal for isolating specific vocalizations.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Audio device type' AND ml.name = 'Audio encounter' + ), + 'Unaided Ear', + 'Direct human auditory observation without the use of recording devices, relying on the observers hearing to detect and identify sounds in the environment.' + ); ---------------------------------------------------------------------------------------- ------------------------------Update Radar Tower Entry.--------------------------------- ---------------------------------------------------------------------------------------- --In this section, I updated the previous value of radio signal tower to incorporate handheld radios --Broadening the higher classifaction and creating attributes for the user to refine their modality as an attribute ----------------------------------------------------------------------------------------- + + UPDATE method_lookup SET name = 'Radio', description = 'The use of radio waves as a method to track, monitor, or communicate with tagged animals or devices, including handheld and other radio wave-based equipment.' From c22f99a3625346353b7cd1ee8ae5bb58b1284312 Mon Sep 17 00:00:00 2001 From: Andrew <105487051+LouisThedroux@users.noreply.github.com> Date: Wed, 4 Sep 2024 11:04:47 -0700 Subject: [PATCH 04/12] fix --- database/src/migrations/20240830000011_method_lookup_updates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/src/migrations/20240830000011_method_lookup_updates.ts b/database/src/migrations/20240830000011_method_lookup_updates.ts index a1fa0f5cfa..b88f0b1d5c 100644 --- a/database/src/migrations/20240830000011_method_lookup_updates.ts +++ b/database/src/migrations/20240830000011_method_lookup_updates.ts @@ -1,7 +1,7 @@ import { Knex } from 'knex'; /** - * Update method_lookup vlaues and associated attributes to accomodate spi-migration data and for other future data. + * Update method_lookup vlaues and associated attributes to accomodate spi-migration data and for other future data. * * This migration file updates values into method lookup table, technique attribute qual and quant tables, * method lookup quant and qual and qualitative options and attractants From 79ccb77e804d16cc2eaa3b77a34522a75d66a5ab Mon Sep 17 00:00:00 2001 From: Andrew <105487051+LouisThedroux@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:35:28 -0700 Subject: [PATCH 05/12] tidying --- .../20240830000011_method_lookup_updates.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/database/src/migrations/20240830000011_method_lookup_updates.ts b/database/src/migrations/20240830000011_method_lookup_updates.ts index b88f0b1d5c..f8a94904d8 100644 --- a/database/src/migrations/20240830000011_method_lookup_updates.ts +++ b/database/src/migrations/20240830000011_method_lookup_updates.ts @@ -1,9 +1,9 @@ import { Knex } from 'knex'; /** - * Update method_lookup vlaues and associated attributes to accomodate spi-migration data and for other future data. + * Update method_lookup values and associated attributes to accomodate spi-migration data and for other future data. * - * This migration file updates values into method lookup table, technique attribute qual and quant tables, + * This migration file inserts or updates values into method lookup table, technique attribute qual and quant tables, * method lookup quant and qual and qualitative options and attractants * * @export @@ -17,7 +17,7 @@ export async function up(knex: Knex): Promise { ---------------------------------------------------------------------------------------- ---------------------------------Insert new ml values-------------------------------------- ---------------------------------------------------------------------------------------- --- In this sesction. I have inserted the method lookup values for drone , hair snag and undetermined. +-- In this sesction. I have inserted the method lookup values for Drone, Audio encounter, Hair snag and Undetermined. -- along with all the appropriate attributes and units. ---------------------------------------------------------------------------------------- @@ -38,10 +38,9 @@ VALUES ('Audio frequency range','The range of frequencies captured during the audio encounter, important for detecting different species vocalizations, from low-frequency calls to high-pitched signals.'); ---------------------------------------------------------------------------------------- ---Inserting quant attributtes for all the above. +--Inserting quant attributtes, min, max and units for Drone, Audio encounter, Hair snag. ---------------------------------------------------------------------------------------- - INSERT INTO method_lookup_attribute_quantitative (technique_attribute_quantitative_id, method_lookup_id, min, max, unit) VALUES ( @@ -65,6 +64,9 @@ VALUES 0, 20000, 'Hz' ); +---------------------------------------------------------------------------------------- +--Inserting qualitative names and descriptions for Drone, Audio encounter, Hair snag. +---------------------------------------------------------------------------------------- INSERT INTO technique_attribute_qualitative (name, description) VALUES @@ -75,6 +77,10 @@ VALUES ('Hair snag material', 'Material the snag is comprised of.'), ('Audio device type', 'The specific tool or equipment used to capture or detect sounds during an audio encounter, including handheld recorders, fixed microphones, parabolic microphones, or unaided human listening.'); +---------------------------------------------------------------------------------------- +--Inserting associations for method lookups and their qualitative attributes +---------------------------------------------------------------------------------------- + -- Insert into method_lookup_attribute_qualitative table INSERT INTO method_lookup_attribute_qualitative (technique_attribute_qualitative_id, method_lookup_id) VALUES @@ -103,6 +109,9 @@ VALUES (SELECT method_lookup_id FROM method_lookup WHERE name = 'Audio encounter') ); +---------------------------------------------------------------------------------------- +--Inserting options for the above qualitative attributes +---------------------------------------------------------------------------------------- INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) VALUES From c54d23d9f8a096551b88775a0c50aa9a50da5659 Mon Sep 17 00:00:00 2001 From: Meijer Date: Fri, 6 Sep 2024 15:48:12 -0700 Subject: [PATCH 06/12] adding subcount sign migration --- .../20240906000000_add_subcount_sign.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 database/src/migrations/20240906000000_add_subcount_sign.ts diff --git a/database/src/migrations/20240906000000_add_subcount_sign.ts b/database/src/migrations/20240906000000_add_subcount_sign.ts new file mode 100644 index 0000000000..0026a14737 --- /dev/null +++ b/database/src/migrations/20240906000000_add_subcount_sign.ts @@ -0,0 +1,27 @@ +import { Knex } from 'knex'; + +/** + * Update observation_subcount_sign value to accomodate spi-migration data and for other future data. + * + * This migration file inserts values into observation subcount sign table, + * + * @export + * @param {Knex} knex + * @return {*} {Promise} + */ +export async function up(knex: Knex): Promise { + await knex.raw(` + SET SEARCH_PATH=biohub, public; + +---------------------------------------------------------------------------------------- +---------------------------------Insert new oss values-------------------------------------- +---------------------------------------------------------------------------------------- + INSERT INTO biohub.observation_subcount_sign (create_date, name, description) + VALUES (now(), 'Rub or scratch spot', 'This observation was made due to evidence associated with a rubbing or scratch mark created by am animal'); + + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(``); +} From f22232ab333ff5742e957db600f6d002d0c4b339 Mon Sep 17 00:00:00 2001 From: Meijer Date: Fri, 6 Sep 2024 15:51:10 -0700 Subject: [PATCH 07/12] i had made a typo, also still need to make fix --- database/src/migrations/20240906000000_add_subcount_sign.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/src/migrations/20240906000000_add_subcount_sign.ts b/database/src/migrations/20240906000000_add_subcount_sign.ts index 0026a14737..6cbbbc167d 100644 --- a/database/src/migrations/20240906000000_add_subcount_sign.ts +++ b/database/src/migrations/20240906000000_add_subcount_sign.ts @@ -17,7 +17,7 @@ export async function up(knex: Knex): Promise { ---------------------------------Insert new oss values-------------------------------------- ---------------------------------------------------------------------------------------- INSERT INTO biohub.observation_subcount_sign (create_date, name, description) - VALUES (now(), 'Rub or scratch spot', 'This observation was made due to evidence associated with a rubbing or scratch mark created by am animal'); + VALUES (now(), 'Rub or scratch spot', 'This observation was made due to evidence associated with a rubbing or scratch mark created by an animal'); `); } From 521cbcf3e0e5e6ed03efaa06cd14764c9c9a3332 Mon Sep 17 00:00:00 2001 From: Thompson Date: Tue, 10 Sep 2024 16:20:53 -0700 Subject: [PATCH 08/12] make test and fix --- database/src/migrations/20240906000000_add_subcount_sign.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/src/migrations/20240906000000_add_subcount_sign.ts b/database/src/migrations/20240906000000_add_subcount_sign.ts index 6cbbbc167d..d5d18a11db 100644 --- a/database/src/migrations/20240906000000_add_subcount_sign.ts +++ b/database/src/migrations/20240906000000_add_subcount_sign.ts @@ -3,7 +3,7 @@ import { Knex } from 'knex'; /** * Update observation_subcount_sign value to accomodate spi-migration data and for other future data. * - * This migration file inserts values into observation subcount sign table, + * This migration file inserts values into observation subcount sign table, * * @export * @param {Knex} knex From 1a833ce7b7332368248b47e9ed8d67c3b2a876b9 Mon Sep 17 00:00:00 2001 From: Macgregor Aubertin-Young Date: Wed, 11 Sep 2024 11:31:38 -0700 Subject: [PATCH 09/12] improve migration readability and remove some reference data --- api/src/repositories/code-repository.ts | 1 + .../20240830000011_method_lookup_updates.ts | 454 ------------------ .../20240906000000_add_subcount_sign.ts | 27 -- .../20240911000011_method_lookup_updates.ts | 233 +++++++++ 4 files changed, 234 insertions(+), 481 deletions(-) delete mode 100644 database/src/migrations/20240830000011_method_lookup_updates.ts delete mode 100644 database/src/migrations/20240906000000_add_subcount_sign.ts create mode 100644 database/src/migrations/20240911000011_method_lookup_updates.ts diff --git a/api/src/repositories/code-repository.ts b/api/src/repositories/code-repository.ts index 2ededfc12f..a56db94b8c 100644 --- a/api/src/repositories/code-repository.ts +++ b/api/src/repositories/code-repository.ts @@ -59,6 +59,7 @@ export class CodeRepository extends BaseRepository { name, description FROM method_lookup + WHERE record_end_date < now() ORDER BY name ASC; `; diff --git a/database/src/migrations/20240830000011_method_lookup_updates.ts b/database/src/migrations/20240830000011_method_lookup_updates.ts deleted file mode 100644 index f8a94904d8..0000000000 --- a/database/src/migrations/20240830000011_method_lookup_updates.ts +++ /dev/null @@ -1,454 +0,0 @@ -import { Knex } from 'knex'; - -/** - * Update method_lookup values and associated attributes to accomodate spi-migration data and for other future data. - * - * This migration file inserts or updates values into method lookup table, technique attribute qual and quant tables, - * method lookup quant and qual and qualitative options and attractants - * - * @export - * @param {Knex} knex - * @return {*} {Promise} - */ -export async function up(knex: Knex): Promise { - await knex.raw(` - SET SEARCH_PATH=biohub, public; - ----------------------------------------------------------------------------------------- ----------------------------------Insert new ml values-------------------------------------- ----------------------------------------------------------------------------------------- --- In this sesction. I have inserted the method lookup values for Drone, Audio encounter, Hair snag and Undetermined. --- along with all the appropriate attributes and units. ----------------------------------------------------------------------------------------- - --- Insert into method_lookup table -INSERT INTO method_lookup (name, description) -VALUES - ('Drone', 'Using drones for ecological data collection involves capturing high-resolution imagery and spatial data to monitor wildlife and habitats efficiently and non-invasively.'), - ('Hair snag', 'Hair snag involves collecting hair samples from wildlife using specially designed devices to non-invasively monitor species presence, genetic diversity, and health.'), - ('Undetermined', 'Method of data collection not specified or insufficient data to determine the method.'), - ('Audio encounter', 'A method of collecting ecological data by recording or listening to sounds in the environment to monitor and identify species presence, behavior, and interactions.'); - --- Insert into technique_attribute_quantitative table -INSERT INTO technique_attribute_quantitative (name, description) -VALUES - ('Altitude', 'The elevation above sea level at which ecological data is collected, influencing environmental conditions and species distribution.'), - ('Height of snag', 'The vertical distance from the ground to the placement of the hair snagging device, which can influence the likelihood of collecting hair samples from different species.'), - ('Number of snags', 'The total count of hair snagging devices deployed within a study area, used to estimate sampling effort and potential data coverage.'), - ('Audio frequency range','The range of frequencies captured during the audio encounter, important for detecting different species vocalizations, from low-frequency calls to high-pitched signals.'); - ----------------------------------------------------------------------------------------- ---Inserting quant attributtes, min, max and units for Drone, Audio encounter, Hair snag. ----------------------------------------------------------------------------------------- - -INSERT INTO method_lookup_attribute_quantitative (technique_attribute_quantitative_id, method_lookup_id, min, max, unit) -VALUES - ( - (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Altitude'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Drone'), - 0, 10000, 'meter' - ), - ( - (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Height of snag'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag'), - 0, 1000, 'centimeter' - ), - ( - (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Number of snags'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag'), - 0, 100, 'count' - ), - ( - (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Audio frequency range'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Audio encounter'), - 0, 20000, 'Hz' - ); - ----------------------------------------------------------------------------------------- ---Inserting qualitative names and descriptions for Drone, Audio encounter, Hair snag. ----------------------------------------------------------------------------------------- - -INSERT INTO technique_attribute_qualitative (name, description) -VALUES - ('Drone model', 'The specific make and model of the drone used in ecological studies, important for documenting the capabilities and limitations of the equipment.'), - ('Drone camera type', 'The type of camera mounted on the drone, such as RGB, thermal, or multispectral, which determines the kind of data captured during ecological surveys.'), - ('Hair snag trap type', 'The specific design or material of the hair snagging device, including options like barbed wire, adhesive strips, or brush stations, which influence the effectiveness of sample collection.'), - ('Hair snag substrate type', 'The type of surface or material on which the hair snag device is placed, such as soil, rock, or vegetation, affecting the likelihood of successful sample collection.'), - ('Hair snag material', 'Material the snag is comprised of.'), - ('Audio device type', 'The specific tool or equipment used to capture or detect sounds during an audio encounter, including handheld recorders, fixed microphones, parabolic microphones, or unaided human listening.'); - ----------------------------------------------------------------------------------------- ---Inserting associations for method lookups and their qualitative attributes ----------------------------------------------------------------------------------------- - --- Insert into method_lookup_attribute_qualitative table -INSERT INTO method_lookup_attribute_qualitative (technique_attribute_qualitative_id, method_lookup_id) -VALUES - ( - (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Drone model'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Drone') - ), - ( - (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Drone camera type'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Drone') - ), - ( - (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Hair snag trap type'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag') - ), - ( - (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Hair snag substrate type'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag') - ), - ( - (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Hair snag material'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag') - ), - ( - (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Audio device type'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Audio encounter') - ); - ----------------------------------------------------------------------------------------- ---Inserting options for the above qualitative attributes ----------------------------------------------------------------------------------------- - -INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) -VALUES - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone model' AND ml.name = 'Drone' - ), - 'DJI', - 'A leading Chinese manufacturer known for consumer and professional drones like the Phantom, Mavic, and Matrice series.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone model' AND ml.name = 'Drone' - ), - 'Parrot', - 'A French company known for its Bebop and Anafi drone models.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone model' AND ml.name = 'Drone' - ), - 'Yuneec', - 'A Chinese company that offers drones such as the Typhoon and H520 models.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone model' AND ml.name = 'Drone' - ), - 'Autel Robotics', - 'An American company known for the EVO series drones.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone model' AND ml.name = 'Drone' - ), - 'Skydio', - 'An American manufacturer recognized for its autonomous drones like the Skydio 2.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone model' AND ml.name = 'Drone' - ), - 'Other', - 'Other Manufacturer that is not listed. Please consider recording the manufacturer details in the technique description.' - ); - - -INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) -VALUES - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone camera type' AND ml.name = 'Drone' - ), - 'RGB camera', - 'A standard color camera that captures high-resolution images and videos in the visible light spectrum, commonly used for general photography and videography.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone camera type' AND ml.name = 'Drone' - ), - 'Thermal camera', - 'A camera that detects infrared radiation and captures temperature variations, useful for monitoring wildlife, detecting heat sources, and conducting search and rescue operations.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone camera type' AND ml.name = 'Drone' - ), - 'Multispectral camera', - 'A camera that captures data across multiple wavelengths, including visible and near-infrared, enabling detailed analysis of vegetation health, water quality, and land use.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Drone camera type' AND ml.name = 'Drone' - ), - 'LiDAR', - 'A remote sensing technology that uses laser pulses to create precise 3D models of landscapes, vegetation, and structures, often used in topographic mapping and forestry.' - ); --- Insert qualitative options for Hair snag trap type -INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) -VALUES - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Hair snag trap type' AND ml.name = 'Hair snag' - ), - 'Barbed wire', - 'A trap type using strands of barbed wire to snag hair samples from passing animals, commonly used in large mammal studies.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Hair snag trap type' AND ml.name = 'Hair snag' - ), - 'Adhesive Strips', - 'Sticky strips placed strategically to capture hair samples from animals as they brush against them, useful for small to medium-sized mammals.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Hair snag trap type' AND ml.name = 'Hair snag' - ), - 'Brush Station', - 'A trap setup involving brushes that collect hair samples as animals rub against them, often used for non-invasive sampling of species.' - ); --- Insert qualitative options for Hair snag substrate type -INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) -VALUES - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Hair snag substrate type' AND ml.name = 'Hair snag' - ), - 'Soil', - 'The trap is placed on or near the soil surface, targeting ground-dwelling species and those with low-ranging movements.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Hair snag substrate type' AND ml.name = 'Hair snag' - ), - 'Rock', - 'The trap is set on or near rocky terrain, suitable for species that inhabit or traverse rocky landscapes.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Hair snag substrate type' AND ml.name = 'Hair snag' - ), - 'Vegetation', - 'The trap is situated within or near vegetation, ideal for capturing samples from species that frequent wooded or bushy areas.' - ); - - -- Insert qualitative options for Hair snag material -INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) -VALUES - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Hair snag material' AND ml.name = 'Hair snag' - ), - 'Metal', - 'The trap or snagging device is made of metal, providing durability and resistance to environmental conditions.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Hair snag material' AND ml.name = 'Hair snag' - ), - 'Plastic', - 'The trap is constructed from plastic, offering a lightweight and often more affordable option for various ecological studies.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Hair snag material' AND ml.name = 'Hair snag' - ), - 'Natural Fiber', - 'The trap is made from natural fibers, blending into the environment and minimizing impact on the ecosystem.' - ); - - INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) -VALUES - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Audio device type' AND ml.name = 'Audio encounter' - ), - 'Handheld Recorder', - 'A portable device used for capturing audio in the field, offering flexibility but potentially influenced by the operators movements.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Audio device type' AND ml.name = 'Audio encounter' - ), - 'Fixed Microphone', - 'A stationary microphone placed in a specific location to continuously capture audio, often used for long-term monitoring.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Audio device type' AND ml.name = 'Audio encounter' - ), - 'Parabolic Microphone', - 'A specialized microphone that uses a parabolic reflector to capture distant sounds with high directionality, ideal for isolating specific vocalizations.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Audio device type' AND ml.name = 'Audio encounter' - ), - 'Unaided Ear', - 'Direct human auditory observation without the use of recording devices, relying on the observers hearing to detect and identify sounds in the environment.' - ); - ----------------------------------------------------------------------------------------- -------------------------------Update Radar Tower Entry.--------------------------------- ----------------------------------------------------------------------------------------- ---In this section, I updated the previous value of radio signal tower to incorporate handheld radios ---Broadening the higher classifaction and creating attributes for the user to refine their modality as an attribute - - - UPDATE method_lookup - SET name = 'Radio', - description = 'The use of radio waves as a method to track, monitor, or communicate with tagged animals or devices, including handheld and other radio wave-based equipment.' - WHERE name = 'Radio signal tower'; - - UPDATE technique_attribute_quantitative - SET description = 'Frequency refers to the specific radio wave band at which the transmitter on the animal and the receiver communicate to ensure accurate tracking and data transmission.' - WHERE name = 'Radio frequency'; - - INSERT INTO technique_attribute_qualitative - (name, description) - VALUES - ('Modality', 'The form which radio technology is utilized for recording ecological data, such as handheld radios or radio towers.'); - - - INSERT INTO method_lookup_attribute_qualitative - (technique_attribute_qualitative_id, method_lookup_id) - VALUES - ( - (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Modality'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radio')); - - INSERT INTO method_lookup_attribute_qualitative_option - (method_lookup_attribute_qualitative_id, name, description) - VALUES - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Modality' AND ml.name = 'Radio' - ), - 'Handheld radio', - 'A portable, handheld radio device used for communication and data transmission in ecological studies.' - ); - - - INSERT INTO method_lookup_attribute_qualitative_option - (method_lookup_attribute_qualitative_id, name, description) - VALUES - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Modality' AND ml.name = 'Radio' - ), - 'Radio tower', - 'A stationary structure equipped with a radio transmitter and receiver used for long-range data communication in ecological monitoring.' - ); - - `); -} - -export async function down(knex: Knex): Promise { - await knex.raw(``); -} diff --git a/database/src/migrations/20240906000000_add_subcount_sign.ts b/database/src/migrations/20240906000000_add_subcount_sign.ts deleted file mode 100644 index 6cbbbc167d..0000000000 --- a/database/src/migrations/20240906000000_add_subcount_sign.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Knex } from 'knex'; - -/** - * Update observation_subcount_sign value to accomodate spi-migration data and for other future data. - * - * This migration file inserts values into observation subcount sign table, - * - * @export - * @param {Knex} knex - * @return {*} {Promise} - */ -export async function up(knex: Knex): Promise { - await knex.raw(` - SET SEARCH_PATH=biohub, public; - ----------------------------------------------------------------------------------------- ----------------------------------Insert new oss values-------------------------------------- ----------------------------------------------------------------------------------------- - INSERT INTO biohub.observation_subcount_sign (create_date, name, description) - VALUES (now(), 'Rub or scratch spot', 'This observation was made due to evidence associated with a rubbing or scratch mark created by an animal'); - - `); -} - -export async function down(knex: Knex): Promise { - await knex.raw(``); -} diff --git a/database/src/migrations/20240911000011_method_lookup_updates.ts b/database/src/migrations/20240911000011_method_lookup_updates.ts new file mode 100644 index 0000000000..ffd53a7b86 --- /dev/null +++ b/database/src/migrations/20240911000011_method_lookup_updates.ts @@ -0,0 +1,233 @@ +import { Knex } from 'knex'; + +/** + * Update method_lookup values and associated attributes to accomodate spi-migration data and for other future data. + * + * This migration file inserts or updates values into method lookup table, technique attribute qual and quant tables, + * method lookup quant and qual and qualitative options and attractants + * + * @export + * @param {Knex} knex + * @return {*} {Promise} + */ +export async function up(knex: Knex): Promise { + await knex.raw(` + SET SEARCH_PATH=biohub; + + ---------------------------------------------------------------------------------------- + -- Allow method lookup options to be soft deleted + ---------------------------------------------------------------------------------------- + ALTER TABLE method_lookup ADD COLUMN record_end_date; + ALTER TABLE method_lookup ADD COLUMN record_effective_date DEFAULT now(); + + COMMENT ON COLUMN method_lookup.record_end_date IS 'Record level end date.'; + COMMENT ON COLUMN method_lookup.record_effective_date IS 'Record level effective date.'; + + CREATE OR REPLACE VIEW biohub_dapi_v1.method_lookup AS SELECT * FROM biohub.method_lookup; + + ---------------------------------------------------------------------------------------- + -- Insert new method lookup values necessary for the SPI ETL + ---------------------------------------------------------------------------------------- + INSERT INTO method_lookup (name, description, record_end_date) + VALUES + ('Drone', 'Detecting species using cameras or sensors mounted to a drone.', NULL), + ('Hair snag', 'Detecting species using barbs or similar devices that collect species hair or fur.', NULL), + -- Add an end date to filter undetermined from the list of options that users can pick; undetermined should only be used for the SPI ETL + ('Undetermined', 'Insufficient information to determine the method.', now()), + ('Audio encounter', 'Detecting species by songs, calls, or other noises made by the species.', NULL); + + ---------------------------------------------------------------------------------------- + -- Insert quantitative attributes for the new method lookup values + ---------------------------------------------------------------------------------------- + INSERT INTO technique_attribute_quantitative (name, description) + VALUES + ('Altitude', 'Elevation above sea level.'); + + INSERT INTO method_lookup_attribute_quantitative (technique_attribute_quantitative_id, method_lookup_id, min, max, unit) + VALUES + ( + (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Altitude'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Drone'), + 0, + 10000, + 'meter' + ), + ( + (SELECT technique_attribute_quantitative_id FROM technique_attribute_quantitative WHERE name = 'Height above ground'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag'), + 0, + 1000, + 'centimeter' + ); + + ---------------------------------------------------------------------------------------- + -- Insert qualitative attributes for the new method lookup values + ---------------------------------------------------------------------------------------- + INSERT INTO technique_attribute_qualitative (name, description) + VALUES + ('Camera type', 'The type of camera mounted on the drone, such as RGB, thermal, or multispectral.'), + ('Trap type', 'The specific design or material of the hair snagging device.'); + + INSERT INTO method_lookup_attribute_qualitative (technique_attribute_qualitative_id, method_lookup_id) + VALUES + ( + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Camera type'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Drone') + ), + ( + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Trap type'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Hair snag') + ); + + INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) + VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Camera type' AND ml.name = 'Drone' + ), + 'RGB', + 'Captures images in the visible light spectrum using three color channels (red, green, blue).' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Camera type' AND ml.name = 'Drone' + ), + 'Thermal', + 'Captures infrared radiation emitted by objects.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Camera type' AND ml.name = 'Drone' + ), + 'Multispectral', + 'Captures data across a limited number of spectral bands (typically between 3 and 15 bands) in the electromagnetic spectrum.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Camera type' AND ml.name = 'Drone' + ), + 'Hyperspectral', + 'Captures data across numerous spectral bands, providing continuous coverage of a broad spectral range.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Camera type' AND ml.name = 'Drone' + ), + 'LiDAR', + 'Uses laser pulses to measure distances to the Earth''s surface and other objects.' + ); + + + INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) + VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Trap type' AND ml.name = 'Hair snag' + ), + 'Barbed wire', + 'A metal wire used to collect hair from passing species.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Trap type' AND ml.name = 'Hair snag' + ), + 'Adhesive strip', + 'A sticky strip used to collect hair from passing species.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Trap type' AND ml.name = 'Hair snag' + ), + 'Brush', + 'A brush used to collect hair from passing species.' + ); + + ---------------------------------------------------------------------------------------- + -- Update the radio tower method lookup option + ---------------------------------------------------------------------------------------- + UPDATE method_lookup + SET name = 'Radio receiver or transmitter', + description = 'Detecting species using radio waves.' + WHERE name = 'Radio signal tower'; + + UPDATE technique_attribute_quantitative + SET description = 'The frequency at which radio waves are transmitted or received.' + WHERE name = 'Radio frequency'; + + INSERT INTO technique_attribute_qualitative (name, description) + VALUES ('Station type', 'The type of station used to transmit or receive signals.'); + + INSERT INTO method_lookup_attribute_qualitative (technique_attribute_qualitative_id, method_lookup_id) + VALUES ( + (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Station type'), + (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radio receiver or transmitter') + ); + + INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) + VALUES + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Station type' AND ml.name = 'Radio receiver or transmitter' + ), + 'Receiver', + 'A device used to receive radio signals from passing species.' + ), + ( + ( + SELECT method_lookup_attribute_qualitative_id + FROM method_lookup_attribute_qualitative mlaq + INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id + INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id + WHERE taq.name = 'Station type' AND ml.name = 'Radio receiver or transmitter' + ), + 'Transmitter', + 'A device used to transmit radio signals to detect passing species.' + ); + + ---------------------------------------------------------------------------------------- + -- Insert new subcount sign option + ---------------------------------------------------------------------------------------- + INSERT INTO biohub.observation_subcount_sign (name, description) + VALUES ('Rub or scratch mark', 'A rubbing or scratch mark created by a species'); + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(``); +} From c040ddc4b3edfb46899420db0cbe4457e7b72fdf Mon Sep 17 00:00:00 2001 From: Macgregor Aubertin-Young Date: Wed, 11 Sep 2024 13:56:28 -0700 Subject: [PATCH 10/12] reassign radio tower method lookup to radar --- api/src/repositories/code-repository.ts | 3 +- .../TechniqueGeneralInformationForm.tsx | 13 +-- .../20240911000011_method_lookup_updates.ts | 90 +++++++------------ 3 files changed, 39 insertions(+), 67 deletions(-) diff --git a/api/src/repositories/code-repository.ts b/api/src/repositories/code-repository.ts index 11d1587873..07c079cda4 100644 --- a/api/src/repositories/code-repository.ts +++ b/api/src/repositories/code-repository.ts @@ -62,9 +62,8 @@ export class CodeRepository extends BaseRepository { SELECT method_lookup_id as id, name, - description + description FROM method_lookup - WHERE record_end_date < now() ORDER BY name ASC; `; diff --git a/app/src/features/surveys/sampling-information/techniques/components/general-information/TechniqueGeneralInformationForm.tsx b/app/src/features/surveys/sampling-information/techniques/components/general-information/TechniqueGeneralInformationForm.tsx index 9decbb3db1..db67e69c39 100644 --- a/app/src/features/surveys/sampling-information/techniques/components/general-information/TechniqueGeneralInformationForm.tsx +++ b/app/src/features/surveys/sampling-information/techniques/components/general-information/TechniqueGeneralInformationForm.tsx @@ -30,11 +30,14 @@ export const TechniqueGeneralInformationForm = < }, [codesContext.codesDataLoader]); const methodOptions: ISelectWithSubtextFieldOption[] = - codesContext.codesDataLoader.data?.sample_methods.map((option) => ({ - value: option.id, - label: option.name, - subText: option.description - })) ?? []; + codesContext.codesDataLoader.data?.sample_methods + .map((option) => ({ + value: option.id, + label: option.name, + subText: option.description + })) + // Undetermined is a possible option, but filter from the list to discourage its use + .filter((option) => option.label.toLowerCase() !== 'undetermined') ?? []; if (!codesContext.codesDataLoader.data) { return ; diff --git a/database/src/migrations/20240911000011_method_lookup_updates.ts b/database/src/migrations/20240911000011_method_lookup_updates.ts index ffd53a7b86..ca493cda13 100644 --- a/database/src/migrations/20240911000011_method_lookup_updates.ts +++ b/database/src/migrations/20240911000011_method_lookup_updates.ts @@ -1,10 +1,7 @@ import { Knex } from 'knex'; /** - * Update method_lookup values and associated attributes to accomodate spi-migration data and for other future data. - * - * This migration file inserts or updates values into method lookup table, technique attribute qual and quant tables, - * method lookup quant and qual and qualitative options and attractants + * Update method_lookup values and associated attributes for SPI ETL. * * @export * @param {Knex} knex @@ -17,8 +14,8 @@ export async function up(knex: Knex): Promise { ---------------------------------------------------------------------------------------- -- Allow method lookup options to be soft deleted ---------------------------------------------------------------------------------------- - ALTER TABLE method_lookup ADD COLUMN record_end_date; - ALTER TABLE method_lookup ADD COLUMN record_effective_date DEFAULT now(); + ALTER TABLE method_lookup ADD COLUMN record_end_date DATE; + ALTER TABLE method_lookup ADD COLUMN record_effective_date DATE DEFAULT now(); COMMENT ON COLUMN method_lookup.record_end_date IS 'Record level end date.'; COMMENT ON COLUMN method_lookup.record_effective_date IS 'Record level effective date.'; @@ -26,22 +23,20 @@ export async function up(knex: Knex): Promise { CREATE OR REPLACE VIEW biohub_dapi_v1.method_lookup AS SELECT * FROM biohub.method_lookup; ---------------------------------------------------------------------------------------- - -- Insert new method lookup values necessary for the SPI ETL + -- Insert new method lookup values ---------------------------------------------------------------------------------------- - INSERT INTO method_lookup (name, description, record_end_date) + INSERT INTO method_lookup (name, description) VALUES - ('Drone', 'Detecting species using cameras or sensors mounted to a drone.', NULL), - ('Hair snag', 'Detecting species using barbs or similar devices that collect species hair or fur.', NULL), - -- Add an end date to filter undetermined from the list of options that users can pick; undetermined should only be used for the SPI ETL - ('Undetermined', 'Insufficient information to determine the method.', now()), - ('Audio encounter', 'Detecting species by songs, calls, or other noises made by the species.', NULL); + ('Drone', 'Detecting species using cameras or sensors mounted to a drone.'), + ('Hair snag', 'Detecting species using barbs or similar devices that collect species hair or fur.'), + ('Undetermined', 'Insufficient information to determine the method.'), + ('Audio encounter', 'Detecting species by songs, calls, or other noises made by the species.'); ---------------------------------------------------------------------------------------- -- Insert quantitative attributes for the new method lookup values ---------------------------------------------------------------------------------------- INSERT INTO technique_attribute_quantitative (name, description) - VALUES - ('Altitude', 'Elevation above sea level.'); + VALUES ('Altitude', 'Elevation above sea level.'); INSERT INTO method_lookup_attribute_quantitative (technique_attribute_quantitative_id, method_lookup_id, min, max, unit) VALUES @@ -135,11 +130,7 @@ export async function up(knex: Knex): Promise { ), 'LiDAR', 'Uses laser pulses to measure distances to the Earth''s surface and other objects.' - ); - - - INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) - VALUES + ), ( ( SELECT method_lookup_attribute_qualitative_id @@ -149,7 +140,7 @@ export async function up(knex: Knex): Promise { WHERE taq.name = 'Trap type' AND ml.name = 'Hair snag' ), 'Barbed wire', - 'A metal wire used to collect hair from passing species.' + 'A barbed wire used to collect hair from passing species.' ), ( ( @@ -175,50 +166,29 @@ export async function up(knex: Knex): Promise { ); ---------------------------------------------------------------------------------------- - -- Update the radio tower method lookup option + -- Drop the radio signal tower option and reassign existing data to the radar option ---------------------------------------------------------------------------------------- - UPDATE method_lookup - SET name = 'Radio receiver or transmitter', - description = 'Detecting species using radio waves.' - WHERE name = 'Radio signal tower'; - UPDATE technique_attribute_quantitative - SET description = 'The frequency at which radio waves are transmitted or received.' - WHERE name = 'Radio frequency'; + -- Reassign existing attributes for radio signal tower to the radar option + UPDATE method_technique + SET method_lookup_id = (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radar') + WHERE method_lookup_id = (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radio signal tower'); - INSERT INTO technique_attribute_qualitative (name, description) - VALUES ('Station type', 'The type of station used to transmit or receive signals.'); + UPDATE method_lookup_attribute_qualitative + SET method_lookup_id = (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radar') + WHERE method_lookup_id = (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radio signal tower'); - INSERT INTO method_lookup_attribute_qualitative (technique_attribute_qualitative_id, method_lookup_id) - VALUES ( - (SELECT technique_attribute_qualitative_id FROM technique_attribute_qualitative WHERE name = 'Station type'), - (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radio receiver or transmitter') - ); + UPDATE method_lookup_attribute_quantitative + SET method_lookup_id = (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radar') + WHERE method_lookup_id = (SELECT method_lookup_id FROM method_lookup WHERE name = 'Radio signal tower'); + + DELETE FROM method_lookup + WHERE name = 'Radio signal tower'; - INSERT INTO method_lookup_attribute_qualitative_option (method_lookup_attribute_qualitative_id, name, description) - VALUES - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Station type' AND ml.name = 'Radio receiver or transmitter' - ), - 'Receiver', - 'A device used to receive radio signals from passing species.' - ), - ( - ( - SELECT method_lookup_attribute_qualitative_id - FROM method_lookup_attribute_qualitative mlaq - INNER JOIN technique_attribute_qualitative taq ON taq.technique_attribute_qualitative_id = mlaq.technique_attribute_qualitative_id - INNER JOIN method_lookup ml ON ml.method_lookup_id = mlaq.method_lookup_id - WHERE taq.name = 'Station type' AND ml.name = 'Radio receiver or transmitter' - ), - 'Transmitter', - 'A device used to transmit radio signals to detect passing species.' - ); + UPDATE technique_attribute_quantitative + SET name = 'Frequency', + description = 'The frequency at which a signal is transmitted or received.' + WHERE name = 'Radio frequency'; ---------------------------------------------------------------------------------------- -- Insert new subcount sign option From 01d1bf05e66fa007d11364016f75735e0c9127ba Mon Sep 17 00:00:00 2001 From: Nick Phura Date: Tue, 17 Sep 2024 15:38:22 -0700 Subject: [PATCH 11/12] Update todo: add jira link --- .../general-information/TechniqueGeneralInformationForm.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/features/surveys/sampling-information/techniques/components/general-information/TechniqueGeneralInformationForm.tsx b/app/src/features/surveys/sampling-information/techniques/components/general-information/TechniqueGeneralInformationForm.tsx index db67e69c39..e4b74c7d62 100644 --- a/app/src/features/surveys/sampling-information/techniques/components/general-information/TechniqueGeneralInformationForm.tsx +++ b/app/src/features/surveys/sampling-information/techniques/components/general-information/TechniqueGeneralInformationForm.tsx @@ -36,6 +36,7 @@ export const TechniqueGeneralInformationForm = < label: option.name, subText: option.description })) + // TODO https://apps.nrs.gov.bc.ca/int/jira/browse/SIMSBIOHUB-615 - Replace filter with more generic solution // Undetermined is a possible option, but filter from the list to discourage its use .filter((option) => option.label.toLowerCase() !== 'undetermined') ?? []; From aad343aa881b3236eed565f976044bc4f393e1c7 Mon Sep 17 00:00:00 2001 From: Nick Phura Date: Tue, 17 Sep 2024 16:22:47 -0700 Subject: [PATCH 12/12] ignore-skip