Mengapa perhitungan di dalam script berikut tidak sesuai dengan perhitungan manual?

package com.example.rectifiercalculator

import android.content.Intent import android.os.Bundle import android.widget.Button import android.widget.EditText import android.widget.TextView import android.widget.Toast import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import org.w3c.dom.Text import kotlin.math.roundToInt import java.math.BigDecimal import java.math.RoundingMode

class AuditPowerActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_audit_power)

    // Retrieve phase type from intent
    val phaseType = intent.getIntExtra("PHASE_TYPE", 0)
    val tvPhaseTypeAudit = findViewById<TextView>(R.id.tvPhaseTypeAudit)

    // Display phase type
    tvPhaseTypeAudit.text = if (phaseType == 1) "Phase Type: 1 Phasa" else "Phase Type: 3 Phasa"

    // Input fields
    val etCapMCBPLN = findViewById<EditText>(R.id.etCapMCBPLN)
    val etLoadCurrent = findViewById<EditText>(R.id.etLoadCurrent)
    val etVoltageFloat = findViewById<EditText>(R.id.etVoltageFloat)
    val etTotalBatteryCapacity = findViewById<EditText>(R.id.etTotalBatteryCapacity)
    val etBatteryCurrentLimit = findViewById<EditText>(R.id.etBatteryCurrentLimit)
    val etVoltRn = findViewById<EditText>(R.id.etVoltRn)
    val etVoltSn = findViewById<EditText>(R.id.etVoltSn)
    val etVoltTn = findViewById<EditText>(R.id.etVoltTn)
    val etQtyRectifierModuleR = findViewById<EditText>(R.id.etQtyRectifierModuleR)
    val etQtyRectifierModuleS = findViewById<EditText>(R.id.etQtyRectifierModuleS)
    val etQtyRectifierModuleT = findViewById<EditText>(R.id.etQtyRectifierModuleT)
    val etCosPhi = findViewById<EditText>(R.id.etCosPhi)
    val etRectifierEfficiency = findViewById<EditText>(R.id.etRectifierEfficiency)
    val etTotalLoadNonRectifierPhasaR = findViewById<EditText>(R.id.etTotalLoadNonRectifierPhasaR)
    val etTotalLoadNonRectifierPhasaS = findViewById<EditText>(R.id.etTotalLoadNonRectifierPhasaS)
    val etTotalLoadNonRectifierPhasaT = findViewById<EditText>(R.id.etTotalLoadNonRectifierPhasaT)
    val btnCalculateAudit = findViewById<Button>(R.id.btnCalculateAudit)

    btnCalculateAudit.setOnClickListener {
        try {
            // Validate and parse inputs
            val capMCBPLN = etCapMCBPLN.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Cap MCB PLN harus diisi!")
            val loadCurrent = etLoadCurrent.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Load Current harus diisi!")
            val voltageFloat = etVoltageFloat.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Voltage Float harus diisi!")
            val totalBatteryCapacity = etTotalBatteryCapacity.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Total Battery Capacity harus diisi!")
            val batteryCurrentLimit = etBatteryCurrentLimit.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Battery Current Limit harus diisi!")
            val voltRn = etVoltRn.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Tegangan R-N harus diisi!")
            val voltSn = etVoltSn.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Tegangan S-N harus diisi!")
            val voltTn = etVoltTn.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Tegangan T-N harus diisi!")
            val qtyRectifierModuleR = etQtyRectifierModuleR.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Jumlah Rectifier Module R harus diisi!")
            val qtyRectifierModuleS = etQtyRectifierModuleS.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Jumlah Rectifier Module S harus diisi!")
            val qtyRectifierModuleT = etQtyRectifierModuleT.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Jumlah Rectifier Module T harus diisi!")
            val cosPhi = etCosPhi.text.toString().toDoubleOrNull() ?: throw IllegalArgumentException("Cos φ harus diisi!")
            val rectifierEfficiency = etRectifierEfficiency.text.toString().toDoubleOrNull()?.div(100) ?: throw IllegalArgumentException("Rectifier Efficiency harus diisi!")
            val totalLoadNonRectifierR = etTotalLoadNonRectifierPhasaR.text.toString().toDoubleOrNull() ?: 0.0
            val totalLoadNonRectifierS = etTotalLoadNonRectifierPhasaS.text.toString().toDoubleOrNull() ?: 0.0
            val totalLoadNonRectifierT = etTotalLoadNonRectifierPhasaT.text.toString().toDoubleOrNull() ?: 0.0

            // Calculations
            val totalModules = qtyRectifierModuleR + qtyRectifierModuleS + qtyRectifierModuleT
            val dayaTanpaCharging = (((((loadCurrent / totalModules) + 1.5) * totalModules) * voltageFloat) / rectifierEfficiency / cosPhi).toInt()
            val dayaChargingBattery = ((((((loadCurrent + (batteryCurrentLimit / 100 * totalBatteryCapacity)) / totalModules) + 1.5) * totalModules) * voltageFloat) / (rectifierEfficiency * cosPhi)).toInt()
            val totalCurrentR = (((((((loadCurrent + (batteryCurrentLimit / 100 * totalBatteryCapacity)) / totalModules) + 1.5) * qtyRectifierModuleR) * voltageFloat) / (rectifierEfficiency * cosPhi)) / voltRn + totalLoadNonRectifierR).toInt()
            val totalCurrentS = (((((((loadCurrent + (batteryCurrentLimit / 100 * totalBatteryCapacity)) / totalModules) + 1.5) * qtyRectifierModuleS) * voltageFloat) / (rectifierEfficiency * cosPhi)) / voltSn + totalLoadNonRectifierS).toInt()
            val totalCurrentT = (((((((loadCurrent + (batteryCurrentLimit / 100 * totalBatteryCapacity)) / totalModules) + 1.5) * qtyRectifierModuleT) * voltageFloat) / (rectifierEfficiency * cosPhi)) / voltTn + totalLoadNonRectifierT).toInt()
            val occMCBPhaseR = (totalCurrentR / capMCBPLN).roundToInt()
            val occMCBPhaseS = (totalCurrentS / capMCBPLN).roundToInt()
            val occMCBPhaseT = (totalCurrentT / capMCBPLN).roundToInt()
            val dayaTotalGabungan = dayaTanpaCharging + dayaChargingBattery

            // Determine OK or OVERLOAD
            val statusR = if (occMCBPhaseR <= 100) "OK" else "OVERLOAD"
            val statusS = if (occMCBPhaseS <= 100) "OK" else "OVERLOAD"
            val statusT = if (occMCBPhaseT <= 100) "OK" else "OVERLOAD"

            // Build result text
            val resultText = if (phaseType == 1) {
                """
                1 Phasa Results:
                Daya Tanpa Charging Battery: $dayaTanpaCharging Watt
                Daya + Charging Battery: $dayaTotalGabungan Watt
                Total Current Phase R: $totalCurrentR A AC
                Occ MCB Phase R: $occMCBPhaseR % $statusR
                """.trimIndent()
                    } else {
                        """
                3 Phasa Results:
                Daya Tanpa Charging Battery: $dayaTanpaCharging Watt
                Daya + Charging Battery: $dayaTotalGabungan Watt
                Total Current Phase R: $totalCurrentR A AC
                Total Current Phase S: $totalCurrentS A AC
                Total Current Phase T: $totalCurrentT A AC
                Occ MCB Phase R: $occMCBPhaseR % $statusR
                Occ MCB Phase S: $occMCBPhaseS % $statusS
                Occ MCB Phase T: $occMCBPhaseT % $statusT
                """.trimIndent()
            }

            // Navigate to result activity
            val intent = Intent(this, AuditResultActivity::class.java)
            intent.putExtra("RESULT_TEXT", resultText)
            startActivity(intent)

        } catch (e: Exception) {
            Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
        }
    }
}

}

