perf: Do not read worksheet twice
This commit is contained in:
+7
-2
@@ -12,10 +12,15 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import ExcelJS from "exceljs"
|
||||||
|
|
||||||
import parseV1V2 from "./parse/v1_v2.js";
|
import parseV1V2 from "./parse/v1_v2.js";
|
||||||
import parseV3 from "./parse/v3.js";
|
import parseV3 from "./parse/v3.js";
|
||||||
|
|
||||||
export default async function parseThisShit(downloadedFilePath: string) {
|
export default async function parseThisShit(downloadedFilePath: string) {
|
||||||
await parseV1V2(downloadedFilePath);
|
const workbook = new ExcelJS.Workbook();
|
||||||
await parseV3(downloadedFilePath);
|
await workbook.xlsx.readFile(downloadedFilePath);
|
||||||
|
|
||||||
|
await parseV1V2(workbook);
|
||||||
|
await parseV3(workbook, downloadedFilePath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ExcelJS, { Worksheet } from "exceljs"
|
import { Workbook, Worksheet } from "exceljs"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import parseAbsence, { AbsenceResult } from "../utils/parseAbsence.js"
|
import parseAbsence, { AbsenceResult } from "../utils/parseAbsence.js"
|
||||||
import parseTeachers from "../utils/parseTeachers.js"
|
import parseTeachers from "../utils/parseTeachers.js"
|
||||||
@@ -27,9 +27,7 @@ interface ScheduleDay {
|
|||||||
ABSENCE?: AbsenceResult[];
|
ABSENCE?: AbsenceResult[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function parseV1V2(downloadedFilePath: string) {
|
export default async function parseV1V2(workbook: Workbook) {
|
||||||
const workbook = new ExcelJS.Workbook();
|
|
||||||
await workbook.xlsx.readFile(downloadedFilePath);
|
|
||||||
const teacherMap = await parseTeachers();
|
const teacherMap = await parseTeachers();
|
||||||
|
|
||||||
const dateRegex = /^(pondělí|úterý|středa|čtvrtek|pátek|po|út|ut|st|čt|ct|pa|pá)\s+(\d{1,2})\.\s*(\d{1,2})\.\s*(\d{4}|\d{2})/i;
|
const dateRegex = /^(pondělí|úterý|středa|čtvrtek|pátek|po|út|ut|st|čt|ct|pa|pá)\s+(\d{1,2})\.\s*(\d{1,2})\.\s*(\d{4}|\d{2})/i;
|
||||||
|
|||||||
+2
-6
@@ -15,7 +15,7 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import parseAbsence from "../utils/parseAbsence.js"
|
import parseAbsence from "../utils/parseAbsence.js"
|
||||||
import parseTeachers from "../utils/parseTeachers.js"
|
import parseTeachers from "../utils/parseTeachers.js"
|
||||||
import ExcelJS, { Worksheet, Cell, Row } from "exceljs"
|
import ExcelJS, { Worksheet, Cell, Row, Workbook } from "exceljs"
|
||||||
import JSZip from "jszip";
|
import JSZip from "jszip";
|
||||||
import { parseStringPromise } from "xml2js";
|
import { parseStringPromise } from "xml2js";
|
||||||
|
|
||||||
@@ -42,8 +42,6 @@ async function getThemeColors(filePath: string): Promise<ThemeColors | null> {
|
|||||||
const data = fs.readFileSync(filePath);
|
const data = fs.readFileSync(filePath);
|
||||||
const zip = await JSZip.loadAsync(data);
|
const zip = await JSZip.loadAsync(data);
|
||||||
|
|
||||||
// list all files for debug
|
|
||||||
|
|
||||||
const themeFile = zip.file("xl/theme/theme1.xml");
|
const themeFile = zip.file("xl/theme/theme1.xml");
|
||||||
if (!themeFile) {
|
if (!themeFile) {
|
||||||
return null;
|
return null;
|
||||||
@@ -118,9 +116,7 @@ function resolveCellColor(cell: Cell, themeColors: ThemeColors | null) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function parseV3(downloadedFilePath: string) {
|
export default async function parseV3(workbook: Workbook, downloadedFilePath: string) {
|
||||||
const workbook = new ExcelJS.Workbook();
|
|
||||||
await workbook.xlsx.readFile(downloadedFilePath);
|
|
||||||
const themeColors = await getThemeColors(downloadedFilePath);
|
const themeColors = await getThemeColors(downloadedFilePath);
|
||||||
|
|
||||||
const teacherMap = await parseTeachers();
|
const teacherMap = await parseTeachers();
|
||||||
|
|||||||
Reference in New Issue
Block a user