Commit 99873e61 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Add API Wrapper for lab usage statistics

parent 40604916
Pipeline #2987 passed with stages
in 1 minute and 7 seconds
......@@ -33,6 +33,7 @@ class EduLab {
this.router.post('/api/create-machine', (req, res) => this.APIcreateMachine(req, res));
this.router.post('/api/wmstatus', (req, res) => this.APIwmstatus(req, res));
this.router.delete('/api/lab/:labid' , (req, res) => this.APIlabDelete(req, res));
this.router.get('/api/lab/:labid/usage' , (req, res) => this.APIlabUsage(req, res));
}
getUserContext(req) {
......@@ -148,6 +149,41 @@ class EduLab {
}
filterData(data) {
var results = {};
data.forEach((cur, index) => {
console.log(cur);
if (!cur.instance_data.tags || !cur.instance_data.tags.feide_userid) return
let userid = cur.instance_data.tags.feide_userid
if (!results[userid]) {
results[userid] = []
}
results[userid].push(cur)
})
return results
}
APIlabUsage(req, res) {
var labid = req.params.labid;
console.log("About to fetch usage data for " + labid);
this.getAPI(req, '/classrooms/' + labid + '/resourceusage?daysback=1', {
method: "GET",
json: true
})
.then((response) => {
console.log("WE got response from lab resourceusage ", labid);
console.log(response);
console.log("---------");
res.json(this.filterData(response.UsageAggregation));
})
.catch((err) => {
console.error("Error debug page", err);
res.render('error', err);
});
}
APIlabDelete(req, res) {
var labid = req.params.labid;
console.log("ABOUT TO DELETE LAB " + labid);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment