Closed usernamenumber closed 7 years ago
Instead of using setIfUnset
, I'd recommend using just a default object:
populateXAPI(statement_data) {
const default_statement_data = {
timestamp: new Date().toISOString(),
version: '1.0.0',
...
};
statement_data = Object.assign({}, default_statement_data, statement_data);
}
Other than that looks good to me!
Argh, I knew there must have been a nicer way to do that in JS. Ok, will update and then merge.
...actually, I don't think that will work. The point of the default statement is to store a bunch of values that most statements will not need to change. The "context" subdict is a good example of one that mixes settings that statements probably won't need to update with ones they probably will.
Unfortunately, the Object.assign
technique seems to only merge at the shallowest level, so if you override anything in a subdict you have to override everything in it, which defeats the point.
var default_statement_data = { "context" : { "var1":"val1", "var2":"val2", "var3":"val3" } }
var statement_data = { "context": { "var2":"overidden" } }
console.log(Object.assign({}, default_statement_data, statement_data))
// { context: { var2: "overridden" } }
We could recurse through and only update leaf nodes, but at that point I think the setIfUnset
method looks cleaner.
Thoughts?
@mcantor @Jakeii
I completely redid how the xapi statements are structured, and included a bunch more useful data, including optional location data per Certell's request. Still hoping to figure out a better way to balance making it clear whether students are using the app at school or not, but for now I've addressed it by making the gps accuracy configurable and defaulting it to something middle-of-the-road. Maybe the book metadata could include coords of the institution's campus(es), and the xapi could just include how far the user is from the closest one?
I should push this out sooner rather than later, but since it's a big change if either of you have a sec to look it over before I merge, that would be great. So you can see how the xapi stuff gets built if nothing else.
Here's an example of what a statement looks like as of this PR: