Skip to content

Commit

Permalink
Add NMIND data
Browse files Browse the repository at this point in the history
  • Loading branch information
nx10 committed Feb 13, 2024
1 parent e3fd0e4 commit a41dfcd
Show file tree
Hide file tree
Showing 65 changed files with 563 additions and 7,898 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "node src/lib/data/concatenate_data.js src/lib/data/evaluatedTools src/lib/data/evaluationSchemas src/lib/data/concat_data.json && vite dev",
"build": "node src/lib/data/concatenate_data.js src/lib/data/evaluatedTools src/lib/data/evaluationSchemas src/lib/data/concat_data.json && vite build",
"dev": "node src/lib/data/back_migrate_tools.js && node src/lib/data/concatenate_data.js src/lib/data/evaluatedTools src/lib/data/evaluationSchemas src/lib/data/concat_data.json && vite dev",
"build": "node src/lib/data/back_migrate_tools.js && node src/lib/data/concatenate_data.js src/lib/data/evaluatedTools src/lib/data/evaluationSchemas src/lib/data/concat_data.json && vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"build_test_fixtures": "node src/lib/data/concatenate_data.js tests/fixtures/evaluatedTools tests/fixtures/evaluationSchemas src/lib/data/concat_data.json",
"build_test_fixtures": "node src/lib/data/back_migrate_tools.js && node src/lib/data/concatenate_data.js tests/fixtures/evaluatedTools tests/fixtures/evaluationSchemas src/lib/data/concat_data.json",
"test": "vitest",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
Expand Down
106 changes: 106 additions & 0 deletions src/lib/data/back_migrate_tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// @ts-nocheck
import { promises } from 'fs';
import { join } from 'path';

const PATH_DIR_ENTRIES_INPUT = 'src/lib/data/entries';
const PATH_DIR_ENTRIES_OUTPUT = 'src/lib/data/evaluatedTools';


const OUTPUT_SKELETON = {
"name": null,
"description": null,
"urls": [],
"maintainers": [],
"evaluations": [],
"slug": null,
"image": "brain_9_svgrepo_com--CadetBlue.png",
"tags": []
};

const EVALUATION_SKELETON = {
"checklistVersion": "1.1",
"toolVersion": "0.0.0",
"date": null,
"evaluatorEmail": "[email protected]",
"checklist": {}
}


/**
* Read all json files from the input directory
* @param {string} dirPath - The path to the directory to read from
* @returns {Promise<any[]>} Each element is the parsed JSON content of a file
*/
async function readDirectoryData(dirPath) {
const files = await promises.readdir(dirPath);
const jsonFiles = files.filter((file) => file.endsWith('.json'));

return Promise.all(
jsonFiles.map(async (file) => {
const filePath = join(dirPath, file);
try {
const fileContents = await promises.readFile(filePath, 'utf8');
return JSON.parse(fileContents);
} catch (error) {
console.error(`Error reading file ${filePath}:`, error.message);
throw error;
}
})
);
}

function makeUrlSafeName(name) {
return name.toLowerCase().replace(/[^\w\s]/gi, '').replace(/ /g, '-');
}

function convertKeys(obj) {
const newObj = {};
Object.keys(obj).forEach(key => {
let categoryAbbreviation;
if (key === 'testing') {
categoryAbbreviation = 'tst';
} else if (key === 'infrastructure') {
categoryAbbreviation = 'inf';
} else if (key === 'documentation') {
categoryAbbreviation = 'doc';
} else {
return;
}
newObj[key] = {};
Object.keys(obj[key]).forEach(subKey => {
newObj[key][subKey] = {};
Object.keys(obj[key][subKey]).forEach(subSubKey => {
newObj[key][subKey][`${subKey}_${categoryAbbreviation}_${subSubKey}`] = obj[key][subKey][subSubKey];
});
});
});
return newObj;
}

function backMigrate(entry) {
const entry_backmigrated = { ...OUTPUT_SKELETON };
entry_backmigrated.name = entry.name;
entry_backmigrated.description = `This tool was migrated from the old format. Please update it.`;
entry_backmigrated.urls = entry.urls.map(x => ({ "text": x.url_type, href: x.url }));
entry_backmigrated.slug = makeUrlSafeName(entry.name);

const evaluation = { ...EVALUATION_SKELETON };
// set date as today in the format YYYY-MM-DD
evaluation.date = new Date().toISOString().split('T')[0];
evaluation.checklist = convertKeys(entry);

entry_backmigrated.evaluations.push(evaluation);
return entry_backmigrated;
}

