Fix table bug, sort bug and path bug

This commit is contained in:
Oystein Kristoffer Tveit 2020-05-25 22:16:04 +02:00
parent 8fe252ea48
commit f6f5878164
2 changed files with 13 additions and 12 deletions

View File

@ -8,19 +8,20 @@ const {kanjiTable} = require('./src/kanjiTables.js');
/* Encapsulate main process in async function */ /* Encapsulate main process in async function */
async function main(jlptLevel) { async function main(jlptLevel) {
const jlptLevelCaps = jlptLevel.toUpperCase();
const kanjiArray = await fetchKanjiFromTxt(`./data/txt/${jlptLevel}.txt`); const kanjiArray = await fetchKanjiFromTxt(`./data/txt/${jlptLevel}.txt`);
console.log(`Fetched txt for ${jlptLevel}`); console.log(`${jlptLevelCaps}: Fetched txt`);
const results = await fetchKanjiFromJisho(kanjiArray); const results = await fetchKanjiFromJisho(kanjiArray);
console.log(`Fetched data from Jisho for ${jlptLevel}`); console.log(`${jlptLevelCaps}: Fetched Jisho data`);
const sortedResults = sortKanji(results); const sortedKanjiArray = results.map(result => result.query);
const sortedKanji = sortedResults.map(result => result.query); const texData = getKanjiTexData(results);
const texData = getKanjiTexData(sortedResults); console.log(`${jlptLevelCaps}: Processed pages`);
console.log(`Processed pages for ${jlptLevel}`);
const resultTable = kanjiTable(sortedKanji); const resultTable = kanjiTable(sortedKanjiArray);
console.log(`Processed table for ${jlptLevel}`); console.log(`${jlptLevelCaps}: Processed table`);
let resultPage = ''; let resultPage = '';
for (kanji of texData) { for (kanji of texData) {
@ -32,8 +33,8 @@ async function main(jlptLevel) {
\\newpage\n`; \\newpage\n`;
} }
fs.writeFile(`../data/tables/${jlptLevel}.tex`, resultTable, (err) => {if (err) console.error(err)}); fs.writeFile(`./data/tables/${jlptLevel}.tex`, resultTable, (err) => {if (err) console.error(err)});
fs.writeFile(`../data/pages/${jlptLevel}.tex`, resultPage, (err) => {if (err) console.error(err)}); fs.writeFile(`./data/pages/${jlptLevel}.tex`, resultPage, (err) => {if (err) console.error(err)});
} }
async function mainWrapper() { async function mainWrapper() {

View File

@ -1,5 +1,5 @@
function kanjiTable(kanjiArray) { function kanjiTable(kanjiArray) {
const xLength = 20; const xLength = 15;
const yLength = Math.ceil(kanjiArray.length/xLength); const yLength = Math.ceil(kanjiArray.length/xLength);
const sideLength = Math.ceil(Math.sqrt(kanjiArray.length)); const sideLength = Math.ceil(Math.sqrt(kanjiArray.length));
@ -9,7 +9,7 @@ function kanjiTable(kanjiArray) {
const lineArray = new Array; const lineArray = new Array;
for (let x_index = 0; x_index < xLength; x_index++) { for (let x_index = 0; x_index < xLength; x_index++) {
const indexNumber = y_index * yLength + x_index; const indexNumber = y_index * xLength + x_index;
lineArray.push(kanjiArray[indexNumber] ? kanjiArray[indexNumber] : ''); lineArray.push(kanjiArray[indexNumber] ? kanjiArray[indexNumber] : '');
} }