Skip to content

Commit

Permalink
nesp marine hub scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
per305 authored and per305 committed Nov 30, 2021
1 parent f542da0 commit e90fb7c
Show file tree
Hide file tree
Showing 6 changed files with 1,707 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hub_name associatedProgram associatedSubProgram projectSiteId projectType organisationId organisationName organisationUrl organisationLogo projectName aim description plannedStartDate plannedEndDate ecoScienceType isExternal status manager countries uNRegions banner_image projectUrl associatedOrgs contactMail keywords termsOfUseAgreement embeddedVideo embeddedVideoTitle
nesp-marine NESP 1 - Marine Biodiversity Hub Theme A - Threatened and migratory species Ecological or biological survey / assessment (not citizen science) 4a3929aa-5d64-4c96-9e03-4ade85d5f9f1 Charles Darwin University Project A1 - Northern Australian hotspots for the recovery of threatened euryhaline species Australia's northern rivers and estuaries are important to sustaining sawfish and river shark species listed under the EPBC Act. This project will provide the Department of the Environment with information to improve management and facilitate the recovery of these species. "Australia's northern rivers and estuaries are important to sustaining sawfish and river shark species listed under Australia's<em> Environment Protection and Biodiversity Conservation Act 1999</em> (EPBC Act). This project will provide the Department of the Environment with information to improve management and facilitate the recovery of these species.<p>Acoustic telemetry, molecular research, life history studies and Indigenous engagement and education will be central to determining the status of threatened river sharks, and establishing monitoring, management and protection. Following are the key research activities.</p><h2>Monitoring and understanding</h2><p>More than 200 tagged animals will be monitored (via an acoustic array established in earlier research) for mortality estimates, movement patterns and habitat use, acoustic receiver arrays will be designed to measure long term movement and mortality in NT, QLD and WA rivers, and statistical methods developed for estimating annual juvenile mortality.</p><p>Thirty neonate <em>Glyphis glyphis</em> (Speartooth Sharks) will be tagged for mortality estimates and large sub-adult <em>G. glyphis</em> will be tagged to investigate adult distribution, reproductive philopatry and mortality (Adelaide River) and the age structure of <em>G. glyphis</em> will be determined for demographic models.</p><p><em>G. garricki</em> (Northern River Shark) tissue samples will be collected in unsurveyed NT habitat (including the Daly, Finniss, Fitzmaurice, Victoria, Keep rivers) and in WA (Cambridge Gulf, King Sound) in partnership with Indigenous Ranger Groups, Murdoch University and NT Fisheries. <em>G. garricki</em> population structure will be examined and close-kin mark recapture used to establish a lower bound population size estimate.</p><p>Marine Biodiversity Hub research on habitat use, long-term movements and biologically important areas will be synthesised and recovery-directed research prioritised, and&nbsp;new information will be&nbsp;provided&nbsp;for updating the&nbsp;EPBC status of river sharks.</p><h2>Indigenous partnerships for management</h2><p>Key components of this project are being undertaken in partnership with Indigenous organisations, communities and ranger groups. Partnerships will assess Indigenous cultural use and knowledge of sawfish, and develop a sawfish education package for communities.</p><p>The Northern Australian Indigenous Land and Sea Management Alliance is a project partner and Indigenous land councils will be consulted to evaluate engagement and partnership opportunities.</p><p>Malak Malak Rangers (NT) and Dambi-Mangari Rangers (WA) among other ranger groups are assisting with field research, and protocols and methodologies are being developed for an annual Malak Malak <em>Pristis pristis</em> (Largetooth Sawfish) survey.</p><p><strong>Related information</strong></p><ul><li><a href=https://www.nespmarine.edu.au/news/sampling-speartooth-sharks-remote-lower-ord-river"">Sampling Speartooth Sharks on the remote Lower Ord River</a></li><li><a href=""https://www.nespmarine.edu.au/news/fishers-offer-narrow-sawfish-helping-hand"">Fishers offer Narrow Sawfish a helping hand</a></li><li><a href=""https://www.nespmarine.edu.au/news/largetooth-sawfish-found-rock-art-500-kilometres-sea"">Largetooth Sawfish found in rock art 500 kilometres from the sea</a></li><li><a href=""https://www.nespmarine.edu.au/news/making-art-videos-signs-and-steps-save-sawfish-australias-northern-rivers"">Making art, videos, signs and steps to save sawfish in Australia's northern rivers</a></li><li>S<a href=""http://www.nespmarine.edu.au/sawfish"">awfish and river shark research</a> undertaken during the National Environmental Research Program&nbsp; (NERP) 2011-2014&nbsp;</li></ul>" 7/01/2016 8/01/2016 TRUE Completed Peter Kyne Australia Oceania https://www.nespmarine.edu.au/sites/default/files/sawfish%20rock%20art%20Peter%20Kyne%20carousel_0.png https://www.nespmarine.edu.au/project/project-a1-northern-australian-hotspots-recovery-threatened-euryhaline-species peter.kyne@cdu.edu.au "Euryhaline sharks,Glyphis garricki,Glyphis glyphis,Indigenous engagement,Largetooth Sawfish,Malak Malak Rangers,northern river sharks,Pristis pristis,Speartooth Shark" TRUE
129 changes: 129 additions & 0 deletions scripts/RestClient/nesp/marine/document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
var document =
{
"labels" : [ ],
"dateCreated" : "",
"lastUpdated" : "",
"isPrimaryProjectImage" : true,
"documentId" : "",
"filepath" : "2021-11",
"thirdPartyConsentDeclarationMade" : false,
"projectActivityId" : "",
"role" : "mainImage",
"name" : "",
"type" : "image",
"status" : "active",
"filename" : "",
"isSciStarter" : false,
"projectId" : "",
"readOnly" : false,
"filesize" : 104117,
"contentType" : "image/jpeg"
}

