diff --git a/app/src/main/java/com/example/refactoredapp/domain/ResultCalculationWithFirstImpl.kt b/app/src/main/java/com/example/refactoredapp/domain/ResultCalculationWithFirstImpl.kt new file mode 100644 index 0000000..4b118df --- /dev/null +++ b/app/src/main/java/com/example/refactoredapp/domain/ResultCalculationWithFirstImpl.kt @@ -0,0 +1,101 @@ +package com.example.refactoredapp.domain + +import android.util.Log +import com.example.refactoredapp.data.constant.Constants +import com.example.refactoredapp.data.model.TestRightResultType +import kotlin.math.log10 + +class ResultCalculationWithFirstImpl { + + private val TAG = "Testright" + + fun getResults( + wavelengthToPixelArray: ArrayList>, + intensityReferenceArray: ArrayList>, + intensitySampleArray: ArrayList> + ) : TestRightResultType { + var pixelNoWithWave_427 = 0 + var pixelNoWithWave_555 = 0 + + Log.d(TAG, "wavelengthToPixelArray size = ${wavelengthToPixelArray.size}") +// println("wavelengthToPixelArray size = ${wavelengthToPixelArray.size}") + for (each in wavelengthToPixelArray) { + var diff = each[0] - 427 + if (pixelNoWithWave_427 == 0 && diff >= 0 && diff < 1) { + pixelNoWithWave_427 = each[1].toInt() + } + + diff = each[0] - 555 + if (pixelNoWithWave_555 == 0 && diff >= 0 && diff < 1) { + pixelNoWithWave_555 = each[1].toInt() + } + + if (pixelNoWithWave_427 != 0 && pixelNoWithWave_555 != 0) { + break + } + } + + Log.d(TAG, "pixelOfInterest_427 = ${pixelNoWithWave_427}") + Log.d(TAG, "pixelOfInterest_555 = ${pixelNoWithWave_555}") + +// println("pixelOfInterest_427 = ${pixelNoWithWave_427}") +// println("pixelOfInterest_555 = ${pixelNoWithWave_555}") + + val invertedPixel_427 = (Constants.TEST_RIGHT_TOTAL_PIXEL + 1) - pixelNoWithWave_427 + val invertedPixel_555 = (Constants.TEST_RIGHT_TOTAL_PIXEL + 1) - pixelNoWithWave_555 + + var io_427 = 0.0 + var io_555 = 0.0 + + for (each in intensityReferenceArray) { + if (each[0].toInt() == invertedPixel_427) { + io_427 = each[1] + } + if (each[0].toInt() == invertedPixel_555) { + io_555 = each[1] + } + } + Log.d(TAG, "I0 values are I0_427 = $io_427 , IO_555 = $io_555") +// println("I0 values are I0_427 = $io_427 , IO_555 = $io_555") + + var i_427 = 0.0 + var i_555 = 0.0 + + for (each in intensitySampleArray) { + if (each[0].toInt() == invertedPixel_427) { + i_427 = each[1] + } + if (each[0].toInt() == invertedPixel_555) { + i_555 = each[1] + } + } + Log.d(TAG, "I values are I_427 = $i_427 , I_555 = $i_555") +// println("I values are I_427 = $i_427 , I_555 = $i_555") + + val absorbanceAtPixelWithWave_427 = log10(io_427 / i_427) + val absorbanceAtPixelWithWave_555 = log10(io_555 / i_555) + Log.d( + TAG, + "absorbance values are for 427 = $absorbanceAtPixelWithWave_427 , for 555 = $absorbanceAtPixelWithWave_555" + ) +// println("absorbance values are for 427 = $absorbanceAtPixelWithWave_427 , for 555 = $absorbanceAtPixelWithWave_555") + + var value = 0.0 + if (absorbanceAtPixelWithWave_427 != 0.0 && absorbanceAtPixelWithWave_555 != 0.0) { + value = absorbanceAtPixelWithWave_555 / absorbanceAtPixelWithWave_427 + } + Log.d(TAG, "value = $value") +// println("value = $value") + + + if (value < 0.24 || value == 0.0) { + return TestRightResultType.NORMAL + } else if (value >= 0.24 && value < 0.30) { + return TestRightResultType.SICKLECELLTRAIT + } else if (value >= 0.30) { + return TestRightResultType.SICKLECELLDISEASE + } + return TestRightResultType.UNDEFINED + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/refactoredapp/domain/ResultCalculationWithMaxImpl.kt b/app/src/main/java/com/example/refactoredapp/domain/ResultCalculationWithMaxImpl.kt new file mode 100644 index 0000000..39a98b6 --- /dev/null +++ b/app/src/main/java/com/example/refactoredapp/domain/ResultCalculationWithMaxImpl.kt @@ -0,0 +1,87 @@ +package com.example.refactoredapp.domain + +import com.example.refactoredapp.data.constant.Constants +import com.example.refactoredapp.data.model.TestRightCalculationData +import com.example.refactoredapp.data.model.TestRightResultType + +class ResultCalculationWithMaxImpl : TestRightResultCalculation { + + val testRightCalculationData = TestRightCalculationData( + null, + null, + null, + null, + null, + null, + null, + TestRightResultType.UNDEFINED + ) + + override fun getResults(wavelengthToAbsorbance: ArrayList>): TestRightCalculationData { + + val startWavelengthOne = + Constants.WAVELENGTH_OF_INTEREST_ONE - Constants.RANGE_IN_RESULT_CALCULATIONS + val endWavelengthOne = + Constants.WAVELENGTH_OF_INTEREST_ONE + Constants.RANGE_IN_RESULT_CALCULATIONS + 1 + var maxAbsorbanceAtOne = -999999.0 + var wavelengthOfAbsorbanceOne = 0.0 + + val startWavelengthTwo = + Constants.WAVELENGTH_OF_INTEREST_TWO - Constants.RANGE_IN_RESULT_CALCULATIONS + val endWavelengthTwo = + Constants.WAVELENGTH_OF_INTEREST_TWO + Constants.RANGE_IN_RESULT_CALCULATIONS + 1 + var maxAbsorbanceAtTwo = -999999.0 + var wavelengthOfAbsorbanceTwo = 0.0 + + for (each in wavelengthToAbsorbance) { + if (each[0] >= startWavelengthOne && each[0] < endWavelengthOne) { + if (each[1] > maxAbsorbanceAtOne) { + maxAbsorbanceAtOne = each[1] + wavelengthOfAbsorbanceOne = each[0] + } + } + if (each[0] >= startWavelengthTwo && each[0] < endWavelengthTwo) { +// maxAbsorbanceAtTwo = max(maxAbsorbanceAtTwo, each[1]) + if (each[1] > maxAbsorbanceAtTwo) { + maxAbsorbanceAtTwo = each[1] + wavelengthOfAbsorbanceTwo = each[0] + } + } + } + + testRightCalculationData.absorbanceOne = maxAbsorbanceAtOne + testRightCalculationData.wavelengthOfAbsorbanceOne = wavelengthOfAbsorbanceOne + testRightCalculationData.absorbanceTwo = maxAbsorbanceAtTwo + testRightCalculationData.wavelengthOfAbsorbanceTwo = wavelengthOfAbsorbanceTwo + + testRightCalculationData.result = calculateResultsAndRatio(maxAbsorbanceAtOne, maxAbsorbanceAtTwo) + return testRightCalculationData + } + + private fun calculateResultsAndRatio( + absorbanceAtWaveOne: Double, + absorbanceAtWaveTwo: Double + ): TestRightResultType { + if (absorbanceAtWaveOne != Double.MIN_VALUE && absorbanceAtWaveTwo != Double.MIN_VALUE && absorbanceAtWaveOne != 0.0) { + val value = absorbanceAtWaveTwo / absorbanceAtWaveOne + testRightCalculationData.ratioValue = value + + if (value < 0.24 || value == 0.0) { + testRightCalculationData.ratioMinRange = 0.0 + testRightCalculationData.ratioMaxRange = 0.24 + return TestRightResultType.NORMAL + } else if (value >= 0.24 && value < 0.30) { + testRightCalculationData.ratioMinRange = 0.24 + testRightCalculationData.ratioMaxRange = 0.30 + return TestRightResultType.SICKLECELLTRAIT + } else if (value >= 0.30) { + testRightCalculationData.ratioMinRange = 0.30 + testRightCalculationData.ratioMaxRange = 999.0 + return TestRightResultType.SICKLECELLDISEASE + } + } + + return TestRightResultType.UNDEFINED + } + +} \ No newline at end of file