|
||
To create an AnalysisRun through the API, we need to create several sub-structures and the top-level entity using ~api/entity.
Here's the pseudo-code (JavaScript-ish to avoid lots of verbosity):
// The SisKey of the Term:
var termSisKey;
// The SisKey of the prior Term:
var priorTermSisKey;
// The Like Terms and their prior Terms:
var likeTerms = [
{ termSisKey: "...", priorTermSisKey: "..." },
{ termSisKey: "...", priorTermSisKey: "..." }
];
var weights = [34, 33, 33];
// give the above (which you would mostly likely have to know), build
// the Analysis Run:
// Gets the Astra Id of the entity given its type (e.g., "Term") and its SisKey.
function getBySisKey (type, sisKey)
{
var url = "~api/query/"+type+"?fields=Id&filter="+Url.encode("SisKey=='"+sisKey+"'");
var resp = callApi("GET", url);
// resp = { totalRecords: 1, data: [ ["e680c918-bc58-46a9-9f55-3ff049f20706"] ] }
return resp.data[0][0];
}
//---
var xact = {
Inserts: {
Analysis: {},
AnalysisLikeTerm: {},
AnalysisStudentStat: {},
AnalysisWeight: {}
}
};
var analysisRun = {
Id: guidGen(),
Term: getBySisKey("term", termSisKey),
PriorTerm: getBySisKey("term", priorTermSisKey),
PriorTermInProgress: true,
Name: "something",
CheckPriorTermHistory: true,
PartialRegistration: true,
Status: 80
};
xact.Inserts.Analysis[analysisRun.Id] = analysisRun;
for (var i = 0; i < likeTerms.length; ++i) {
var likeTerm = {
Id: guidGen()
AnalysisId: analysisRun.Id,
TermId: getBySisKey("term", likeTerms[i].termSisKey),
PriorTermId: getBySisKey("term", likeTerms[i].priorTermSisKey),
PriorTermInProgress: true,
Weight: 25
};
xact.Inserts.AnalysisLikeTerm[likeTerm.Id] = likeTerm;
}
for (var i = 0; i < weights.length; ++i) {
var wt = {
Id: guidGen()
AnalysisId: analysisRun.Id,
AnalysisType: i,
Weight: weights[i]
};
xact.Inserts.AnalysisWeight[wt.Id] = wt;
}
var studentStat = {
Id: guidGen()
AnalysisId: analysisRun.Id
};
xact.Inserts.AnalysisStudentStat[studentStat.Id] = studentStat;
callApi("POST", "~api/entity", encodeJSON(xact));
Obviously, there are several moving parts here, but this is essentially how we test our imports internally in our automated system. The above is translated pared down from our internal C# code.
Assuming you want to look up our ID based on the SisKey (the Campus Vue Id)... To run the section import, we need to run a Job with the “AnalysisId” job parameter set accordingly. If the job is already defined, and we know its ID, all we need to do is modify its AteJobParameter. Something like this should do:
function getJobParamId (jobId, paramName)
{
var url = "~api/query/ateJobParameter?fields=Id&filter="+
Url.encode("AteJobId=='"+jobId+"' && Name=='"+paramName+"'");
var resp = callApi("GET", url);
// resp = { totalRecords: 1, data: [ ["e680c918-bc58-46a9-9f55-3ff049f20706"] ] }
return resp.data[0][0];
}
var xact = {
Updates: {
AteJobParameter: {}
}
};
var id = getJobParamId(jobId, "AnalysisId");
xact.Updates.AteJobParameter[id] = { Value: analysisRun.Id };
callApi("POST", "~api/entity", encodeJSON(xact));
Now you can run this job via the job invocation API mentioned previously.
In the next milestone API build there is a “recase=1” option in the API that will lower-case the properties we return. This is experimental, but should be helpful.