Skip to content

Commit

Permalink
Add chemical analysis workflow, re #1134
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Anderson committed Jun 27, 2023
1 parent 9021773 commit c77ce96
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ define([
tilesManaged: 'one',
parameters: {
graphid: '707cbd78-ca7a-11e9-990b-a4d18cec433a', /* Digital Resources */
physicalThingResourceId: "['select-project']['select-phys-thing']['physicalThing']"
physicalThingResourceId: "['select-project']['select-observation']['phsyicalThingResourceId']",
observationResourceId: "['select-project']['select-observation']['observation']"
},
},
],
Expand All @@ -85,10 +86,11 @@ define([
uniqueInstanceName: 'add-chemical-analysis-images-final',
tilesManaged: 'none',
parameters: {
sampleObjectResourceId: "['select-project']['select-phys-thing']['physicalThing']",
relatedProjectData: "['select-project']['select-phys-thing']",
observationResourceId: "['select-project']['select-observation']['observation']",
relatedProjectData: "['select-project']['select-observation']",
imageStepData: "['image-step']['image-service-instance'][0]['data']",
digitalReferenceResourceId: "['image-step']['image-service-instance'][0]['resourceinstance_id']"
digitalResourcesIds: "['image-step']['image-service-instance']['digitalResourcesIds']",
manifestResourceId: "['image-step']['image-service-instance']['manifestResourceId']",
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,115 +10,39 @@ define([

function viewModel(params) {
var self = this;

params.form.resourceId(params.sampleObjectResourceId);
const digitalResourceServiceIdentifierContentNodeId = '56f8e9bd-ca7c-11e9-b578-a4d18cec433a';
const manifestUrl = params.imageStepData[digitalResourceServiceIdentifierContentNodeId][arches.activeLanguage]['value'];
const digitalReferenceResourceId = params.digitalReferenceResourceId;

this.regionInstances = params.regionsStepData?.data.map(function(data){
return {
regionName: data.data["3e541cc6-859b-11ea-97eb-acde48001122"],
regionResource: data.data["b240c366-8594-11ea-97eb-acde48001122"][0]["resourceId"],
};
});
const currentAnalysisAreas = params.regionsStepData?.currentAnalysisAreas;
params.form.resourceId(params.relatedProjectData.observation);
self.relatedDigitalResources = ko.observableArray()
self.workflowDigitalResources = ko.observableArray()
self.workflowManifestResource = ko.observable()
self.digitalResourcesIds = params.digitalResourcesIds.digitalResourceInstancesIds;
self.manifestResourceId = params.manifestResourceId.ManifestResourceId;

SummaryStep.apply(this, [params]);

this.objectAnnotations = ko.observableArray();
this.resourceData.subscribe(function(val){
this.displayName = val['displayname'] || 'unnamed';
const digitalReference = val.resource['Digital Reference'].find(function(val){
return val['Digital Source']['resourceId'] === digitalReferenceResourceId;
});
this.reportVals = {
projectName: {'name': 'Project', 'value': params.relatedProjectData.projectName, 'resourceid': params.relatedProjectData.project},
parentObject: {'name': 'Object', 'value': this.getResourceValue(val.resource, ['part of', '@display_value'])},
digitalReference: {'name': 'Image Service', 'value': digitalReference['Digital Source']["@display_value"]},
observationName: {'name': 'Observation', 'value': params.relatedProjectData.observationName, 'resourceid': params.relatedProjectData.observation},
};
var annotationCollection = {};
self.regionResourceIds = self.regionInstances?.map(x => x.regionResource);
val.resource['Part Identifier Assignment'].forEach(function(annotation){
const annotationResourceId = self.getResourceValue(annotation,['Part Identifier Assignment_Physical Part of Object','resourceId']);
const annotationName = self.getResourceValue(annotation,['Part Identifier Assignment_Physical Part of Object','@display_value']);
const annotationLabel = self.getResourceValue(annotation,['Part Identifier Assignment_Label','@display_value']);
const annotator = self.getResourceValue(annotation,['Part Identifier Assignment_Annotator','@display_value']);
const annotationStr = self.getResourceValue(annotation,['Part Identifier Assignment_Polygon Identifier','@display_value']);
const tileId = self.getResourceValue(annotation,['Part Identifier Assignment_Polygon Identifier','@tile_id']);
if (annotationStr) {
const annotationJson = JSON.parse(annotationStr.replaceAll("'",'"'));
if (annotationJson.features.length > 0){
const currentManifestUrl = annotation['Part Identifier Assignment_Polygon Identifier']['geojson']['features'][0]['properties']['manifest'];
if (currentManifestUrl === manifestUrl){
const canvas = annotationJson.features[0].properties.canvas;
annotationJson.features.forEach(function(feature){
feature.properties.tileId = tileId;
});
if (canvas in annotationCollection) {
annotationCollection[canvas].push({
resourceId: annotationResourceId,
tileId: tileId,
annotationName: annotationName,
annotationLabel: annotationLabel,
annotator: annotator,
annotationJson: annotationJson,
});
} else {
annotationCollection[canvas] = [{
resourceId: annotationResourceId,
tileId: tileId,
annotationName: annotationName,
annotationLabel: annotationLabel,
annotator: annotator,
annotationJson: annotationJson,
}];
}
}
}
}
});

for (const canvas in annotationCollection) {
let name;
let annotationCombined;
let info = [];
annotationCollection[canvas].forEach(function(annotation){
name = annotation.annotationName;
if (annotationCombined) {
annotationCombined.features = annotationCombined.features.concat(annotation.annotationJson.features);
} else {
annotationCombined = annotation.annotationJson;
}
if (currentAnalysisAreas?.includes(annotation.tileId)) {
info.push({
tileId: annotation.tileId,
name: annotation.annotationName,
annotator: annotation.annotator,
});
} else {
annotation.annotationJson.features.map(feature => {
feature.properties.color = '#999999';
feature.properties.fillColor = '#999999';
feature.properties.tileId = annotation.tileId;
feature.properties.name = annotation.annotationName;
feature.properties.active = false;
});
}
});

const leafletConfig = self.prepareAnnotation(annotationCombined);
if (info.length > 0) {
self.objectAnnotations.push({
name: name,
info: info,
leafletConfig: leafletConfig,
featureCollection: annotationCombined,
});
}
}
this.loading(false);
}, this);

this.getWorkflowResourceData = async function(resourceid) {
const response = await window.fetch(this.urls.api_resources(resourceid) + '?format=json&compact=false&v=beta')
return await response.json()
};

(async (val) => {
self.workflowDigitalResources(await Promise.all(self.digitalResourcesIds.map( async function(resourceid){
return await self.getWorkflowResourceData(resourceid);
})));
})();

(async (val) => {
self.workflowManifestResource(await self.getWorkflowResourceData(self.manifestResourceId))
})()

}

ko.components.register('add-chemical-analysis-images-final-step', {
Expand Down
Loading

0 comments on commit c77ce96

Please sign in to comment.