/*
var document =
{
"documentId" : "",
"filename" : "",
"filepath" : "2021-02",
"isPrimaryProjectImage" : true,
"isSciStarter" : false,
"labels" : [ ],
"name" : "",
"projectId" : "",
"role" : "mainImage",
"status" : "active",
"thirdPartyConsentDeclarationMade" : false,
"type" : "image",
"lng" : "",
"filesize" : 104117,
"public" : true,
"contentType" : "image/jpeg",
"lat" : "",
"projectActivityId" : "",
"roles" : [
{
"name" : "Information",
"id" : "information"
},
{
"name" : "Embedded Video",
"id" : "embeddedVideo"
},
{
"name" : "Exceedance Report",
"id" : "exceedanceReport"
},
{
"name" : "Photo",
"id" : "photo"
},
{
"name" : "Project Plan / Work plan",
"id" : "projectPlan"
},
{
"name" : "Project Variation",
"id" : "projectVariation"
},
{
"name" : "Project Highlight Report",
"id" : "projectHighlightReport"
},
{
"name" : "Other Project document",
"id" : "other"
}
],
"fileReady" : true,
"thirdPartyConsentDeclarationRequired" : true,
"embeddedVideoVisible" : false,
"settings" : {
"thirdPartyDeclarationTextSelector" : "#thirdPartyDeclarationText",
"roles" : [
{
"name" : "Information",
"id" : "information"
},
{
"name" : "Embedded Video",
"id" : "embeddedVideo"
},
{
"name" : "Exceedance Report",
"id" : "exceedanceReport"
},
{
"name" : "Photo",
"id" : "photo"
},
{
"name" : "Project Plan / Work plan",
"id" : "projectPlan"
},
{
"name" : "Project Variation",
"id" : "projectVariation"
},
{
"name" : "Project Highlight Report",
"id" : "projectHighlightReport"
},
{
"name" : "Other Project document",
"id" : "other"
}
],
"showSettings" : true,
"imageLocation" : "/assets/"
},
"hasPreview" : false,
"fileButtonText" : "Change file",
"readOnly" : false,
"saveHelp" : "You must accept the Privacy Declaration before an image can be made viewable by everyone",
"fileLabel" : "",
"progress" : 0,
"complete" : false,
"saveEnabled" : false
};
*/
238 changes: 238 additions & 0 deletions scripts/RestClient/nesp/marine/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
print("Imported started");
var path = '';
load(path + "document.js")
load(path+"testExample.js");
load(path+'uuid.js');
load(path+'siteTemplate.js');

print("Loaded all dependent files...");

/*
//Prod
var projectSiteId = "75e5599b-44f2-4ffa-975a-e7900839ae35" //https://biocollect.ala.org.au/nesp/site/index/75e5599b-44f2-4ffa-975a-e7900839ae35
// https://biocollect.ala.org.au/nesp/project/index/e7e0fe1a-315d-4485-84ef-73276a812dac
*/

