export class ReporterVariablesFile {
/**
* Constructs a new ReporterVariablesFile object by deleting the existing
* file at the specified location and opening a new empty file.
* @param {string} dir Directory
* @param {string} filename Filename
* @example
* let file = new ReporterVariablesFile(reporter_temp, ReporterVariablesFile.JOB_CONTROL);
*/
constructor(dir, filename) {
if (!File.IsDirectory(dir)) {
ErrorMessage(`Directory <dir> in ReporterVariablesFile constructor does not exist: ${dir}`);
Exit();
}
if (!ReporterVariablesFile.GetAllNames().includes(filename)) {
ErrorMessage(`Unexpected <filename = "${filename}"> in ReporterVariablesFile constructor.`);
Exit();
}
let f_csv_name = `${dir}/${filename}`;
if (File.Exists(f_csv_name)) {
let success = File.Delete(f_csv_name);
if (!success) {
ErrorMessage(`Unable to delete existing file in ReporterVariablesFile constructor: ${f_csv_name}`);
Exit();
}
}
this._file = new File(f_csv_name, File.WRITE);
}
/** Job control variables filename
* @type {string} */
static get JOB_CONTROL() {
return `AAW_job_control_variables.csv`;
}
/** Results filename
* @type {string} */
static get RESULTS() {
return `automotive_assessment_results.csv`;
}
/* Class methods */
/**
* Return an array of all the available REPORTER variables filenames
* @returns {string[]}
* @example
* let filenames = ReporterVariablesFile.GetAllNames();
*/
static GetAllNames() {
return [ReporterVariablesFile.JOB_CONTROL, ReporterVariablesFile.RESULTS];
}
/**
* Writes a REPORTER variable to a CSV file.
* @param {string} name Name of variable
* @param {string} value Variable value
* @param {string} desc Description of variable
* @param {string} type Type of variable. Predefined types are "Directory", "File(absolute)", "File(basename)", "File(extension)", "File(tail)", "General", "Number" and "String". Alternatively give your own type. e.g. "NODE ID". If omitted default is "General"
* @example
* file.WriteVariable(f_csv, "KEYWORD_FILE", "C:/model/job.key", "Keyword file", "File(absolute)");
*/
WriteVariable(name, value, desc, type) {
this._file.Writeln(name + "," + value + "," + desc + "," + type);
}
/**
* Closes the ReporterVariablesFile.
* @example
* file.Close();
*/
Close() {
this._file.Close();
}
}