modify landing page
This commit is contained in:
commit
dd232b1c02
2599 files changed
+226992
No files matched your search
@@ -0,0 +1,81 @@
|
||||
/* crop_water.js — ความต้องการน้ำของพืช (ETc = Kc × ETo)
|
||||
pure module: ไม่แตะ DOM ใช้ได้ทั้งเบราว์เซอร์และ Node test
|
||||
|
||||
หน่วย:
|
||||
- ETo (mm/day) มาจาก data/climate/eto_by_region.json (Penman-Monteith รายจังหวัด)
|
||||
- 1 ไร่ = 1,600 ตร.ม. · น้ำลึก 1 มม. บน 1 ไร่ = 1.6 ลบ.ม.
|
||||
*/
|
||||
|
||||
export const RAI_IN_SQUARE_METRE = 1600;
|
||||
export const CUBIC_METRE_PER_MILLIMETRE_PER_RAI = RAI_IN_SQUARE_METRE / 1000; // 1.6
|
||||
|
||||
function requirePositive(value, label) {
|
||||
const number = Number(value);
|
||||
if (!Number.isFinite(number) || number <= 0) {
|
||||
throw new RangeError(label + " ต้องเป็นตัวเลขมากกว่า 0");
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} input
|
||||
* @param {number} input.eto_mm_per_day ค่าอ้างอิงการระเหยของพืช (มม./วัน)
|
||||
* @param {number} input.crop_coefficient สัมประสิทธิ์พืช Kc (พืชอ้างอิง = 1.00)
|
||||
* @param {number} input.area_rai พื้นที่ปลูก (ไร่)
|
||||
* @param {number} input.irrigation_efficiency_percent ประสิทธิภาพการให้น้ำ (%)
|
||||
* @returns {{value:number, unit:string, steps:Array, warnings:string[], details:object}}
|
||||
*/
|
||||
export function calculateCropWaterDemand(input) {
|
||||
const eto = requirePositive(input.eto_mm_per_day, "ETo");
|
||||
const coefficient = requirePositive(input.crop_coefficient, "Kc");
|
||||
const area = requirePositive(input.area_rai, "พื้นที่ปลูก");
|
||||
const efficiency = requirePositive(input.irrigation_efficiency_percent, "ประสิทธิภาพการให้น้ำ");
|
||||
|
||||
if (efficiency > 100) {
|
||||
throw new RangeError("ประสิทธิภาพการให้น้ำต้องไม่เกิน 100%");
|
||||
}
|
||||
|
||||
const etc_mm_per_day = eto * coefficient;
|
||||
const net_m3_per_day = etc_mm_per_day * CUBIC_METRE_PER_MILLIMETRE_PER_RAI * area;
|
||||
const gross_mm_per_day = etc_mm_per_day / (efficiency / 100);
|
||||
const gross_m3_per_day = gross_mm_per_day * CUBIC_METRE_PER_MILLIMETRE_PER_RAI * area;
|
||||
|
||||
const warnings = [];
|
||||
if (coefficient < 0.2 || coefficient > 1.3) {
|
||||
warnings.push("Kc = " + coefficient + " อยู่นอกช่วง 0.2–1.3 ที่พบทั่วไป — ตรวจค่ากับตาราง Kc ของพืชก่อนใช้");
|
||||
}
|
||||
if (efficiency < 40) {
|
||||
warnings.push("ประสิทธิภาพการให้น้ำต่ำกว่า 40% — น้ำที่ต้องสูบจะมากกว่าที่พืชใช้หลายเท่า");
|
||||
}
|
||||
|
||||
const steps = [
|
||||
{ label: "ETo ของพื้นที่/เดือนที่เลือก", value: Number(eto.toFixed(2)), unit: "มม./วัน" },
|
||||
{ label: "ETc = Kc × ETo = " + coefficient + " × " + eto, value: Number(etc_mm_per_day.toFixed(2)), unit: "มม./วัน" },
|
||||
{ label: "1 มม. บน 1 ไร่", value: CUBIC_METRE_PER_MILLIMETRE_PER_RAI, unit: "ลบ.ม." },
|
||||
{
|
||||
label: "ปริมาณน้ำที่พืชใช้ = ETc × 1.6 × " + area,
|
||||
value: Number(net_m3_per_day.toFixed(2)),
|
||||
unit: "ลบ.ม./วัน"
|
||||
},
|
||||
{
|
||||
label: "ปริมาณน้ำที่ต้องให้ = ÷ ประสิทธิภาพ " + efficiency + "%",
|
||||
value: Number(gross_m3_per_day.toFixed(2)),
|
||||
unit: "ลบ.ม./วัน"
|
||||
}
|
||||
];
|
||||
|
||||
return {
|
||||
value: Number(gross_m3_per_day.toFixed(2)),
|
||||
unit: "cubic_metre_per_day",
|
||||
steps,
|
||||
warnings,
|
||||
details: {
|
||||
eto_mm_per_day: Number(eto.toFixed(2)),
|
||||
etc_mm_per_day: Number(etc_mm_per_day.toFixed(2)),
|
||||
net_m3_per_day: Number(net_m3_per_day.toFixed(2)),
|
||||
gross_m3_per_day: Number(gross_m3_per_day.toFixed(2)),
|
||||
gross_m3_per_week: Number((gross_m3_per_day * 7).toFixed(2)),
|
||||
gross_m3_per_month: Number((gross_m3_per_day * 30).toFixed(2))
|
||||
}
|
||||
};
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/* pond.js — ปริมาตรสระน้ำ (เรขาคณิต) + น้ำฝนที่รับได้
|
||||
pure module: ไม่แตะ DOM
|
||||
|
||||
สูตรที่ใช้ (ตรวจย้อนกลับได้):
|
||||
- ปริมาตรทรงสี่เหลี่ยมคางหมู (frustum): V = h/3 × (Aล่าง + Aบน + √(Aล่าง×Aบน))
|
||||
- ความชันข้าง s (แนวนอน ต่อ 1 แนวตั้ง): ด้านล่าง = ด้านบน − 2×s×h
|
||||
- น้ำฝนลงสระ = พื้นที่รับน้ำฝน(ตร.ม.) × ฝน(ม.) × สัมประสิทธิ์น้ำไหลลงสระ
|
||||
*/
|
||||
|
||||
export const RAI_IN_SQUARE_METRE = 1600;
|
||||
|
||||
function requirePositive(value, label) {
|
||||
const number = Number(value);
|
||||
if (!Number.isFinite(number) || number <= 0) {
|
||||
throw new RangeError(label + " ต้องเป็นตัวเลขมากกว่า 0");
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
function requirePercent(value, label) {
|
||||
const number = Number(value);
|
||||
if (!Number.isFinite(number) || number <= 0 || number > 100) {
|
||||
throw new RangeError(label + " ต้องอยู่ระหว่าง 0–100");
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
function frustumVolume(bottomArea, topArea, height) {
|
||||
return (height / 3) * (bottomArea + topArea + Math.sqrt(bottomArea * topArea));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} input
|
||||
* @param {"box"|"trapezoid"} input.shape box = ผนังตั้งฉาก, trapezoid = ผนังลาด
|
||||
* @param {number} input.top_length_m ความยาวปากบ่อ (ม.)
|
||||
* @param {number} input.top_width_m ความกว้างปากบ่อ (ม.)
|
||||
* @param {number} input.depth_m ความลึกบ่อ (ม.)
|
||||
* @param {number} [input.side_slope_horizontal_per_vertical] ความชันผนัง (แนวนอนต่อแนวตั้ง)
|
||||
* @param {number} input.usable_depth_percent ระดับน้ำใช้การ (% ของความลึก)
|
||||
* @param {number} [input.catchment_rai] พื้นที่รับน้ำฝน (ไร่)
|
||||
* @param {number} [input.rainfall_mm] ปริมาณฝนที่ตกในครั้ง/ช่วงที่คิด (มม.)
|
||||
* @param {number} [input.runoff_coefficient] สัมประสิทธิ์น้ำไหลลงสระ (0–1)
|
||||
*/
|
||||
export function calculatePondVolume(input) {
|
||||
const shape = input.shape === "box" ? "box" : "trapezoid";
|
||||
const topLength = requirePositive(input.top_length_m, "ความยาวปากบ่อ");
|
||||
const topWidth = requirePositive(input.top_width_m, "ความกว้างปากบ่อ");
|
||||
const depth = requirePositive(input.depth_m, "ความลึกบ่อ");
|
||||
const slope = shape === "box" ? 0 : Math.max(0, Number(input.side_slope_horizontal_per_vertical) || 0);
|
||||
const usablePercent = requirePercent(input.usable_depth_percent, "ระดับน้ำใช้การ");
|
||||
|
||||
const catchmentRai = Math.max(0, Number(input.catchment_rai) || 0);
|
||||
const rainfallMm = Math.max(0, Number(input.rainfall_mm) || 0);
|
||||
const runoff = Math.min(1, Math.max(0, Number(input.runoff_coefficient ?? 0.8)));
|
||||
|
||||
const bottomLength = topLength - 2 * slope * depth;
|
||||
const bottomWidth = topWidth - 2 * slope * depth;
|
||||
|
||||
if (bottomLength <= 0 || bottomWidth <= 0) {
|
||||
throw new RangeError(
|
||||
"ผนังลาดชันเกินขนาดปากบ่อ: ด้านล่างเหลือ " +
|
||||
bottomLength.toFixed(2) + " × " + bottomWidth.toFixed(2) +
|
||||
" ม. — เพิ่มขนาดปากบ่อ ลดความลึก หรือลดความชันผนัง"
|
||||
);
|
||||
}
|
||||
|
||||
const topArea = topLength * topWidth;
|
||||
const bottomArea = bottomLength * bottomWidth;
|
||||
const excavatedVolume = shape === "box" ? topArea * depth : frustumVolume(bottomArea, topArea, depth);
|
||||
|
||||
/* ปริมาตรน้ำใช้การ = ปริมาตรระหว่างก้นบ่อถึงระดับน้ำใช้การ */
|
||||
const usableDepth = (depth * usablePercent) / 100;
|
||||
const levelLength = bottomLength + 2 * slope * usableDepth;
|
||||
const levelWidth = bottomWidth + 2 * slope * usableDepth;
|
||||
const levelArea = levelLength * levelWidth;
|
||||
const usableVolume = shape === "box"
|
||||
? bottomArea * usableDepth
|
||||
: frustumVolume(bottomArea, levelArea, usableDepth);
|
||||
|
||||
const rainHarvestM3 = catchmentRai * RAI_IN_SQUARE_METRE * (rainfallMm / 1000) * runoff;
|
||||
const totalAvailable = usableVolume + rainHarvestM3;
|
||||
|
||||
const warnings = [];
|
||||
if (usablePercent < 50) {
|
||||
warnings.push("ระดับน้ำใช้การเหลือ " + usablePercent + "% — น้ำส่วนล่างจะระเหย/รั่วซึมง่าย");
|
||||
}
|
||||
if (shape === "box" && depth > 4) {
|
||||
warnings.push("ผนังตั้งฉากลึกเกิน 4 ม. เสี่ยงดินถล่ม — ควรลาดผนัง (trapezoid)");
|
||||
}
|
||||
if (rainfallMm > 0 && catchmentRai === 0) {
|
||||
warnings.push("ใส่พื้นที่รับน้ำฝนเป็น 0 — น้ำฝนที่คำนวณได้จึงเป็น 0");
|
||||
}
|
||||
|
||||
const steps = [
|
||||
{ label: "พื้นที่ปากบ่อ", value: Number(topArea.toFixed(2)), unit: "ตร.ม." },
|
||||
{ label: "พื้นที่ก้นบ่อ", value: Number(bottomArea.toFixed(2)), unit: "ตร.ม." },
|
||||
{ label: "ปริมาตรขุดทั้งหมด", value: Number(excavatedVolume.toFixed(2)), unit: "ลบ.ม." },
|
||||
{
|
||||
label: "ระดับน้ำใช้การ " + usablePercent + "% = " + usableDepth.toFixed(2) + " ม.",
|
||||
value: Number(usableVolume.toFixed(2)),
|
||||
unit: "ลบ.ม."
|
||||
},
|
||||
{
|
||||
label: "น้ำฝนลงสระ = " + catchmentRai + " ไร่ × " + rainfallMm + " มม. × " + runoff,
|
||||
value: Number(rainHarvestM3.toFixed(2)),
|
||||
unit: "ลบ.ม."
|
||||
}
|
||||
];
|
||||
|
||||
return {
|
||||
value: Number(totalAvailable.toFixed(2)),
|
||||
unit: "cubic_metre",
|
||||
steps,
|
||||
warnings,
|
||||
details: {
|
||||
excavated_volume_m3: Number(excavatedVolume.toFixed(2)),
|
||||
usable_volume_m3: Number(usableVolume.toFixed(2)),
|
||||
rain_harvest_m3: Number(rainHarvestM3.toFixed(2)),
|
||||
total_available_m3: Number(totalAvailable.toFixed(2)),
|
||||
bottom_length_m: Number(bottomLength.toFixed(2)),
|
||||
bottom_width_m: Number(bottomWidth.toFixed(2)),
|
||||
usable_depth_m: Number(usableDepth.toFixed(2))
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user