Skip to content

Commit

Permalink
# This is a combination of 5 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

remove obsolete properties from data sources

# This is the commit message drugis#2:

let workspaces work with the new schema; some refactoring

# This is the commit message drugis#3:

some refactoring

# This is the commit message drugis#4:

wip

# This is the commit message drugis#5:

wip rewriting inputknowledgeservice
  • Loading branch information
kzalite authored and chinook25 committed Jun 3, 2019
1 parent 935f34b commit 086c0ab
Show file tree
Hide file tree
Showing 27 changed files with 335 additions and 862 deletions.
90 changes: 45 additions & 45 deletions app/js/benefitRisk/schemaService.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';
define(['lodash', 'angular', 'ajv'], function (_, angular, Ajv) {
define(['lodash', 'angular', 'ajv'], function(_, angular, Ajv) {

var dependencies = [
'currentSchemaVersion',
'generateUuid'
];
var SchemaService = function (
var SchemaService = function(
currentSchemaVersion,
generateUuid
) {
Expand All @@ -28,10 +28,10 @@ define(['lodash', 'angular', 'ajv'], function (_, angular, Ajv) {
if (newProblem.schemaVersion === '1.1.0') {
newProblem = updateToVersionOnePointTwoPointZero(newProblem);
}

if (newProblem.schemaVersion === currentSchemaVersion) {
var error = isInvalidSchema(newProblem);

if (error) {
return {
isValid: false,
Expand Down Expand Up @@ -76,7 +76,7 @@ define(['lodash', 'angular', 'ajv'], function (_, angular, Ajv) {

function updateToVersionOnePointZeroPointZero(problem) {
var newProblem = angular.copy(problem);
newProblem.criteria = _.mapValues(problem.criteria, _.partial(createNewCriterion, problem));
newProblem.criteria = _.mapValues(problem.criteria, createNewCriterion);
newProblem.performanceTable = createNewPerformanceTable(newProblem);
newProblem.schemaVersion = '1.0.0';
return newProblem;
Expand All @@ -94,20 +94,38 @@ define(['lodash', 'angular', 'ajv'], function (_, angular, Ajv) {

function updateToVersionOnePointTwoPointZero(problem) {
var newProblem = angular.copy(problem);
newProblem.performanceTable = _.map(newProblem.performanceTable, function (entry) {
newProblem.performanceTable = changePerformanceTypeToArray(newProblem);
newProblem.criteria = removeObsoletePropertiesFromDataSource(newProblem);
newProblem.schemaVersion = '1.2.0';
return newProblem;
}

function removeObsoletePropertiesFromDataSource(problem) {
return _.mapValues(problem.criteria, function(criterion) {
criterion.dataSources = _.map(criterion.dataSources, function(dataSource) {
delete dataSource.inputType;
delete dataSource.inputMethod;
delete dataSource.dataType;
delete dataSource.parameterOfInterest;
return dataSource;
});
return criterion;
});
}

function changePerformanceTypeToArray(problem) {
return _.map(problem.performanceTable, function(entry) {
if (entry.alternative) {
entry.performance.type = [entry.performance.type];
return entry;
} else {
return entry;
}
});
newProblem.schemaVersion = '1.2.0';
return newProblem;
}

function putFavorabilityOnCriteria(problem) {
return _.mapValues(problem.criteria, function (criterion, criterionId) {
return _.mapValues(problem.criteria, function(criterion, criterionId) {
var newCriterion = angular.copy(criterion);
if (problem.valueTree.children[0].criteria) {
newCriterion.isFavorable = _.includes(problem.valueTree.children[0].criteria, criterionId);
Expand All @@ -119,7 +137,7 @@ define(['lodash', 'angular', 'ajv'], function (_, angular, Ajv) {
}

function createNewPerformanceTable(problem) {
return _.map(problem.performanceTable, function (tableEntry) {
return _.map(problem.performanceTable, function(tableEntry) {
var newEntry = angular.copy(tableEntry);
if (tableEntry.criterionUri) {
newEntry.criterion = tableEntry.criterionUri;
Expand All @@ -130,46 +148,28 @@ define(['lodash', 'angular', 'ajv'], function (_, angular, Ajv) {
});
}

function createNewCriterion(problem, criterion, criterionId) {
var newCriterion = _.pick(criterion, ['title', 'description', 'unitOfMeasurement']);
var dataSource = createDataSource(problem, criterion, criterionId);
function createNewCriterion(criterion) {
var newCriterion = _.pick(criterion, [
'title',
'description',
'unitOfMeasurement'
]);
var dataSource = createDataSource(criterion);
newCriterion.dataSources = [dataSource];
return newCriterion;
}

function createDataSource(problem, criterion, criterionId) {
var dataSource = _.pick(criterion, ['pvf', 'source', 'sourceLink', 'strengthOfEvidence', 'uncertainties', 'scale']);
function createDataSource(criterion) {
var dataSource = _.pick(criterion, [
'pvf',
'source',
'sourceLink',
'strengthOfEvidence',
'uncertainties',
'scale'
]);
dataSource.id = generateUuid();
var inputParameters = getInputParameters(problem.performanceTable, criterionId);
return _.merge(dataSource, inputParameters);
}

function getInputParameters(performanceTable, criterionId) {
var type = findEntryTypeForCriterion(performanceTable, criterionId);
if (isManualDistribution(type)) {
return {
inputType: 'distribution',
inputMethod: 'manualDistribution'
};
} else if (type === 'dt') {
return {
inputType: 'distribution',
inputMethod: 'assistedDistribution',
dataType: 'continuous'
};
}
}

function findEntryTypeForCriterion(performanceTable, criterionId) {
var tableEntry = _.find(performanceTable, function (entry) {
return entry.criterion === criterionId || entry.criterionUri === criterionId;
});
return tableEntry.performance.type;
}

function isManualDistribution(type) {
var MANUAL_DISTRIBUTIONS = ['exact', 'dnorm', 'dbeta', 'dgamma'];
return _.includes(MANUAL_DISTRIBUTIONS, type);
return dataSource;
}

return {
Expand Down
23 changes: 0 additions & 23 deletions app/js/effectsTable/criterionCardDirective.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,6 @@ <h5>{{criterion.title}}</h5>
<th style="min-width: 15rem;">Reference
<inline-help help-key="criterion-source"></inline-help>
</th>
<th>
Input type
<inline-help help-key="input-type"></inline-help>
</th>
<th>
Input method
<inline-help help-key="input-method"></inline-help>
</th>
<th>
Data type
<inline-help help-key="criterion-data-type"></inline-help>
</th>
<th>
Parameter of interest
<inline-help help-key="parameter-of-interest"></inline-help>
</th>
<th>Strength of evidence / Uncertainties
<inline-help help-key="uncertainties"></inline-help>
<inline-help help-key="strength-of-evidence"></inline-help>
Expand Down Expand Up @@ -104,13 +88,6 @@ <h5>{{criterion.title}}</h5>
{{dataSource.source}}
</div>
</td>
<td ng-style="!dataSource.inputType ? {'color': 'red'} : {}">
{{dataSource.inputType ? dataSource.inputType : 'Unknown'}}</td>
<td>{{dataSource.inputType === 'distribution' ? INPUT_METHODS[dataSource.inputMethod] :'NA'}}</td>
<td>{{dataSource.inputType === 'effect' || dataSource.inputMethod === 'assistedDistribution' ? dataSource.dataType
: 'NA'}}</td>
<td>{{(dataSource.inputType && dataSource.inputType !== 'distribution') || dataSource.inputMethod === 'assistedDistribution'
? PARAMETERS_OF_INTEREST[dataSource.parameterOfInterest] : 'NA'}}</td>
<td>
<b>SoE: </b>{{dataSource.strengthOfEvidence}}
<br>
Expand Down
13 changes: 0 additions & 13 deletions app/js/effectsTable/criterionCardDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ define(['lodash'], function(_) {
scope.editDataSource = editDataSource;

// init
scope.INPUT_METHODS = {
manualDistribution: 'Manual distribution',
assistedDistribution: 'Assisted distribution'
};

scope.PARAMETERS_OF_INTEREST = {
mean: 'Mean',
median: 'Median',
cumulativeProbability: 'Cumulative probability',
eventProbability: 'Event probability',
value: 'value'
};

setUnit();
scope.$on('elicit.settingsChanged', setUnit);

Expand Down
13 changes: 0 additions & 13 deletions app/js/effectsTable/criterionListDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ define(['lodash'], function(_) {
//private
function initializeCriteriaLists() {
if (scope.isInput) {
checkForUnknownCriteria();
checkForMissingFavorability();
}
var partition = _.partition(scope.criteria, ['isFavorable', true]);
Expand All @@ -130,18 +129,6 @@ define(['lodash'], function(_) {
scope.errors.push('Missing favorability');
}
}

function checkForUnknownCriteria() {
var error = 'Unknown input type';
_.pull(scope.errors, error);
if (_.find(scope.criteria, function(criterion) {
return _.find(criterion.dataSources, function(dataSource) {
return !dataSource.inputType;
});
})) {
scope.errors.push(error);
}
}
}
};
};
Expand Down
3 changes: 1 addition & 2 deletions app/js/effectsTable/effectsTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ <h4>Effects Table
workspace-settings="workspaceSettings"
scales="scales[row.dataSource.id][alternative.id]"
theoretical-scale="row.dataSource.scale"
alternative-id="alternative.id"
input-type="row.dataSource.inputType">
alternative-id="alternative.id">
</effects-table-cell>

</td>
Expand Down
8 changes: 4 additions & 4 deletions app/js/effectsTable/effectsTableCellDirective.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{{effectDataSourceLabel}}
</div>
<div ng-if="!isEffect">
<effects-table-scales-cell scales="scales" workspace-settings="workspaceSettings" theoretical-scale="theoreticalScale"
uncertainty="uncertainty">
<effects-table-scales-cell scales="scales" workspace-settings="workspaceSettings"
theoretical-scale="theoreticalScale" uncertainty="uncertainty">
</effects-table-scales-cell>
</div>
</div>
Expand All @@ -24,8 +24,8 @@
</effects-table-scales-cell>
</div>

<div ng-if="effectsDisplay==='deterministic'">
<div ng-if="effectsDisplay === 'deterministic'">
<effects-table-scales-cell scales="scales" uncertainty="false" workspace-settings="workspaceSettings"
theoretical-scale="theoreticalScale">
</effects-table-scales-cell>
</div>
</div>
9 changes: 4 additions & 5 deletions app/js/effectsTable/effectsTableCellDirective.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
define([], function() {
define(['lodash'], function(_) {

var dependencies = ['$filter'];

Expand All @@ -11,8 +11,7 @@ define([], function() {
'workspaceSettings': '=',
'scales': '=',
'theoreticalScale': '=',
'alternativeId': '=',
'inputType': '='
'alternativeId': '='
},
templateUrl: './effectsTableCellDirective.html',
link: function(scope) {
Expand All @@ -21,11 +20,11 @@ define([], function() {
scope.$watch('workspaceSettings', init, true);

function init() {
scope.uncertainty = scope.effectsTableInfo.distributionType === 'relative' || scope.effectsTableInfo.studyDataLabelsAndUncertainty[scope.alternativeId].hasUncertainty;
scope.uncertainty = _.includes(scope.effectsTableInfo.distributionType , 'relative') || scope.effectsTableInfo.studyDataLabelsAndUncertainty[scope.alternativeId].hasUncertainty;
scope.effectsDisplay = scope.workspaceSettings.effectsDisplay;
scope.hasStudyData = scope.effectsTableInfo.hasStudyData;
scope.isEffect = scope.inputType === 'effect';
scope.effectDataSourceLabel = scope.effectsTableInfo.studyDataLabelsAndUncertainty ? scope.effectsTableInfo.studyDataLabelsAndUncertainty[scope.alternativeId].label : undefined;
scope.isEffect = _.includes(scope.effectsTableInfo.distributionType , 'exact');
}
}

Expand Down
Loading

0 comments on commit 086c0ab

Please sign in to comment.