// Test
// Test Project https://biocollect-test.ala.org.au/nesp/project/index/a833ad82-bc3b-41f6-8d98-106df76a089c
// Test Site https://biocollect-test.ala.org.au/biocollect-all/site/index/6d9270aa-6cdd-4cce-a319-5226e0affefc
var hub_name = 0;
var associatedProgram = hub_name + 1;
var associatedSubProgram = associatedProgram + 1;
var projectSiteId = associatedSubProgram + 1;
var projectType = projectSiteId + 1;
var organisationId = projectType + 1;
var organisationName = organisationId + 1;
var organisationUrl = organisationName + 1;
var organisationLogo = organisationUrl + 1;
var projectName = organisationLogo + 1;
var aim = projectName + 1;
var description = aim + 1;
var plannedStartDate = description + 1;
var plannedEndDate = plannedStartDate + 1;
var ecoScienceType = plannedEndDate + 1
var isExternal = ecoScienceType + 1;
var status = isExternal + 1;
var manager = status + 1;
var countries = manager + 1;
var uNRegions = countries + 1;
var banner_image = uNRegions + 1;
var projectUrl = banner_image + 1;
var associatedOrgs = projectUrl + 1;
var contactMail = associatedOrgs + 1;
var keywords = contactMail + 1;
var termsOfUseAgreement = keywords + 1;

var csvData = cat(path+'Marine_Biodiversity_Hub_Projects_tab.txt');
print("Loaded csv file");
var csvRows = csvData.split('\r');
print("Total rows "+ csvRows.length);

// key value pairs of assoiated orgs
var organisations = [
{name:"CSIRO", organisationId:"8c3a7806-6d5e-4b60-97d7-b76ba495750e"},
{name:"Charles Darwin University", organisationId:"9fe1c64f-ad8c-487d-b7f7-b975563d5e4b"},
{name:"Curtin University", organisationId:"sdsdc64f-ad8c-487d-b7f7-b975563d5e4b"},
{name:"Murdoch University", organisationId:"sddwc64f-ad8c-487d-b7f7-b975563d5e4b"}
];

