cleanifix
Version:
Intelligent data cleaning CLI with natural language support - Docker-powered Python engine
197 lines โข 8.24 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutputFormatter = void 0;
const chalk_1 = __importDefault(require("chalk"));
const cli_table3_1 = __importDefault(require("cli-table3"));
class OutputFormatter {
/**
* Format the analyze command results
*/
static formatAnalyzeResults(result) {
console.log('\n' + chalk_1.default.bold.cyan('๐ Data Analysis Results'));
console.log(chalk_1.default.gray('โ'.repeat(50)));
// Missing values analysis
if (result.missing_values) {
console.log('\n' + chalk_1.default.yellow('๐ Missing Values Analysis:'));
const missing = result.missing_values;
if (missing.total_missing_cells === 0) {
console.log(chalk_1.default.green(' โ No missing values found!'));
}
else {
console.log(chalk_1.default.red(` โ ๏ธ Total missing cells: ${missing.total_missing_cells}`));
if (missing.missing_by_column && Object.keys(missing.missing_by_column).length > 0) {
const table = new cli_table3_1.default({
head: [chalk_1.default.white('Column'), chalk_1.default.white('Missing Count')],
style: { head: [], border: [] }
});
for (const [column, count] of Object.entries(missing.missing_by_column)) {
if (count > 0) {
table.push([column, chalk_1.default.red(count.toString())]);
}
}
if (table.length > 0) {
console.log(table.toString());
}
}
}
}
// Duplicates analysis
if (result.duplicates) {
console.log('\n' + chalk_1.default.yellow('๐ Duplicate Analysis:'));
const dups = result.duplicates;
if (dups.count === 0) {
console.log(chalk_1.default.green(' โ No duplicate rows found!'));
}
else {
console.log(chalk_1.default.red(` โ ๏ธ Duplicate rows found: ${dups.count}`));
if (dups.details) {
const table = new cli_table3_1.default({
head: [chalk_1.default.white('Type'), chalk_1.default.white('Count')],
style: { head: [], border: [] }
});
for (const [type, count] of Object.entries(dups.details)) {
table.push([type, chalk_1.default.yellow(count.toString())]);
}
console.log(table.toString());
}
}
}
// Format issues
if (result.format_issues) {
console.log('\n' + chalk_1.default.yellow('๐ Format Issues:'));
const issues = result.format_issues;
if (issues.count === 0) {
console.log(chalk_1.default.green(' โ No format issues detected!'));
}
else {
console.log(chalk_1.default.red(` โ ๏ธ Format issues found: ${issues.count}`));
}
}
// Quality score
if (result.quality) {
console.log('\n' + chalk_1.default.yellow('๐ Data Quality Score:'));
const score = result.quality.score;
let scoreColor = chalk_1.default.green;
let emoji = '๐ข';
if (score < 60) {
scoreColor = chalk_1.default.red;
emoji = '๐ด';
}
else if (score < 80) {
scoreColor = chalk_1.default.yellow;
emoji = '๐ก';
}
const scoreBar = this.createProgressBar(score, 100);
console.log(` ${emoji} Score: ${scoreColor.bold(score + '%')} ${scoreBar}`);
// Quality insights
if (score >= 80) {
console.log(chalk_1.default.gray(' Good data quality! Minor improvements possible.'));
}
else if (score >= 60) {
console.log(chalk_1.default.gray(' Fair data quality. Consider cleaning operations.'));
}
else {
console.log(chalk_1.default.gray(' Poor data quality. Significant cleaning needed.'));
}
}
console.log('\n' + chalk_1.default.gray('โ'.repeat(50)));
}
/**
* Format the clean command results
*/
static formatCleanResults(result) {
console.log('\n' + chalk_1.default.bold.green('๐งน Data Cleaning Complete!'));
console.log(chalk_1.default.gray('โ'.repeat(50)));
if (result.message) {
console.log(chalk_1.default.green(' โ ' + result.message));
}
if (result.warning) {
console.log(chalk_1.default.yellow(' โ ๏ธ ' + result.warning));
}
if (result.result) {
const details = result.result;
if (details.rows_removed !== undefined) {
console.log(chalk_1.default.cyan(` ๐ Rows removed: ${details.rows_removed}`));
}
if (details.rows_modified !== undefined) {
console.log(chalk_1.default.cyan(` ๐ Rows modified: ${details.rows_modified}`));
}
if (details.cells_cleaned !== undefined) {
console.log(chalk_1.default.cyan(` ๐ Cells cleaned: ${details.cells_cleaned}`));
}
}
console.log(chalk_1.default.gray('โ'.repeat(50)));
}
/**
* Format error messages
*/
static formatError(error) {
console.log('\n' + chalk_1.default.bold.red('โ Error'));
console.log(chalk_1.default.gray('โ'.repeat(50)));
if (error.message) {
console.log(chalk_1.default.red(' ' + error.message));
}
else {
console.log(chalk_1.default.red(' An unexpected error occurred'));
}
if (error.type) {
console.log(chalk_1.default.gray(` Error type: ${error.type}`));
}
console.log(chalk_1.default.gray('โ'.repeat(50)));
}
/**
* Create a visual progress bar
*/
static createProgressBar(value, max, width = 20) {
const percentage = value / max;
const filled = Math.round(width * percentage);
const empty = width - filled;
return chalk_1.default.green('โ'.repeat(filled)) + chalk_1.default.gray('โ'.repeat(empty));
}
/**
* Format generic success message
*/
static formatSuccess(message) {
console.log('\n' + chalk_1.default.bold.green('โ
Success'));
console.log(chalk_1.default.gray('โ'.repeat(50)));
console.log(chalk_1.default.green(' ' + message));
console.log(chalk_1.default.gray('โ'.repeat(50)));
}
/**
* Format the output based on command type and result
*/
static format(result) {
// Hide the raw JSON and Docker logs
if (!result || typeof result !== 'object') {
return;
}
if (!result.success) {
this.formatError(result.error || result);
return;
}
switch (result.type) {
case 'analyze':
if (result.result) {
this.formatAnalyzeResults(result.result);
}
break;
case 'clean':
this.formatCleanResults(result);
break;
case 'health_check':
console.log(chalk_1.default.green('โ
Health check passed!'));
console.log(chalk_1.default.gray(` Python version: ${result.python_version}`));
break;
default:
// For other commands, show a generic success message
if (result.message) {
this.formatSuccess(result.message);
}
}
}
}
exports.OutputFormatter = OutputFormatter;
//# sourceMappingURL=output-formatter.js.map