phd/assets/optimize-curves.js

38 lines
893 B
JavaScript
Raw Permalink Normal View History

2019-08-28 17:43:21 +02:00
const fs = require('fs');
2019-09-11 16:47:38 +02:00
const optimum = 500;
2019-08-28 17:43:21 +02:00
function find(path) {
let output = [];
for (let content of fs.readdirSync(path, {withFileTypes: true})) {
if (content.isDirectory()) {
output.push(...find(path + '/' + content.name));
} else {
output.push(path + '/' + content.name);
}
}
return output;
}
function optimizeCurve(path) {
let input = fs.readFileSync(path, 'utf-8')
.split('\n')
.map((x) => x.split(' '));
let output = [input[0]];
let step = Math.floor(input.length / optimum);
for (let i = 1; i < input.length; i += step) {
output.push(input[i]);
}
fs.writeFileSync(path.slice(0, - '-full.dat'.length) + '.dat', output.map((x) => x.join(' ')).join('\n'));
}
for (let file of find('.')) {
if (file.endsWith('-full.dat')) {
optimizeCurve(file);
}
}