import React, { useState, useEffect, useMemo } from 'react'; import { Plus, Trash2, Calculator, ArrowRight, Zap, Wind, TrendingUp, DollarSign, Info, AlertTriangle, Clock, User, MapPin, Calendar } from 'lucide-react'; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, Cell } from 'recharts'; // --- CONSTANTS & HELPERS --- const HP_TO_KW = 0.7457; const kwToHp = (kw: number) => parseFloat((kw / HP_TO_KW).toFixed(1)); const hpToKw = (hp: number) => parseFloat((hp * HP_TO_KW).toFixed(2)); // CẤU HÌNH GIÁ ĐIỆN SẢN XUẤT (Cập nhật mới nhất) const ELECTRICITY_RATES = { voltageLevel1: { // Dưới 6 kV normal: 1896, offPeak: 1241, peak: 3474 }, voltageLevel2: { // 6kV - 22kV normal: 1812, offPeak: 1178, peak: 3348 }, voltageLevel3: { // 22kV - 110kV (Farm rất lớn) normal: 1749, offPeak: 1136, peak: 3242 } }; const calculateWeightedPrice = (rates: typeof ELECTRICITY_RATES.voltageLevel1) => { const peakHoursPerWeek = 5 * 6; const offPeakHoursPerWeek = 6 * 7; const normalHoursPerWeek = 168 - peakHoursPerWeek - offPeakHoursPerWeek; const totalCostPerWeek = (peakHoursPerWeek * rates.peak) + (offPeakHoursPerWeek * rates.offPeak) + (normalHoursPerWeek * rates.normal); return totalCostPerWeek / 168; }; // Dữ liệu ước tính cho máy Roots Blower (BS Series) và Bi Gốm const MACHINE_DATA: Record = { 'BS 65': { baseFlow: 2.7, baseKw: 2.2 }, // ~3HP 'BS 80': { baseFlow: 5.2, baseKw: 4.0 }, // ~5.5HP 'BS 100': { baseFlow: 8.5, baseKw: 7.5 }, // ~10HP 'BS 125': { baseFlow: 14.5, baseKw: 11 }, // ~15HP 'BS 150': { baseFlow: 22.0, baseKw: 15 }, // ~20HP 'BS 200': { baseFlow: 40.0, baseKw: 30 }, // ~40HP 'BS 250': { baseFlow: 60.0, baseKw: 45 }, // ~60HP 'Vòng bi gốm': { baseFlow: 24.0, baseKw: 15 }, // ~20HP }; const PRESSURE_OPTIONS = [20, 25, 30, 35]; // Thông số Dolic làm chuẩn so sánh const DOLIC_SPECS: Record> = { 15: { 20: 38, 25: 36, 30: 34, 35: 30 }, 18: { 35: 26 } }; export default function DolicAnalyzer() { // --- STATE --- const [pressure, setPressure] = useState(30); const [voltageLevel, setVoltageLevel] = useState('voltageLevel1'); // Customer Info State const [customerInfo, setCustomerInfo] = useState({ name: '', address: '', date: new Date().toLocaleDateString('vi-VN') }); const averageElectricityPrice = useMemo(() => { return calculateWeightedPrice(ELECTRICITY_RATES[voltageLevel]); }, [voltageLevel]); const [farmMachines, setFarmMachines] = useState([ { id: 1, type: 'BS 150', quantity: 1, powerHP: 20, powerKw: 15 } ]); const [activeTab, setActiveTab] = useState('input'); // --- HANDLERS --- const handleCustomerChange = (field: string, value: string) => { setCustomerInfo(prev => ({ ...prev, [field]: value })); }; const addMachine = () => { const newId = farmMachines.length > 0 ? Math.max(...farmMachines.map(m => m.id)) + 1 : 1; setFarmMachines([...farmMachines, { id: newId, type: 'BS 150', quantity: 1, powerHP: 20, powerKw: 15 }]); }; const removeMachine = (id: number) => { setFarmMachines(farmMachines.filter(m => m.id !== id)); }; const updateMachine = (id: number, field: string, value: any) => { setFarmMachines(farmMachines.map(m => { if (m.id === id) { let updated = { ...m, [field]: value }; if (field === 'type') { const baseKw = MACHINE_DATA[value].baseKw; updated.powerKw = baseKw; updated.powerHP = kwToHp(baseKw); } else if (field === 'powerHP') { updated.powerKw = hpToKw(value); } return updated; } return m; })); }; // --- CALCULATIONS --- // 1. Tính toán hệ thống hiện tại const currentSystemStats = useMemo(() => { let totalKw = 0; let totalFlow = 0; farmMachines.forEach(m => { totalKw += Number(m.powerKw) * Number(m.quantity); let flowFactor = 1; if (pressure === 20) flowFactor = 1.1; if (pressure === 25) flowFactor = 1.05; if (pressure === 35) flowFactor = 0.95; const baseFlow = MACHINE_DATA[m.type]?.baseFlow || 0; totalFlow += baseFlow * flowFactor * Number(m.quantity); }); const efficiency = totalKw > 0 ? totalFlow / totalKw * 60 : 0; return { totalKw, totalFlow, efficiency }; }, [farmMachines, pressure]); // 2. Tính toán giải pháp Dolic 15kW thay thế const dolicSolution = useMemo(() => { const dolicFlowPerUnit = DOLIC_SPECS[15][pressure] || 34; const dolicPowerPerUnit = 15; // Dolic 15kW cố định const unitsNeeded = currentSystemStats.totalFlow / dolicFlowPerUnit; const totalDolicKw = unitsNeeded * dolicPowerPerUnit; // Tổng lưu lượng khí của hệ thống Dolic đề xuất (m3/phút) // = Số lượng máy * Lưu lượng mỗi máy const totalDolicFlow = unitsNeeded * dolicFlowPerUnit; const dolicEfficiency = (dolicFlowPerUnit * 60) / dolicPowerPerUnit; const kwSavedPerHour = currentSystemStats.totalKw - totalDolicKw; const moneyLostPerHour = kwSavedPerHour * averageElectricityPrice; const moneyLostPerDay = moneyLostPerHour * 24; const moneyLostPerMonth = moneyLostPerDay * 30; const moneySavedPerYear = moneyLostPerDay * 270; return { flowPerUnit: dolicFlowPerUnit, powerPerUnit: dolicPowerPerUnit, unitsNeeded, totalKw: totalDolicKw, totalFlow: totalDolicFlow, // Thêm trường này efficiency: dolicEfficiency, kwSavedPerHour, moneyLostPerDay, moneyLostPerMonth, moneySavedPerYear }; }, [currentSystemStats, pressure, averageElectricityPrice]); // Chart Data const chartData = [ { name: 'Hệ thống cũ', 'Hiệu suất (m³ khí / 1 kWh điện)': parseFloat((currentSystemStats.totalFlow * 60 / currentSystemStats.totalKw).toFixed(1)), color: '#94a3b8' }, { name: 'Dolic 15kW', 'Hiệu suất (m³ khí / 1 kWh điện)': parseFloat(dolicSolution.efficiency.toFixed(1)), color: '#0ea5e9' } ]; const formatCurrency = (value: number) => { return new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(value); }; return (
{/* Header */}