avatar Shelll9
@Shelll9

1 Kontribusi 0 Poin

Diperbarui 5 hari yang lalu

1 Jawaban:

  1. Cek Input Data Pastikan semua input data yang diperlukan diisi dengan benar. Misalnya:

Apakah semua EditText diisi dengan angka valid? Apakah format input (misalnya, titik atau koma) sudah benar sesuai dengan yang diharapkan? 2. Cek Rumus Perhitungan Mari kita analisis rumus-rumus yang ada di kode. Kita fokus pada beberapa rumus utama:

val dayaTanpaCharging = (((((loadCurrent / totalModules) + 1.5) * totalModules) * voltageFloat) / rectifierEfficiency / cosPhi).toInt()

val dayaChargingBattery = ((((((loadCurrent + (batteryCurrentLimit / 100 * totalBatteryCapacity)) / totalModules) + 1.5) * totalModules) * voltageFloat) / (rectifierEfficiency * cosPhi)).toInt()

val totalCurrentR = (((((((loadCurrent + (batteryCurrentLimit / 100 * totalBatteryCapacity)) / totalModules) + 1.5) * qtyRectifierModuleR) * voltageFloat) / (rectifierEfficiency * cosPhi)) / voltRn + totalLoadNonRectifierR).toInt() 3. Uji Coba Perhitungan Manual Mari kita coba membuat satu contoh dengan input tertentu, dan kita hitung manual sesuai rumus dengan hasil dari kode tersebut.

Misalnya, Coba Input Ini: Cap MCB PLN: 10 Load Current: 20 Voltage Float: 12 Total Battery Capacity: 100 Battery Current Limit: 40 Volt R-N: 5 Volt S-N: 5 Volt T-N: 5 Jumlah Rectifier Module R/S/T: 2 Cos φ: 0,9 Rectifier Efficiency: 90% Total Load Non Rectifier R/S/T: 0 (misalkan) 4. Hitung Manual Berdasarkan Input di Atas totalModules: 2 + 2 + 2 = 6 Hitung dayaTanpaCharging dan dayaChargingBattery Hitung totalCurrentR berdasarkan rumus Karena lo udah tau cara menghitung sesuai rumus, coba hitung manual dan bandingkan dengan hasil dari aplikasi.

  1. Debugging Jika udah mencoba di atas dan masih ga cocok, tambahkan log di setiap langkah perhitungan untuk melihat value dari setiap variabel. Contohnya:

Log.d("Debug", "Load Current: $loadCurrent") Log.d("Debug", "Total Modules: $totalModules") Log.d("Debug", "Daya Tanpa Charging: $dayaTanpaCharging")

avatar adamajalah27
@adamajalah27

120 Kontribusi 40 Poin

Dipost 5 hari yang lalu

Login untuk ikut Jawaban