Project 'vue-project/liangXing/frontEnd' was moved to 'vue-project/ZhangJian/ZhangJianFrontEnd'. Please update any links and bookmarks that may still have the old path.
Commit 14356554 by zhengyoujia

Merge branch 'dataExtraction' into 'master'

Data extractor

See merge request !2
parents c0e15878 f9616acd
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
/logs /logs
/video /video
/files /files
/data
*test* *test*
*.logs *.logs
*.zip *.zip
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
"request": "^2.88.0", "request": "^2.88.0",
"svg-captcha": "^1.3.12", "svg-captcha": "^1.3.12",
"tencentcloud-sdk-nodejs": "^4.0.562", "tencentcloud-sdk-nodejs": "^4.0.562",
"ts-node": "^10.9.2",
"ws": "^5.2.2", "ws": "^5.2.2",
"xlsx": "^0.18.5",
"xml2js": "^0.4.23" "xml2js": "^0.4.23"
}, },
"scripts": { "scripts": {
...@@ -44,5 +46,10 @@ ...@@ -44,5 +46,10 @@
"video/**/*" "video/**/*"
], ],
"outputPath": "dist" "outputPath": "dist"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"ts-jest": "^29.1.5"
} }
} }
import { join } from 'path';
import { readdirSync, readFileSync } from 'fs';
import * as XLSX from 'xlsx';
export class DataExtractor {
private static instance: DataExtractor;
private data: { [key: string]: any } = {};
private constructor() {
this.loadAllData();
}
public static getInstance(): DataExtractor {
if (!DataExtractor.instance) {
DataExtractor.instance = new DataExtractor();
}
return DataExtractor.instance;
}
private loadAllData(): void {
const dirPath = join(__dirname, '../../data');
const files = readdirSync(dirPath).filter(file => file.endsWith('.xlsx'));
console.log("Path is " + files);
files.forEach(file => {
const filePath = join(dirPath, file);
this.data[file] = this.parseExcel(filePath);
});
}
private parseExcel(filePath: string): any {
const file = readFileSync(filePath);
const workbook = XLSX.read(file, { type: 'buffer' });
const sheetNames = workbook.SheetNames;
const data = sheetNames.map(sheetName => ({
sheetName,
data: XLSX.utils.sheet_to_json(workbook.Sheets[sheetName])
}));
return data;
}
public getData(fileName: string): any {
return this.data[fileName];
}
public getAvailableFiles(): string[] {
return Object.keys(this.data);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment