Skip to content

Commit 827420a

Browse files
jdkentnicoalee
andauthored
[FIX] Be more forgiving with white spaces and newlines in Sleuth Files (#1121)
* replace windows (\r\n) /old mac (\r) return carriages with (\n) * fix: added cypress test case * be more forgiving on whitespace * fix extra parens * remove the only function * be more restrictive on metadata * rollback messages * give error that matches tests * Revert "give error that matches tests" This reverts commit cf460d5. * revert this change * fix: clean up helper file --------- Co-authored-by: Nicholas Lee <[email protected]>
1 parent 8d082ba commit 827420a

19 files changed

+941
-925
lines changed

compose/neurosynth-frontend/cypress/e2e/workflows/SleuthImport/DoSleuthImport.cy.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('DoSleuthImport', () => {
2929
cy.contains('button', 'next').click();
3030
});
3131

32-
describe('should upload invalid sleuth files', () => {
32+
describe('should handle invalid sleuth files', () => {
3333
it('should upload a file and show invalid with no reference', () => {
3434
cy.get('input[type="file"]').selectFile(
3535
'cypress/fixtures/DoSleuthImport/sleuthFiles/invalidSleuthFileNoReference.txt',
@@ -142,6 +142,24 @@ describe('DoSleuthImport', () => {
142142
cy.get('[data-testid="InsertDriveFileIcon"]').should('have.length', 2);
143143
});
144144

145+
it('should upload a valid sleuth file with windows line endings', () => {
146+
cy.get('input[type="file"]').selectFile(
147+
'cypress/fixtures/DoSleuthImport/sleuthFiles/validSleuthFileWindowsLineEndings.txt',
148+
{ force: true }
149+
);
150+
cy.get('[data-testid="InsertDriveFileIcon"]').should('exist').and('be.visible');
151+
cy.contains('button', 'create project').should('be.enabled');
152+
});
153+
154+
it('should upload a valid sleuth file with wonky white space', () => {
155+
cy.get('input[type="file"]').selectFile(
156+
'cypress/fixtures/DoSleuthImport/sleuthFiles/validSleuthFileWonkyWhiteSpace.txt',
157+
{ force: true }
158+
);
159+
cy.get('[data-testid="InsertDriveFileIcon"]').should('exist').and('be.visible');
160+
cy.contains('button', 'create project').should('be.enabled');
161+
});
162+
145163
it('should enable if a valid file is uploaded', () => {
146164
cy.get('input[type="file"]').selectFile(
147165
'cypress/fixtures/DoSleuthImport/sleuthFiles/validSleuthFileWithDOI.txt',
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Reference=MNI
2+
// DOI=10.1016/1234567
3+
// PubMedId=67123237
4+
// Smith et al., 2019: Working Memory vs Baseline
5+
// Subjects=23
6+
-7.5 -8.5 -9.5
7+
10 -12 -62
8+
21 -14 -2
9+
0 -9 16
10+
11+
12+
// DOI=10.217/1234568
13+
// PubMedId=23782389
14+
// Roberts et al., 1995: 2 Back vs 1 Back
15+
// Graeff et al., 2000: 1 Back vs 0 Back
16+
// Edwards et al., 2017: 2 Back vs 0 Back
17+
// Subjects=62
18+
82 12 0
19+
-27 34 72
20+
-7 -8 -9
21+
10 -12 -62
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Reference=MNI
2+
// DOI=10.9999/example-doi-0001
3+
// PubMedID=12345678
4+
// Doe et al., 2021: sleep disorder > controls Table 1
5+
//Subjects=12
6+
-12 28 54
7+
3 12 27
8+
9+
// DOI=10.8888/example-doi-0002
10+
// PubMedID=23456789
11+
// Roe et al., 2022: sleep disorder < controls
12+
// Subjects = 10
13+
18 -12 63
14+
-42 -57 0
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const executeHTTPRequestsAsBatches = async <T, Y>(
2+
requestList: T[],
3+
mapFunc: (request: T) => Promise<Y>,
4+
rateLimit: number,
5+
delayInMS?: number,
6+
progressCallbackFunc?: (progress: number) => void
7+
) => {
8+
const arrayOfRequestArrays = [];
9+
for (let i = 0; i < requestList.length; i += rateLimit) {
10+
arrayOfRequestArrays.push(requestList.slice(i, i + rateLimit));
11+
}
12+
13+
const batchedResList: Y[] = [];
14+
for (const requests of arrayOfRequestArrays) {
15+
/**
16+
* I have to do the mapping from object to HTTP request here because
17+
* the promises are not lazy. The HTTP requests are launched as soon as
18+
* the function is called regardless of whether a .then() is added
19+
*/
20+
const batchedRes = await Promise.all(requests.map(mapFunc));
21+
batchedResList.push(...batchedRes);
22+
if (progressCallbackFunc) {
23+
progressCallbackFunc(Math.round((batchedResList.length / requestList.length) * 100));
24+
}
25+
if (delayInMS) {
26+
await new Promise((res) => {
27+
setTimeout(() => res(null), delayInMS);
28+
});
29+
}
30+
}
31+
return batchedResList;
32+
};

compose/neurosynth-frontend/src/hooks/metaAnalyses/useGetNeurovaultImages.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from 'axios';
2-
import { executeHTTPRequestsAsBatches } from 'pages/SleuthImport/SleuthImport.helpers';
2+
import { executeHTTPRequestsAsBatches } from 'helpers/requests';
33
import { useQuery } from 'react-query';
44

55
export interface INeurovault {

0 commit comments

Comments
 (0)