// Create the output directory if it doesn't exist
await promises.mkdir(PATH_DIR_ENTRIES_OUTPUT, { recursive: true });

// Read all entries from the input directory, and write them to the output directory
for (const entry of await readDirectoryData(PATH_DIR_ENTRIES_INPUT)) {
const entry_backmigrated = backMigrate(entry);
const id = entry_backmigrated.slug;
const outputPath = join(PATH_DIR_ENTRIES_OUTPUT, `${id}.json`);
await promises.writeFile(outputPath, JSON.stringify(entry_backmigrated, null, 2));
console.log(`Generated ${outputPath} successfully.`);
}
79 changes: 79 additions & 0 deletions src/lib/data/entries/checklist_C_PAC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "C-PAC",
"urls": [
{
"url_type": "Source code",
"url": "https://github.com/FCP-INDI/C-PAC"
},
{
"url_type": "Landing page",
"url": "https://fcp-indi.github.io/"
}
],
"documentation": {
"bronze": {
"1": true,
"2": false,
"3": false,
"4": true,
"5": true,
"6": true,
"7": true,
"8": true,
"9": true
},
"silver": {
"1": true,
"2": false,
"3": true,
"4": true,
"5": true,
"6": true
},
"gold": {
"1": true,
"2": true,
"3": true,
"4": true,
"5": false,
"6": false
}
},
"infrastructure": {
"bronze": {
"1": true,
"2": true,
"3": true,
"4": true,
"5": true,
"6": false,
"7": true
},
"silver": {
"1": true,
"2": true,
"3": true
},
"gold": {
"1": true,
"2": false,
"3": false,
"4": false,
"5": false
}
},
"testing": {
"bronze": {
"1": true,
"2": true
},
"silver": {
"1": true,
"2": false
},
"gold": {
"1": false,
"2": false
}
}
}
75 changes: 75 additions & 0 deletions src/lib/data/entries/checklist_DataLad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"name": "DataLad",
"urls": [
{
"url_type": "Source code",
"url": "https://github.com/datalad/datalad/"
}
],
"documentation": {
"bronze": {
"1": true,
"2": true,
"3": true,
"4": true,
"5": true,
"6": true,
"7": true,
"8": true,
"9": true
},
"silver": {
"1": true,
"2": true,
"3": true,
"4": true,
"5": true,
"6": true
},
"gold": {
"1": true,
"2": true,
"3": true,
"4": true,
"5": true,
"6": true
}
},
"infrastructure": {
"bronze": {
"1": true,
"2": true,
"3": true,
"4": true,
"5": true,
"6": true,
"7": true
},
"silver": {
"1": true,
"2": true,
"3": true
},
"gold": {
"1": true,
"2": true,
"3": true,
"4": true,
"5": true
}
},
"testing": {
"bronze": {
"1": true,
"2": true
},
"silver": {
"1": true,
"2": true
},
"gold": {
"1": true,
"2": true
}
}
}
75 changes: 75 additions & 0 deletions src/lib/data/entries/checklist_dcm2niix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"name": "dcm2niix",
"urls": [
{
"url_type": "Source code",
"url": "https://github.com/rordenlab/dcm2niix"
}
],
"documentation": {
"bronze": {
"1": true,
"2": true,
"3": true,
"4": true,
"5": true,
"6": true,
"7": true,
"8": true,
"9": true
},
"silver": {
"1": true,
"2": false,
"3": true,
"4": true,
"5": false,
"6": true
},
"gold": {
"1": true,
"2": true,
"3": true,
"4": false,
"5": true,
"6": true
}
},
"infrastructure": {
"bronze": {
"1": true,
"2": true,
"3": true,
"4": true,
"5": true,
"6": false,
"7": true
},
"silver": {
"1": true,
"2": false,
"3": true
},
"gold": {
"1": false,
"2": true,
"3": true,
"4": true,
"5": false
}
},
"testing": {
"bronze": {
"1": true,
"2": true
},
"silver": {
"1": true,
"2": false
},
"gold": {
"1": false,
"2": false
}
}
}
Loading

0 comments on commit a41dfcd

Please sign in to comment.