DOLIC Performance Analyzer

Công cụ so sánh hiệu năng máy nén khí cho trại nuôi

Phiên bản so sánh Dolic DL15 (15kW)
Giá điện tích hợp 3 khung giờ
{/* Tab Selection (Mobile friendly) */}
{/* LEFT PANEL: INPUT */}
{/* Customer Info Section */}

Thông tin khách hàng

handleCustomerChange('name', e.target.value)} />
handleCustomerChange('address', e.target.value)} />
Ngày phân tích:
{customerInfo.date}

Cấu hình Farm hiện tại

{/* Global Settings */}
{/* Voltage Level Selection */}
TB: {formatCurrency(averageElectricityPrice).replace('₫', '')}/kWh Đã tính tỷ lệ 3 khung giờ
{/* Pressure Selection */}
{PRESSURE_OPTIONS.map(p => ( ))}
{/* Machines List */}
{farmMachines.map((machine, index) => (
{index + 1}
updateMachine(machine.id, 'quantity', parseInt(e.target.value) || 0)} />
updateMachine(machine.id, 'powerHP', parseFloat(e.target.value) || 0)} /> {/* Display converted kW */}
≈ {machine.powerKw} kW
))}
{/* Total Summary Mini */}
Tổng điện tiêu thụ: {currentSystemStats.totalKw.toFixed(1)} kW
Tổng khí (ước tính): {currentSystemStats.totalFlow.toFixed(1)} m³/phút
{/* RIGHT PANEL: ANALYSIS */}
{/* Header Report for Screenshot */} {customerInfo.name && (

Báo cáo hiệu quả năng lượng

Khách hàng: {customerInfo.name} {customerInfo.address && - {customerInfo.address}}
)}

Phân tích hiệu quả chuyển đổi

{/* Main Stats Comparison */}
{/* Current */}
Hiện trạng (Cũ)
{(currentSystemStats.totalFlow * 60 / currentSystemStats.totalKw || 0).toFixed(1)} m³/kWh
Hiệu suất sinh khí
Tiêu thụ: {currentSystemStats.totalKw.toFixed(1)} kWh
Tổng khí: {currentSystemStats.totalFlow.toFixed(1)} m³/phút
{/* New Dolic */}
KHUYÊN DÙNG
Hệ thống Dolic 15kW
{dolicSolution.efficiency.toFixed(1)} m³/kWh
Hiệu suất sinh khí
Tiêu thụ: {dolicSolution.totalKw.toFixed(1)} kWh
Tổng khí: {dolicSolution.totalFlow.toFixed(1)} m³/phút
{/* Money Calculation Detailed */}

Dự tính hiệu quả kinh tế

{/* 1. Mất oan mỗi ngày */}
Tiền mất oan / Ngày
{dolicSolution.moneyLostPerDay > 0 ? formatCurrency(dolicSolution.moneyLostPerDay) : '0 ₫'}
Lãng phí do dùng máy cũ
{/* 2. Mất oan mỗi tháng */}
Tiền mất oan / Tháng
{dolicSolution.moneyLostPerMonth > 0 ? formatCurrency(dolicSolution.moneyLostPerMonth) : '0 ₫'}
Lãng phí tích lũy 30 ngày
{/* 3. Tiết kiệm 1 năm - Hero Metric */}
Tiết kiệm được / 1 Năm
{dolicSolution.moneySavedPerYear > 0 ? formatCurrency(dolicSolution.moneySavedPerYear) : '0 ₫'}
Tính cho 3 vụ nuôi (270 ngày)
{/* Additional Context */}
Số máy Dolic cần đầu tư {dolicSolution.unitsNeeded.toFixed(1)} máy
Giá điện TB (24/7) {formatCurrency(averageElectricityPrice)}/kWh
{dolicSolution.moneySavedPerYear > 0 && (
"Số tiền này đủ để anh mua thêm {(dolicSolution.moneySavedPerYear / 20000000).toFixed(0)} tấn thức ăn!"
)}
{/* Chart */}

Biểu đồ so sánh lượng khí tạo ra từ 1 kWh điện

{chartData.map((entry, index) => ( ))}
{/* Footer Note */}

Kết quả tính toán dựa trên thông số kỹ thuật chuẩn của máy Dolic DL15 (34m³/min @ 30kPa) và dữ liệu trung bình của các dòng máy Roots/Bi gốm trên thị trường. Giá điện được tính theo giá trung bình của chu kỳ 24h (bao gồm Giờ Bình thường, Cao điểm và Thấp điểm) theo quy định EVN.

); }