200 lines
8.6 KiB
HTML
200 lines
8.6 KiB
HTML
<div class="container page">
|
|
<h1 class="page-title">น้ำที่พืชต้องการ</h1>
|
|
<p class="page-lead">
|
|
คำนวณจาก ETo รายจังหวัด (วิธี Penman-Monteith) × ค่าสัมประสิทธิ์พืช (Kc) ของคุณ
|
|
→ ปริมาณน้ำที่พืชใช้ และปริมาณน้ำที่ต้องสูบจริงเมื่อคิดประสิทธิภาพการให้น้ำ
|
|
</p>
|
|
|
|
<form id="cw-form" class="calc" novalidate>
|
|
<div class="field">
|
|
<label for="cw-region">ภาค</label>
|
|
<select id="cw-region"></select>
|
|
</div>
|
|
<div class="field">
|
|
<label for="cw-province">จังหวัด</label>
|
|
<select id="cw-province"></select>
|
|
<span class="hint">แสดงเฉพาะจังหวัดที่มีข้อมูล ETo ในคลังข้อมูล</span>
|
|
</div>
|
|
<div class="field">
|
|
<label for="cw-month">เดือน</label>
|
|
<select id="cw-month"></select>
|
|
</div>
|
|
<div class="field">
|
|
<label for="cw-kc">ค่า Kc ของพืช</label>
|
|
<input id="cw-kc" type="number" inputmode="decimal" step="0.01" min="0.05" max="2" value="1.00">
|
|
<span class="hint">พืชอ้างอิง = 1.00 · ยังไม่มีตาราง Kc ในเว็บ (ไฟล์เดิมเสีย) — ใส่ค่าจากเอกสารของคุณ</span>
|
|
</div>
|
|
<div class="field">
|
|
<label for="cw-area">พื้นที่ปลูก (ไร่)</label>
|
|
<input id="cw-area" type="number" inputmode="decimal" step="0.1" min="0.1" value="10">
|
|
</div>
|
|
<div class="field">
|
|
<label for="cw-eff">ประสิทธิภาพการให้น้ำ (%)</label>
|
|
<input id="cw-eff" type="number" inputmode="decimal" step="1" min="10" max="100" value="75">
|
|
<span class="hint">สปริงเกลอร์ ~75 · น้ำหยด ~85–90 · รดด้วยสายยาง ~50</span>
|
|
</div>
|
|
<div class="calc-actions field--wide">
|
|
<button type="submit">คำนวณ</button>
|
|
<button type="button" class="ghost" id="cw-reset">ค่าเริ่มต้น</button>
|
|
</div>
|
|
</form>
|
|
|
|
<section class="result" id="cw-result" hidden aria-live="polite">
|
|
<div>
|
|
<span class="result-value" id="cw-value">—</span>
|
|
<span class="result-unit">ลบ.ม./วัน (น้ำที่ต้องให้จริง)</span>
|
|
</div>
|
|
<div class="result-grid">
|
|
<div class="result-item">ETo ที่เลือก <b id="cw-eto">—</b>มม./วัน</div>
|
|
<div class="result-item">ETc (พืชใช้จริง) <b id="cw-etc">—</b>มม./วัน</div>
|
|
<div class="result-item">น้ำที่พืชใช้ <b id="cw-net">—</b>ลบ.ม./วัน</div>
|
|
<div class="result-item">ต่อสัปดาห์ <b id="cw-week">—</b>ลบ.ม.</div>
|
|
<div class="result-item">ต่อเดือน (30 วัน) <b id="cw-month-total">—</b>ลบ.ม.</div>
|
|
<div class="result-item">1 มม. บน 1 ไร่ <b>1.60</b>ลบ.ม.</div>
|
|
</div>
|
|
<ul class="warn-list" id="cw-warnings" hidden></ul>
|
|
<table class="steps" id="cw-steps">
|
|
<thead>
|
|
<tr>
|
|
<th>ขั้นตอน</th>
|
|
<th>ค่า</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</section>
|
|
|
|
<p class="note">
|
|
ที่มาข้อมูล: <code>data/climate/eto_by_region.json</code> (116 จังหวัด ที่มีข้อมูลในต้นฉบับ)
|
|
· สูตรอยู่ใน <code>core/crop_water.js</code> และมี unit test ที่ <code>tests/</code>
|
|
· ยังไม่คิดน้ำฝนใช้ได้ (effective rainfall) และการระเหยจากผิวดิน — จะเพิ่มในรุ่นถัดไป
|
|
</p>
|
|
</div>
|
|
|
|
<script type="module">
|
|
import { calculateCropWaterDemand } from './core/crop_water.js';
|
|
|
|
const MONTHS = [
|
|
["january", "มกราคม"], ["february", "กุมภาพันธ์"], ["march", "มีนาคม"],
|
|
["april", "เมษายน"], ["may", "พฤษภาคม"], ["june", "มิถุนายน"],
|
|
["july", "กรกฎาคม"], ["august", "สิงหาคม"], ["september", "กันยายน"],
|
|
["october", "ตุลาคม"], ["november", "พฤศจิกายน"], ["december", "ธันวาคม"]
|
|
];
|
|
|
|
const $ = (id) => document.getElementById(id);
|
|
const regionSelect = $('cw-region');
|
|
const provinceSelect = $('cw-province');
|
|
const monthSelect = $('cw-month');
|
|
const form = $('cw-form');
|
|
const result = $('cw-result');
|
|
|
|
let DATA = null;
|
|
|
|
function fillMonths() {
|
|
monthSelect.innerHTML = MONTHS
|
|
.map(([key, label]) => `<option value="${key}">${label}</option>`)
|
|
.join('');
|
|
const currentMonth = MONTHS[new Date().getMonth()][0];
|
|
monthSelect.value = currentMonth;
|
|
}
|
|
|
|
function currentRegion() {
|
|
return DATA.regions.find((item) => item.region_id === regionSelect.value);
|
|
}
|
|
|
|
function fillProvinces() {
|
|
const region = currentRegion();
|
|
provinceSelect.innerHTML = region.provinces
|
|
.map((item) => `<option value="${item.province_name_th}">${item.province_name_th}</option>`)
|
|
.join('');
|
|
}
|
|
|
|
function findEto(provinceName, monthKey) {
|
|
for (const region of DATA.regions) {
|
|
const province = region.provinces.find((item) => item.province_name_th === provinceName);
|
|
if (province) return province.monthly_eto_mm_per_day[monthKey];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function render(outcome) {
|
|
result.hidden = false;
|
|
$('cw-value').textContent = outcome.value.toFixed(2);
|
|
$('cw-eto').textContent = outcome.details.eto_mm_per_day.toFixed(2) + ' ';
|
|
$('cw-etc').textContent = outcome.details.etc_mm_per_day.toFixed(2) + ' ';
|
|
$('cw-net').textContent = outcome.details.net_m3_per_day.toFixed(2) + ' ';
|
|
$('cw-week').textContent = outcome.details.gross_m3_per_week.toFixed(2) + ' ';
|
|
$('cw-month-total').textContent = outcome.details.gross_m3_per_month.toFixed(2) + ' ';
|
|
|
|
const list = $('cw-warnings');
|
|
list.innerHTML = outcome.warnings.map((text) => `<li>${text}</li>`).join('');
|
|
list.hidden = outcome.warnings.length === 0;
|
|
|
|
$('cw-steps').querySelector('tbody').innerHTML = outcome.steps
|
|
.map((step) => `<tr><td>${step.label}</td><td>${step.value} ${step.unit}</td></tr>`)
|
|
.join('');
|
|
}
|
|
|
|
function showError(message) {
|
|
result.hidden = false;
|
|
$('cw-value').textContent = '—';
|
|
const list = $('cw-warnings');
|
|
list.innerHTML = `<li>${message}</li>`;
|
|
list.hidden = false;
|
|
}
|
|
|
|
function run() {
|
|
if (!DATA) return;
|
|
const eto = findEto(provinceSelect.value, monthSelect.value);
|
|
if (eto === null || eto === undefined) {
|
|
showError('จังหวัดนี้ไม่มีค่า ETo ของเดือนที่เลือกในคลังข้อมูล');
|
|
return;
|
|
}
|
|
try {
|
|
const outcome = calculateCropWaterDemand({
|
|
eto_mm_per_day: eto,
|
|
crop_coefficient: $('cw-kc').value,
|
|
area_rai: $('cw-area').value,
|
|
irrigation_efficiency_percent: $('cw-eff').value
|
|
});
|
|
render(outcome);
|
|
} catch (error) {
|
|
showError(error.message);
|
|
}
|
|
}
|
|
|
|
$('cw-reset').addEventListener('click', () => {
|
|
$('cw-kc').value = '1.00';
|
|
$('cw-area').value = '10';
|
|
$('cw-eff').value = '75';
|
|
fillMonths();
|
|
run();
|
|
});
|
|
|
|
form.addEventListener('submit', (event) => {
|
|
event.preventDefault();
|
|
run();
|
|
});
|
|
regionSelect.addEventListener('change', () => {
|
|
fillProvinces();
|
|
run();
|
|
});
|
|
[provinceSelect, monthSelect].forEach((el) => el.addEventListener('change', run));
|
|
|
|
fetch('data/climate/eto_by_region.json', { cache: 'no-store' })
|
|
.then((response) => {
|
|
if (!response.ok) throw new Error('HTTP ' + response.status);
|
|
return response.json();
|
|
})
|
|
.then((data) => {
|
|
DATA = data;
|
|
regionSelect.innerHTML = data.regions
|
|
.map((region) => `<option value="${region.region_id}">${region.region_name_th}</option>`)
|
|
.join('');
|
|
fillMonths();
|
|
fillProvinces();
|
|
run();
|
|
})
|
|
.catch(() => showError('โหลดคลังข้อมูล ETo ไม่ได้ (ถ้าออฟไลน์ ให้เปิดหน้านี้ตอนออนไลน์ก่อนหนึ่งครั้ง)'));
|
|
</script>
|