for(var i = 1; i < csvRows.length; i++) {
print("PRINT "+csvRows.length)
var projectId = UUID.generate();
var siteId = UUID.generate();
var row = csvRows[i];
var fields = row.split('\t');

project.projectId = projectId;
project.urlWeb = fields[projectUrl];
project.projectSiteId = siteId
project.projectType = "ecoScience"
project.organisationId = "8a53da29-bbbe-4a76-81c8-13f0bafd2f85" // hub's organisation id

//When there are commas, tsv adds double quotes in the beginning and end of text, following string
//manipulations are done to avoid that
if(fields[contactMail].indexOf(',') != -1){
var tempManagerEmail = fields[contactMail].replace(/""/g, '"');
project.manager = tempManagerEmail.substring(1, tempManagerEmail.length-1);
}
else {
project.manager = fields[contactMail]
}

if(fields[manager].indexOf(',') != -1){
var tempManager = fields[manager].replace(/""/g, '"');
project.managerEmail = tempManager.substring(1, tempManager.length-1);

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

This will have comma separated list of emails. We should only include one email.

}
else {
project.managerEmail = fields[manager]
}

if(fields[description].indexOf(',') != -1){
var tempDescription = fields[description].replace(/""/g, '"');
project.description = tempDescription.substring(1, tempDescription.length-1);
}
else {
project.description = fields[description]
}

if(fields[aim].indexOf(',') != -1){
var tempAim = fields[aim].replace(/""/g, '"');
project.aim = tempAim.substring(1, tempAim.length-1);
}
else {
project.aim = fields[aim]
}

if(fields[projectName].indexOf(',') != -1){
var tempProjectName = fields[projectName];

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

quotes are not removed here

project.name = tempProjectName.substring(1, tempProjectName.length-1);
}
else {
project.name = fields[projectName]
}

project.associatedProgram = fields[associatedProgram]

if(fields[associatedSubProgram].indexOf(',') != -1){
var tempAssociatedSubProgram = fields[associatedSubProgram];

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

same as above

project.associatedSubProgram = tempAssociatedSubProgram.substring(1, tempAssociatedSubProgram.length-1);
}
else {
project.associatedSubProgram = fields[associatedSubProgram]
}

//Handle associated orgs
project.associatedOrgs = []

var tempAssociatedOrgsArr = []
var tempAssociatedOrgs = "";
var tempStr = "";

//get comma separated values from associatedOrgs field in excelsheet
if(fields[associatedOrgs]) {
tempAssociatedOrgs = fields[associatedOrgs].replace(/""/g, '"');
tempStr = tempAssociatedOrgs.substring(1, tempAssociatedOrgs.length - 1);
}

if (tempStr) {
tempAssociatedOrgsArr = tempStr.split(',');
}

for (var k = 0; k < tempAssociatedOrgsArr.length; k++) {
var org = organisations.find(obj => obj.name === tempAssociatedOrgsArr[k]);
project.associatedOrgs.push({organisationId: org.organisationId});

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

My thinking is more details of organisation will be required to be added like logo, url, name etc. Can you point me an example project loaded with associated orgs?

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

what happens if no match is found? print to console if not match is found.

}

//assign organisationId from excelsheet for the first organisationName in excelsheet
project.associatedOrgs.push({organisationId: fields[organisationId]});

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

Does business requirement need org to included here?


var tempKeywords = fields[keywords].replace(/""/g, '"');

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

This code could be replaced by below line since single quote is removed anyway. fields[keywords].replace(/""/g, '');

project.keywords = tempKeywords.substring(1, tempKeywords.length-1);

var startDate = fields[plannedStartDate] ? fields[plannedStartDate].split('/') : '';
var endDate = fields[plannedEndDate] ? fields[plannedEndDate].split('/') : '';

if(!startDate || startDate == undefined || startDate == "" || startDate.length == 0 || startDate.length < 3) {
var dd = "01";
var mm = "01";
var yy = "2000";
startDate = ""+yy+"-"+mm+"-"+dd+"T00:00:00Z"+"";
project.plannedStartDate = ISODate(startDate);
} else {
startDate = ""+startDate[2]+"-"+("0" + startDate[1]).slice(-2)+"-"+("0" + startDate[0]).slice(-2)+"T00:00:00Z"+"";
project.plannedStartDate = ISODate(startDate);
}

if(!endDate || endDate == undefined || endDate == "" || endDate.length == 0 || endDate.length < 3) {
//print("Invalid project end date");
} else {
endDate = endDate[2] + "-" + ("0" + endDate[1]).slice(-2)+"-"+("0" + endDate[0]).slice(-2)+"T00:00:00Z"+"";
project.plannedEndDate = ISODate(endDate);
}

project.ecoScienceType = [];
if(fields[ecoScienceType]) {
project.ecoScienceType << fields[ecoScienceType]

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

This field might be comma separated. remove quote and split by comma.

}

var today = new ISODate();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
var dateUTC = yyyy+"-"+("0" + mm).slice(-2)+"-"+("0" + dd).slice(-2)+"T00:00:00Z";

project.dateCreated = ISODate(dateUTC);
project.lastUpdated = ISODate(dateUTC);

if(siteMap) {
siteMap.projects = [];
siteMap.projects.push(projectId);
siteMap.siteId = siteId;
siteMap.lastUpdated = ISODate(dateUTC);
siteMap.dateCreated = ISODate(dateUTC);
}

if(fields[banner_image]) {
var imageUrl = fields[banner_image]
var urlSplitBySlash = imageUrl.split('/')
var fileName = urlSplitBySlash[urlSplitBySlash.length-1]

var contentType = "image/jpg"

if(fileName.endsWith(".png")) {
contentType = "image/png"
}

document.filename = fileName
document.name = fileName
document.documentId = UUID.generate()
document.projectId = project.projectId
document.contentType = contentType
document.fileLabel = fileName
document.dateCreated = ISODate(dateUTC);
document.lastUpdated = ISODate(dateUTC);
}

var userPermission = {};
userPermission.accessLevel = 'admin';
userPermission.entityId = project.projectId;
userPermission.userId = '8443';

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

This should be your user id.

userPermission.entityType = 'au.org.ala.ecodata.Project';

var documentResult = db.document.insert(document);
var siteResult = db.site.insert(siteMap);

This comment has been minimized.

Copy link
@temi

temi Dec 1, 2021

Contributor

Why create new site? Does not these site already exist?

var projectResult = db.project.insert(project);
var permissionResult = db.userPermission.insert(userPermission);

//print(JSON.stringify(project,null,"\t"));
print("Project is "+project.projectId + "," + project.name);
print("siteResult"+siteResult)
print("projectResult"+projectResult)
print("permissionResult"+permissionResult)
print("documentResult"+documentResult)
}


print(">>>>>>>>>>>>>>>>>>>>")
print("Created " + (i-1) + " projects");
print("<<<<<<<<<<<<<<<<<<<")
Loading

0 comments on commit e90fb7c

Please sign in to comment.