Skip to content
This repository has been archived by the owner on Aug 17, 2018. It is now read-only.

Commit

Permalink
Implement explanation why compliant / not compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Apr 18, 2016
1 parent e970e6c commit 74fb1b2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 24 deletions.
46 changes: 40 additions & 6 deletions lib/common/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ var NEXA_RULES = {
}
return false;
},
explanation: {
1.0: "one of: acceptance, publication",
2.0: "embargo ok for both HUSS and STEM",
false: "not one of acceptance, publication or embargo too long",
},
guidelines: 3.14,
gmga: "29.2.2.b",
},
Expand Down Expand Up @@ -70,6 +75,9 @@ var NEXA_RULES = {
},
guidelines: [3.5, 3.13, 3.15],
gmga: "29.2.2.b",
explanation: {
true: "any value is ok",
},
normalize: function (v) {
return (
((v === "reccomended") ? "recommended" :
Expand Down Expand Up @@ -112,6 +120,11 @@ var NEXA_RULES = {
},
guidelines: 3.14,
gmga: "29.2.2.b",
explanation: {
true: "one of: no, not_specified",
0.25: "is yes (but see caveats)",
false: "not one of: no, not_specified, yes",
},
fuzzyLabels: {
0.25: "Please note that European Commission does not " +
"expressly state that maximal embargo cannot be " +
Expand All @@ -129,6 +142,11 @@ var NEXA_RULES = {
(v === "no") ? 0.75 : (v === "yes") ? 0.25 : false
);
},
explanation: {
0.75: "is 'no'",
0.25: "is 'yes'",
false: "is neither 'no' nor 'yes'",
},
gmga: ["29.1.1", "29.1.2"],
fuzzyLabels: {
0.75: "However, please note that Open Access must be " +
Expand All @@ -154,6 +172,10 @@ var NEXA_RULES = {
value.indexOf("not_specified") < 0
);
},
explanation: {
true: "not 'not_specified'",
false: "'not_specified'",
},
guidelines: [3.1, 3.3, 3.4, 3.11],
gmga: ["29.2.1", "29.2.2.a.2"],
},
Expand All @@ -162,16 +184,27 @@ var NEXA_RULES = {
var evaluateRule = function (rule, record, key, value) {
var compliantValues = rule.compliantValues,
initialExpr = compliantValues;
var compliant = ((typeof compliantValues === "string" &&
value === compliantValues) ||
(compliantValues instanceof Array &&
compliantValues.indexOf(value) >= 0) ||
(compliantValues instanceof Function &&
compliantValues(value, record, key)));
var compliant;
var reason;
if (typeof compliantValues === "string") {
compliant = (value === compliantValues);
reason = ((!compliant) ? "not " : "") + "equal to "
+ "'" + compliantValues + "'";
} else if (compliantValues instanceof Array) {
compliant = (compliantValues.indexOf(value) >= 0);
reason = ((!compliant) ? "not " : "") + "one of: "
+ compliantValues.join(", ");
} else if (compliantValues instanceof Function) {
compliant = compliantValues(value, record, key);
reason = rule.explanation[compliant];
} else {
throw "Programmer error";
}
return {
clause: compliantValues,
expr: initialExpr,
fuzzyLabel: (rule.fuzzyLabels && rule.fuzzyLabels[compliant]),
reason: reason,
value: compliant
};
};
Expand All @@ -186,6 +219,7 @@ var apply = exports.apply = function (record) {
newRecord.push({
field_id: rule.field_id,
field: key,
reason: compliantRec.reason,
value: (function () {
return (rule.normalize && rule.normalize(value));
})() || value,
Expand Down
8 changes: 8 additions & 0 deletions static/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ tr:nth-child(even) {
tr:hover {
background-color: #f3f781
}

td.compliant-true {
color: #228B22
}

td.compliant-false {
color: #FF0000
}
51 changes: 33 additions & 18 deletions static/partials/institution.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,40 @@
(<a href="{{g.selected.uri}}">roarmap url</a>)
(<a href="{{g.selected.policymaker_url}}">policy maker url</a>)
(<a href="{{g.selected.repository_url}}">repository url</a>)
(<a href="{{g.selected.policy_url}}">policy url</a>)</p>
(<a href="{{g.selected.policy_url}}">policy url</a>) <br />
compliance: {{g.selected.percentage|number:2}}%</p>

<ul>
<li>compliance: {{g.selected.percentage|number:2}}%</li>
<li>compliant with:
<ul>
<li ng-repeat="entry in g.selected.nexa | filter : { is_compliant: true }">
{{entry.field}}
</li>
</ul>
</li>
<li>not compliant with:
<ul>
<li ng-repeat="entry in g.selected.nexa | filter : { is_compliant: false }">
{{entry.field}}
</li>
</ul>
</li>
</ul>
<table>
<tr>
<th>#</th>
<th>field</th>
<th>value</th>
<th>is-compliant</th>
<th>reason</th>
<th>caveats</th>
<th>guidelines</th>
<th>gmga</th>
</tr>
<tr ng-repeat="entry in g.selected.nexa | orderBy:'field_id'">
<td class="compliant-{{entry.is_compliant}}">{{entry.field_id}}</td>
<td class="compliant-{{entry.is_compliant}}">{{entry.field}}</td>
<td class="compliant-{{entry.is_compliant}}">{{entry.value}}</td>
<td class="compliant-{{entry.is_compliant}}">{{entry.is_compliant}}</td>
<td class="compliant-{{entry.is_compliant}}">{{entry.reason}}</td>
<td class="compliant-{{entry.is_compliant}}">{{entry.fuzzy_label}}</td>
<td class="compliant-{{entry.is_compliant}}">
<span ng-repeat="ref in entry.gmga">
<a href="/details.html#{{ref}}" target="_blank">[{{ref}}]</a>
</span>
</td>
<td class="compliant-{{entry.is_compliant}}">
<span ng-repeat="ref in entry.guidelines">
<a href="/details.html#{{ref}}" target="_blank">[{{ref}}]</a>
</span>
</td>
</td>
<tr>
</table>

</div>
</div>

0 comments on commit 74fb1b2

Please sign in to comment.