@wbg-mde/r-factory
Version:
Metadata editor R integration module
84 lines (83 loc) • 3.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const fs = require("fs");
const mkdirp = require("mkdirp");
const import_master_1 = require("../modules/import/import-master");
const export_dictionary_1 = require("../modules/export/export-dictionary");
const repository_1 = require("@wbg-mde/repository");
var _ = require('lodash');
class DictionaryTest {
constructor() {
this.inputDatasetDirectory = path.join(process.cwd(), "test_data", "input", "dataset");
this.inputJsonDirectory = path.join(process.cwd(), "test_data", "input", "json");
this.inputCSVDirectory = path.join(process.cwd(), "test_data", "input", "csv");
this.outputDictionaryDirectory = path.join(process.cwd(), "test_data", "data-dictionary");
this.libraryPath = '';
this.memoryLimit = 36000;
this.importMaster = null;
this.exportDictionary = null;
this.datasetType = "SPSS";
this.encoding = "Chinese";
mkdirp.sync(this.inputDatasetDirectory);
mkdirp.sync(this.inputJsonDirectory);
mkdirp.sync(this.inputCSVDirectory);
mkdirp.sync(this.outputDictionaryDirectory);
this.importMaster = new import_master_1.ImportMaster();
this.exportDictionary = new export_dictionary_1.ExportDataDictionary();
}
execute(type, callback) {
try {
this.datasetType = type.toUpperCase();
this.outputDictionaryDirectory = path.join(this.outputDictionaryDirectory, this.datasetType);
mkdirp.sync(this.outputDictionaryDirectory);
fs.readdir(this.inputDatasetDirectory, (err, files) => {
if (files) {
this.executeFiles(files, 0, (result) => {
callback(result);
});
}
});
}
catch (e) {
console.log('execute error >> ' + e);
callback({ result: 'error' });
}
}
executeFiles(files, index, callback) {
try {
let file = files[index];
}
catch (e) {
console.log('execute files error >> ' + e);
callback({ result: 'error' });
}
}
formatJson(filePath, outPath) {
let outstream = repository_1.Repository_Utility
.readFile(filePath)
.toString();
let jsonData = JSON.parse(outstream);
let formattedDataset = _.map(jsonData, (data) => {
let catgry = new Array();
if (data.catgry) {
catgry = _.map(data.catgry, (category) => {
if (category && category.catValu && category.catValu instanceof Array && category.catValu.length > 0) {
return category.catValu[0];
}
});
}
return {
name: data.name,
internalName: data.name,
val: catgry,
width: (data.location) ? data.location.width : [0],
StartPos: data.location.StartPos,
EndPos: data.location.EndPos,
dataType: data.varType
};
});
repository_1.Repository_Utility.writeFile(outPath, JSON.stringify(formattedDataset));
}
}
exports.DictionaryTest = DictionaryTest;