Skip to content

Commit

Permalink
Merge pull request #606 from olgn/fix-603
Browse files Browse the repository at this point in the history
Fix 603
  • Loading branch information
nellh authored Oct 4, 2018
2 parents 3876694 + 661ee6b commit 44460ce
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 13 deletions.
65 changes: 65 additions & 0 deletions validators/__tests__/headerFields.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const assert = require('chai').assert
const { collect39Issues } = require('../headerFields')

describe('headerFields', () => {
describe('collect39Issues()', () => {
it('should return an empty array if there are no files in allIssues39Dict', () => {
const allIssues39Dict = {}
const issues = collect39Issues(allIssues39Dict)
assert.isArray(issues)
assert.lengthOf(issues, 0)
})
it('should return one issue per file in the allIssues39Dict', () => {
const allIssues39Dict = {
file_1: [
{
code: 39,
reason: 'for some reason',
},
{
code: 39,
reason: 'for some other reason',
},
],
}
const issues = collect39Issues(allIssues39Dict)
assert.isArray(issues)
assert.lengthOf(issues, 1)
})
it('should return one issue for each file with code 39 issues', () => {
const allIssues39Dict = {
file_1: [
{
code: 39,
reason: 'reason1',
},
],
file_2: [
{
code: 39,
reason: 'reason2',
},
],
}
const issues = collect39Issues(allIssues39Dict)
assert.lengthOf(issues, 2)
})
it('constructs a combined reason string from each issue.reason of a file', () => {
const allIssues39Dict = {
file_1: [
{
code: 39,
reason: 'reason1',
},
{
code: 39,
reason: 'reason2',
},
],
}
const issues = collect39Issues(allIssues39Dict)
assert.lengthOf(issues, 1)
assert(issues[0].reason == ' reason1 reason2')
})
})
})
31 changes: 18 additions & 13 deletions validators/headerFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Issue = utils.issues.Issue
* arrays more arguments will need to be added to headerField.
*/

var headerFields = function headerFields(headers) {
const headerFields = headers => {
var finalIssues = []
var allIssues39Dict = {}
var fields = ['dim', 'pixdim']
Expand All @@ -34,18 +34,22 @@ var headerFields = function headerFields(headers) {
}
}

for (let file in allIssues39Dict) {
if (allIssues39Dict.hasOwnProperty(file)) {
const firstIssue = allIssues39Dict[file][0]
let evidence = ''
for (var issue of allIssues39Dict[file]) {
evidence = evidence + ' ' + allIssues39Dict[file][issue].reason
}
firstIssue.reason = evidence
finalIssues.push(firstIssue)
finalIssues = finalIssues.concat(collect39Issues(allIssues39Dict))

return finalIssues
}

const collect39Issues = allIssues39Dict => {
const finalIssues = []
for (let file of Object.keys(allIssues39Dict)) {
const firstIssue = allIssues39Dict[file][0]
let evidence = ''
for (var issue of allIssues39Dict[file]) {
evidence = evidence + ' ' + issue.reason
}
firstIssue.reason = evidence
finalIssues.push(firstIssue)
}

return finalIssues
}

Expand All @@ -58,7 +62,7 @@ var headerFields = function headerFields(headers) {
* dimensionality of similar anatomy/functional/dwi headers are being compared.
*/

var headerField = function headerField(headers, field) {
const headerField = (headers, field) => {
var nifti_types = {}
var issues = {}
for (var header_index = 0; header_index < headers.length; header_index++) {
Expand Down Expand Up @@ -249,7 +253,7 @@ var headerField = function headerField(headers, field) {
* errors that cause resolutions to be slightly different. Returns true if
* the two headers are signifigantly different
*/
function headerFieldCompare(header1, header2) {
const headerFieldCompare = (header1, header2) => {
var hdr1 = header1.split(',')
var hdr2 = header2.split(',')
if (hdr1.length !== hdr2.length) {
Expand All @@ -272,3 +276,4 @@ function headerFieldCompare(header1, header2) {
}

module.exports = headerFields
module.exports.collect39Issues = collect39Issues

0 comments on commit 44460ce

Please sign in to comment.