Closed sorsaffari closed 2 years ago
As for our discussion, an update on this:
computeAttributes()
(or another name) should stay as a separate method, but it should accept Answer
s or Concept
s as parameters, so that building canvas nodes and calling methods on Concepts remain 2 different things working on 2 different type of objects.
Pseudo code for computeAttributesOnInstances(answers)
:
/**
* Given an array of answers return an array of Objects { id, attributes}
* Used to asynchronously fetch all the attributes attached to a set of concepts
*/
function computeAttributesOnInstances(answers){
const concepts = extractConceptsFromAnserws(answers); // it can use concepts directly as a parameter, this is just an hypothesis
const instances = concepts.filter(c => c.isThing());
return Promise.all(instances.map(loadAttributes(instance)));
}
"private" async function loadAttributes(instance){
const attributes = await (await instance.attributes()).collect();
const attributesWithValues = await attributesWithValues(attributes);
return Object.assign({id: instance.id , attributes: attributesWithValues });
}
// This function can be rewritten in a more elegant fashion, but which will be less performant,
// up to us to decide whether prioritise elegance or performance
"private" function attributesWithValues(attributes){
return Promise.all(attributes.map(async (concept) => {
const attribute = {};
await Promise.all([
concept.type().then(type => type.label()).then((label) => { attribute.type = label; }),
concept.value().then((value) => { attribute.value = value; }),
]);
return attribute;
}))
}
We can then have another method computeAttributesOnTypes()
or they can stay together with another internal if, again this is just a draft
Once this is done let's remember to remove txService
from the nodes when we build them!
This issue is no longer relevant as Studio uses new architecture.
Currently, the pot-processing that takes place after running queries, is done outside the scope of the
CanvasDataBuider
. Because of this, thenode
objects produced byCanvasDataBuider
must include properties of the original Graql Concepts.Ideally, node objects should only contain properties expected by Visjs
and therefore the post-processing job should be moved to theCanvasDataBuider