UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

48 lines 1.71 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.fileBasedCount = fileBasedCount; exports.writeFileBasedCountToFile = writeFileBasedCountToFile; const fs_1 = __importDefault(require("fs")); /** * The purpose of this function is to reformat {@link ClusterReport} in way that lists file-based contributions. * E.g., "the file with id 12 contained the assignment with `<-` 3 times". * Feature Values are listed in the header. * * @param report - the report to reformat */ function fileBasedCount(report) { const values = report.valueInfoMap; const contexts = [...report.valueInfoMap.values()]; const header = [...values.keys()].map(k => `"${k}"`); const rows = []; for (const id of report.contextIdMap.values()) { rows.push(contexts.map(c => `${c.get(id)}`)); } return { header: header, rows: rows }; } /** * The threshold will cap of values larger to the threshold. */ function writeFileBasedCountToFile(table, filepath) { const handle = fs_1.default.openSync(filepath, 'w'); const header = table.header.join('\t'); fs_1.default.writeSync(handle, `${header}\n`); let max = 0; function processEntry(r) { const val = Number(r); max = Math.max(val, max); return r; } for (const row of table.rows) { fs_1.default.writeSync(handle, row.map(processEntry).join('\t') + '\n'); } fs_1.default.writeSync(handle, `%%% max: ${max}\n`); fs_1.default.closeSync(handle); } //# sourceMappingURL=file-based-count.js.map