@wbg-mde/r-factory
Version:
Metadata editor R integration module
56 lines (55 loc) • 2.76 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const R = require("@wbg-mde/r-script");
const import_config_1 = require("../modules/import/import-config");
const config_1 = require("./config");
const variable_statistics_1 = require("../modules/convert/variable.statistics");
var _ = require('lodash');
class UpdateVarStatsTest {
constructor() {
this.datasetname = 'HND_2012_L2L_missing.dta';
this.fileId = 'F1';
this.statisticsInputRange = [
{
"action": "encodeMissing",
"name": "indid",
"properties": [{ "op": "..", "val": "*", "val2": "5" }]
}
];
this.libraryPath = '';
this.memoryLimit = 36000;
this.variableStatistics = null;
this.variableStatistics = new variable_statistics_1.VariableStatistics();
}
execute(callback) {
try {
let datafile = path.join(config_1.TestConfig.inputPath.dataset, this.datasetname);
let inputJson = path.join(config_1.TestConfig.inputPath.json, this.fileId + '.json');
let inputCSV = path.join(config_1.TestConfig.inputPath.csv, this.fileId + '.csv');
let paramJson = path.join(config_1.TestConfig.inputPath.finaljson, this.fileId + '.json');
let outJsonFile = path.join(config_1.TestConfig.outputPath.json, this.fileId + '.json');
R(config_1.TestConfig.scriptPath.import).data(datafile, path.extname(this.datasetname).slice(1), this.fileId, inputJson, import_config_1.ImportConfig.frequencyCalcLimit, this.libraryPath, this.memoryLimit, config_1.TestConfig.scriptPath.workingDirectory).call((err, rowCount) => {
if (err) {
callback({ result: 'error' });
console.log('import file R script execution error - file( ' + this.datasetname + ' ):' + err.toString());
}
else {
R(config_1.TestConfig.scriptPath.exportCSV).data(datafile, path.extname(this.datasetname).slice(1), inputCSV, this.libraryPath, this.memoryLimit).call((err, resp) => {
if (err) {
callback({ result: 'error' });
console.log('write csv error - file( ' + this.datasetname + ' ):' + err.toString());
}
else {
}
});
}
});
}
catch (e) {
console.log('execute error >> ' + e);
callback({ result: 'error' });
}
}
}
exports.UpdateVarStatsTest = UpdateVarStatsTest;