Fix table bug, sort bug and path bug
This commit is contained in:
parent
8fe252ea48
commit
f6f5878164
|
@ -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() {
|
||||||
|
|
|
@ -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] : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue