Skip to content
Snippets Groups Projects
Commit 322aea16 authored by Jaden Diefenbaugh's avatar Jaden Diefenbaugh
Browse files

add basic report service for data model

parent 4c4e48c1
No related branches found
No related tags found
2 merge requests!223Reports overhaul,!220WIP: Experiment groups
......@@ -21,7 +21,7 @@
*/
//This controller retrieves data from the reportFactory/experimentFactory through the REST API and associates it with the $scope
//The $scope is ultimately bound to the report view
angular.module('reportApp').controller('reportController',['$scope', 'reportFactory', 'experimentFactory', 'plotterFactory', 'dataFactory', '$q', function ($scope, reportFactory, experimentFactory, plotterFactory, dataFactory, $q){
angular.module('reportApp').controller('reportController',['$scope', 'reportFactory', 'experimentFactory', 'plotterFactory', 'dataFactory', '$q', 'ReportService', function ($scope, reportFactory, experimentFactory, plotterFactory, dataFactory, $q, ReportService){
$scope.q = $q;
$scope.user;
$scope.report_id;
......
/*
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch
*
* This file is part of the beat.web module of the BEAT platform.
*
* Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch
*
* Alternatively, this file may be used under the terms of the GNU Affero
* Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file.
* The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero Public License along
* with the BEAT platform. If not, see http://www.gnu.org/licenses/.
*/
/*
* ReportService
* Desc:
* The datastore for the reports app, including data fetched from the
* server and cross-component app state
*/
angular.module('reportApp').factory('ReportService', ['$http', function($http){
let reportServiceInstance = {};
// experiments of reports are in arbitrary groups,
// in a many-to-many relationship
let groupData = [];
// represents a Group in the report
// has a name and a list of experiments that belong to it
class Group {
constructor (name) {
this.name = name;
this.experimentNames = new Set();
}
// get the experiment names in this group
get experiments () {
return Array.from(this.experimentNames);
}
// get the group name
get name () {
return this.name;
}
// check if an exp is in this group
hasExperiment (expName) {
return this.experimentNames.has(expName);
}
// add an exp to this group
addExperiment (expName) {
return this.experimentNames.add(expName);
}
// rm an exp from this group
removeExperiment (expName) {
return this.experimentNames.delete(expName);
}
};
// gets groups
reportServiceInstance.groups = () => groupData.map(g => g.name);
// create a new group for the report
// returns false if it already exists
// returns true if it adds a new group
reportServiceInstance.createGroup = (name) => {
if(typeof name !== 'string'){
throw new Error(`new group name is not a string: ${JSON.stringify(name)}`);
}
if(groupData.find(g => g.name === name)){
return false;
}
groupData.push(new Group(name));
return true;
};
// delete a group
reportServiceInstance.deleteGroup = (name) => {
groupData = groupData.filter(g => g.name !== name);
};
// fetch group info from the api
reportServiceInstance.fetchGroups = (reportName) => {
console.warn(`not implemented: reportServiceInstance.fetchGroups(${JSON.stringify(reportName)})`);
};
// save group info via sending to server
reportServiceInstance.saveGroups = () => {
console.warn(`not implemented: reportServiceInstance.saveGroups`);
};
// add experiment to group
reportServiceInstance.addExperimentToGroup = (expName, groupName) => {
checkForGroup(groupName);
let group = groupData.find(g => g.name === groupName);
return group.addExperiment(expName);
};
// rm experiment from group
reportServiceInstance.removeExperimentFromGroup = (expName, groupName) => {
checkForGroup(groupName);
let group = groupData.find(g => g.name === groupName);
return group.removeExperiment(expName);
};
// gets experiments from a group
reportServiceInstance.getGroupExperiments = (groupName) => {
checkForGroup(groupName);
let group = groupData.find(g => g.name === groupName);
return group.experiments;
};
// gets groups for an experiment
reportServiceInstance.getExperimentGroups = (expName) => {
return groupData.filter(g => g.hasExperiment(expName)).map(g => g.name);
};
// helper to assert that a group exists
function checkForGroup (groupName) {
if(!reportServiceInstance.groups().includes(groupName)){
throw new Error(`Could not find group "${JSON.stringify(groupName)}"`);
}
}
return reportServiceInstance;
}]);
......@@ -75,6 +75,7 @@
<script src="{% fingerprint "reports/app/factories/experimentFactory.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% fingerprint "reports/app/factories/plotterFactory.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% fingerprint "reports/app/factories/dataFactory.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% fingerprint "reports/app/services/reportService.js" %}" type="text/javascript" charset="utf-8"></script>
<!-- directives
-->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment