مقدمة:
حل ألغاز الكود
// radiator_calculator.js
/**
* حساب المشعات المطلوبة
* @param {number} area - مساحة الغرفة بالمتر المربع
* @param {number} insulation - معامل العزل (0.5-1.5)
* @param {number} tempDifference - الفرق بين الداخل والخارج
* @param {number} sectionPower - قوة الريشة الواحدة بالواط
* @returns {object} - عدد المشعات والتفاصيل
*/
function calculateRadiators(area, insulation = 1.0, tempDifference = 20, sectionPower = 150) {
// التحقق من صحة المدخلات
if (area <= 0) {
return { error: "المساحة يجب أن تكون أكبر من 0" };
}
// حساب الواط المطلوب
// الصيغة: المساحة × معامل العزل × الفرق في درجة الحرارة
const ceilingHeight = 3; // ارتفاع السقف (متر)
const wallArea = (area * 2) + (ceilingHeight * 20); // تقريبي
let totalWattNeeded = area * insulation * tempDifference * 1.1; // 1.1 عامل أمان
// حساب عدد الريش
let numberOfSections = Math.ceil(totalWattNeeded / sectionPower);
// توزيع المشعات بذكاء
let radiators = distributeRadiators(area, numberOfSections);
return {
area: area,
insulation: insulation,
tempDifference: tempDifference,
totalWattNeeded: Math.round(totalWattNeeded),
numberOfSections: numberOfSections,
radiators: radiators,
recommendation: getRecommendation(numberOfSections)
};
}
/**
* توزيع ذكي للمشعات
*/
function distributeRadiators(area, totalSections) {
const radiatorSize = 20; // عدد ريش المشعة الواحدة (تقريبي)
const numberOfRadiators = Math.ceil(totalSections / radiatorSize);
// توزيع متساوي
const baseSize = Math.floor(totalSections / numberOfRadiators);
const remainder = totalSections % numberOfRadiators;
let radiators = [];
for (let i = 0; i < numberOfRadiators; i++) {
let sections = baseSize + (i < remainder ? 1 : 0);
radiators.push({
id: i + 1,
sections: sections,
power: sections * 150,
location: getLocationRecommendation(area, i, numberOfRadiators)
});
}
return radiators;
}
/**
* توصية مكان المشعة
*/
function getLocationRecommendation(area, index, total) {
const locations = [
"تحت النافذة الرئيسية",
"جدار خارجي مقابل الباب",
"جدار خارجي الزاوية",
"تحت نافذة جانبية"
];
if (index < locations.length) {
return locations[index];
}
return "جدار خارجي متاح";
}
/**
* توصية حسب عدد الريش
*/
function getRecommendation(sections) {
if (sections < 300) {
return "مشعة واحدة صغيرة كافية";
} else if (sections < 600) {
return "مشعة واحدة متوسطة أو مشعتان صغيرتان";
} else if (sections < 1200) {
return "مشعتان متوسطتان أو ثلاث صغيرات";
} else {
return "مشعات متعددة (3+) أو نظام توزيع مركزي";
}
}
/**
* حساب استهلاك الطاقة السنوي
*/
function calculateAnnualCost(totalWattNeeded, heatingHoursPerYear = 3000, electricityPrice = 0.15) {
const energyKWh = (totalWattNeeded / 1000) * heatingHoursPerYear;
const annualCost = energyKWh * electricityPrice;
return {
energyKWh: Math.round(energyKWh),
monthlyCost: Math.round(annualCost / 12),
annualCost: Math.round(annualCost)
};
}
/**
* دالة مساعدة للحسابات المتقدمة
*/
function advancedCalculation(room) {
const {
area = 20,
height = 3,
windowArea = 5,
insulation = 1.0,
outdoorTemp = 5,
desiredTemp = 22,
exposedWalls = 2 // عدد الجدران الخارجية
} = room;
// حساب أكثر دقة
const tempDiff = desiredTemp - outdoorTemp;
const wallLosses = exposedWalls * height * 20 * (tempDiff / 20); // فقدان الجدران
const windowLosses = windowArea * 5.5 * (tempDiff / 20); // فقدان النوافذ
const floorLosses = area * 1.5 * (tempDiff / 20); // فقدان الأرضية
let totalLosses = (wallLosses + windowLosses + floorLosses) * insulation;
let numberOfSections = Math.ceil(totalLosses / 150);
return {
wallLosses: Math.round(wallLosses),
windowLosses: Math.round(windowLosses),
floorLosses: Math.round(floorLosses),
totalLosses: Math.round(totalLosses),
numberOfSections: numberOfSections,
estimatedRadiators: Math.ceil(numberOfSections / 20)
};
}
// ============ أمثلة الاستخدام ============
// مثال 1: حساب بسيط
console.log("=== حساب بسيط ===");
let result1 = calculateRadiators(30);
console.log(result1);
// مثال 2: حساب متقدم مع معاملات
console.log("\n=== حساب متقدم ===");
let result2 = calculateRadiators(40, 0.8, 18, 150);
console.log(result2);
// مثال 3: حساب التكلفة
console.log("\n=== تكلفة الطاقة ===");
let cost = calculateAnnualCost(result2.totalWattNeeded);
console.log(cost);
// مثال 4: حساب دقيق لغرفة محددة
console.log("\n=== حساب دقيق ===");
let advancedResult = advancedCalculation({
area: 30,
height: 3,
windowArea: 6,
insulation: 0.9,
outdoorTemp: 2,
desiredTemp: 22,
exposedWalls: 2
});
console.log(advancedResult);
من الحكم والأمثال العربية وبعضها من العالم والتاريخ والحكماء عن الفشل والنجاح
الأمثال العربية
من تعثر حكم
بكثرة التعثر يتعلم الصبي المشي
الضربة ما لم تقصم ظهرك تقويك
لا يصل الناس إلى حديقة النجاح دون أن يمرو بمحطات الفشل والتعب
اقوال فلافسة وعلماء
توماس إديسون:أنا لم أفشل بل وجدت ألف طريقة لا يعمل المصباح بها
ألبير أونشطاين :الشخص الذي لم يرتكب أخطاءلم يجرب أي شيء جديد
تجميعة :
أسقط سبع مرات وأنهض في الثامنةمثل ياباني
السهام الة هابطة تسبق الصعود مثل صيني
الماس ليس إلا قطعة فحم تعاملت مع الضغط جيدا مثل إنجليزي
خاتمة
تحية لكل مجتهد للخير.

تعليقات
إرسال تعليق