@ppramanik62/lab-works
Version:
A comprehensive command-line toolkit for hydraulic turbine calculations, supporting Francis Turbine and Pelton Wheel computations with interactive mode and validation.
107 lines • 4.81 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.runFrancis = exports.printResultsJson = exports.printResults = void 0;
/**
* Francis Turbine Calculator - Main orchestrator
*/
const formulas_1 = require("./formulas");
const io_1 = require("./io");
const round_1 = require("../../shared/round");
const colors_1 = require("../../shared/colors");
/**
* Print results in human-readable format
*/
const printResults = (results) => {
const header = (0, colors_1.safeColorize)('\n=== Francis Turbine Results ===', colors_1.theme.header);
console.log(header);
const labels = {
Ha: (0, colors_1.safeColorize)('Ha: ', colors_1.theme.label),
N1: (0, colors_1.safeColorize)('N1: ', colors_1.theme.label),
Q1: (0, colors_1.safeColorize)('Q1: ', colors_1.theme.label),
T1: (0, colors_1.safeColorize)('T1: ', colors_1.theme.label),
Pt1: (0, colors_1.safeColorize)('Pt1:', colors_1.theme.label),
Pa: (0, colors_1.safeColorize)('Pa: ', colors_1.theme.label),
eta: (0, colors_1.safeColorize)('eta:', colors_1.theme.label),
};
console.log(`${labels.Ha} ${(0, colors_1.safeColorize)((0, round_1.threeDecimal)(results.Ha).toString(), colors_1.theme.value)}`);
console.log(`${labels.N1} ${(0, colors_1.safeColorize)((0, round_1.threeDecimal)(results.N1).toString(), colors_1.theme.value)}`);
console.log(`${labels.Q1} ${(0, colors_1.safeColorize)((0, round_1.formatNumber)(results.Q1, 6), colors_1.theme.value)}`);
console.log(`${labels.T1} ${(0, colors_1.safeColorize)((0, round_1.threeDecimal)(results.T1).toString(), colors_1.theme.value)}`);
console.log(`${labels.Pt1} ${(0, colors_1.safeColorize)((0, round_1.threeDecimal)(results.Pt1).toString(), colors_1.theme.value)}`);
console.log(`${labels.Pa} ${(0, colors_1.safeColorize)((0, round_1.threeDecimal)(results.Pa).toString(), colors_1.theme.value)}`);
console.log(`${labels.eta} ${(0, colors_1.safeColorize)((0, round_1.threeDecimal)(results.eta).toString(), colors_1.theme.value)}`);
console.log('');
};
exports.printResults = printResults;
/**
* Print results in JSON format
*/
const printResultsJson = (results) => {
console.log(JSON.stringify({
calculator: 'francis-turbine',
results: {
Ha: (0, round_1.threeDecimal)(results.Ha),
N1: (0, round_1.threeDecimal)(results.N1),
Q1: Number((0, round_1.formatNumber)(results.Q1, 6)),
T1: (0, round_1.threeDecimal)(results.T1),
Pt1: (0, round_1.threeDecimal)(results.Pt1),
Pa: (0, round_1.threeDecimal)(results.Pa),
eta: (0, round_1.threeDecimal)(results.eta),
}
}, null, 2));
};
exports.printResultsJson = printResultsJson;
/**
* Run the Francis Turbine calculator
*/
const runFrancis = async (options = {}) => {
try {
const input = await (0, io_1.collectInput)(options);
const results = (0, formulas_1.calculateFrancis)(input.ppg, input.npg, input.w1, input.w2, input.rpm);
if (options.json) {
(0, exports.printResultsJson)(results);
}
else {
(0, exports.printResults)(results);
}
}
catch (error) {
const { handleError } = await Promise.resolve().then(() => __importStar(require('../../shared/error')));
handleError(error);
}
};
exports.runFrancis = runFrancis;
//# sourceMappingURL=index.js.map