Skip to content

Commit

Permalink
Add absolute effects table & ability to set baseline distribution to …
Browse files Browse the repository at this point in the history
…model view
  • Loading branch information
chinook25 committed Mar 1, 2017
1 parent 78043cc commit 70b896d
Show file tree
Hide file tree
Showing 13 changed files with 317 additions and 197 deletions.
1 change: 0 additions & 1 deletion app/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ define(function(require) {
.controller('CreateNetworkModelController', require('gemtc-web/models/createNetworkModelController'))
.controller('AddComparisonFunnelPlotController', require('gemtc-web/models/addComparisonFunnelPlotController'))
.controller('PlotNavigationController', require('gemtc-web/util/graphModalDirective/plotNavigationController'))
.controller('SetBaselineDistributionController', require('models/setBaselineDistributionController'))
;
});
36 changes: 33 additions & 3 deletions app/js/controllers/modelController.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
define(['lodash', 'clipboard'], function(_, Clipboard) {
var dependencies = ['$scope', '$q', '$modal', '$state', '$stateParams', 'gemtcRootPath', 'ModelResource', 'ModelBaselineResource',
var dependencies = ['$scope', '$q', '$http', '$modal', '$state', '$stateParams', 'gemtcRootPath', 'ModelResource', 'ModelBaselineResource',
'FunnelPlotResource', 'PataviService',
'RelativeEffectsTableService', 'PataviTaskIdResource', 'ProblemResource', 'AnalysisResource', 'ModelService',
'DiagnosticsService', 'AnalysisService', 'DevianceStatisticsService', 'MetaRegressionService',
'ResultsPlotService'
];
var ModelController = function($scope, $q, $modal, $state, $stateParams, gemtcRootPath, ModelResource, ModelBaselineResource,
var ModelController = function($scope, $q, $http, $modal, $state, $stateParams, gemtcRootPath, ModelResource, ModelBaselineResource,
FunnelPlotResource, PataviService,
RelativeEffectsTableService, PataviTaskIdResource, ProblemResource, AnalysisResource, ModelService,
DiagnosticsService, AnalysisService, DevianceStatisticsService, MetaRegressionService,
Expand Down Expand Up @@ -186,6 +186,7 @@ define(['lodash', 'clipboard'], function(_, Clipboard) {
$scope.model.$promise.then(function(model) {
modelDefer.resolve(model);
});
resetScales();
return result;
});
}
Expand Down Expand Up @@ -222,7 +223,36 @@ define(['lodash', 'clipboard'], function(_, Clipboard) {
}

function resetScales() {
var problem = ModelService.buildScalesProblem($scope.analysis, $scope.baselineDistribution, $scope.results);
if (!$scope.baselineDistribution) {
return;
}
var problem = ModelService.buildScalesProblem($scope.analysis, $scope.baselineDistribution, $scope.result);
$http.post('/patavi', problem)
.then(function(result) {
var uri = result.data.uri;
if (result.status === 200 && uri) {
return uri;
}
}, function(error) {
$scope.$root.$broadcast('error', {
type: 'BACK_END_ERROR',
code: error.code || undefined,
message: 'unable to submit the problem to the server'
});
})
.then(function(uri) {
return PataviService.listen(uri);
})
.then(
function(result) {
$scope.scales = result[$scope.analysis.outcome.name];
},
function(pataviError) {
$scope.$root.$broadcast('error', {
type: 'PATAVI',
message: pataviError.desc
});
});
}

};
Expand Down
129 changes: 50 additions & 79 deletions app/js/models/modelService.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,107 +264,78 @@ define(['angular', 'lodash'], function(angular, _) {
return result;
}

function buildScalesProblem(analysis, problem, baselineDistribution) {
function buildScalesProblem(analysis, baselineDistribution, result) {
var criteria = {};
criteria[analysis.outcome.name] = {
scale: baselineDistribution.scale === 'mean' ? null : [0, 1],
pvf: null,
title: analysis.outcome.name,
unitOfMeasurement: baselineDistribution.scale === 'mean' ? null : 'proportion'
};

var alternatives = _.fromPairs(_.map(problem.treatments, function(treatment) {
var baselineId;
var alternatives = _.fromPairs(_.map(analysis.problem.treatments, function(treatment) {
if (baselineDistribution.name === treatment.name) {
baselineId = treatment.id;
}
return [treatment.name, {
alternative: treatment.id,
title: treatment.name
}];
}));

var performanceTable = _.map(criteria, function(criterion, criterionName) {
var result = {
criterion: criterionName
};


var mu = _.fromPairs(_.map(analysis.problem.treatments, function(treatment) {
var value;
if (treatment.id === baselineId) {
value = 0.0;
} else {
value = result.multivariateSummary[baselineId].mu['d.' + baselineId + '.' + treatment.id];
}
return [treatment.name, value];
}));

var treatmentsSorted = _.sortBy(analysis.problem.treatments, function(treatment) {
return treatment.id === baselineId ? -1 : 1;
});
var names = _.map(treatmentsSorted, function(alternative) {
return alternative.name;
});
var data = _.map(treatmentsSorted, function(treatmentX, idxX) {
return _.map(treatmentsSorted, function(treatmentY, idxY) {
if (idxX === 0 || idxY === 0) {
return 0;
}
return result.multivariateSummary[baselineId].sigma['d.' + baselineId + '.' + treatmentY.id]['d.' + baselineId + '.' + treatmentX.id];
});
});

return result;
var returnResult = {
criterion: criterionName,
performance: {
type: result.link === 'identity' ? 'relative-normal' : 'relative-' + result.link + '-normal',
parameters: {
baseline: baselineDistribution,
relative: {
type: 'dmnorm',
mu: mu,
cov: {
rownames: names,
colnames: names,
data: data
}
}
}
}
};
return returnResult;
});

return {
method: 'scales',
criteria: criteria,
alternatives: alternatives,
performanceTable: performanceTable
};

//out
// expectedResult = {
// "criteria": {
// "HAM-D Responders": {
// "criterionUri": "http://trials.drugis.org/concepts/hamd",
// "scale": [
// 0,
// 1
// ],
// "pvf": null,
// "title": "HAM-D Responders",
// "unitOfMeasurement": "proportion"
// }
// },
// "alternatives": {
// "Paroxetine": {
// "alternative": 260,
// "title": "Paroxetine"
// },
// "Fluoxetine": {
// "alternative": 259,
// "title": "Fluoxetine"
// },
// "Sertraline": {
// "alternative": 258,
// "title": "Sertraline"
// }
// },
// "performanceTable": [{
// "criterion": "HAM-D Responders",
// "performance": {
// "type": "relative-logit-normal",
// "parameters": {
// "baseline": {
// "scale": "log odds",
// "mu": 0.5,
// "sigma": 3,
// "name": "Fluoxetine",
// "type": "dnorm"
// },
// "relative": {
// "type": "dmnorm",
// "mu": {
// "Paroxetine": 0.20157,
// "Fluoxetine": 0,
// "Sertraline": 0.2784
// },
// "cov": {
// "rownames": [
// "Fluoxetine",
// "Paroxetine",
// "Sertraline"
// ],
// "colnames": [
// "Fluoxetine",
// "Paroxetine",
// "Sertraline"
// ],
// "data": [
// [0, 0, 0],
// [0, 0.031691, 0.0038127],
// [0, 0.0038127, 0.031576]
// ]
// }
// }
// }
// }
// }]
// };
}


Expand Down
Loading

0 comments on commit 70b896d

Please sign in to comment.