add buffer validation withn bounds

This commit is contained in:
Pritimay Sarkar
2023-11-14 00:22:40 +05:30
parent d3083c8dbc
commit 74ad03bf8b
2 changed files with 46 additions and 14 deletions

View File

@@ -74,4 +74,7 @@ object Constants {
const val BUFFER_VALUE_3 = "BufferValue3"
const val BUFFER_VALUE_4 = "BufferValue4"
const val DEVICE_ID = "DEVICE_ID"
const val BUFFER_LED_LOWER_BOUND = 20000
const val BUFFER_LED_HIGHER_BOUND = 24000
}

View File

@@ -45,12 +45,13 @@ class HemoCubeFragment : Fragment() {
private val testingTrace = Firebase.performance.newTrace("testing_trace")
private var led1BufferForDevice = 0.0
private var led2BufferForDevice = 0.0
private var led3BufferForDevice = 0.0
private var led3BufferForDevice = 0.0
private var led4BufferForDevice = 0.0
private var led1SampleForDevice = 0.0
private var led2SampleForDevice = 0.0
private var led3SampleForDevice = 0.0
private var led3SampleForDevice = 0.0
private var led4SampleForDevice = 0.0
private var validationError = false
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
@@ -96,8 +97,8 @@ class HemoCubeFragment : Fragment() {
binding.tvSubtitle4.visibility = View.VISIBLE
binding.tvSubtitle4.text = "Sample Started"
}
startSampleProcess()
it.visibility = View.GONE
startSampleProcess()
it.visibility = View.GONE
}
binding.btnPlacebuffer.setOnClickListener {
@@ -355,7 +356,8 @@ class HemoCubeFragment : Fragment() {
sampleIntensity = resultLines[7].split(' ')[1].trim()
led3SampleForDevice = resultLines[7].split(' ')[1].trim().toDoubleOrNull()!!
sampleIntensity = resultLines[8].split(' ')[1].split('\r')[0].trim()
led4SampleForDevice = resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!!
led4SampleForDevice =
resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!!
processResult()
}
}
@@ -406,9 +408,34 @@ class HemoCubeFragment : Fragment() {
val led4Average = log10(led4BufferForDevice?.div(led4SampleForDevice!!) ?: 0.0)
val deviceRatio = led3Average / led1Average
if (led1Average < 0 || led2Average < 0) {
if (led1Average < 0 || led2Average < 0 || led3Average < 0 || led4Average < 0) {
validationError = true
activity?.runOnUiThread {
binding.errorMessage.text = "Warning: Negative Abs. Retake Blank Reading"
binding.errorMessage.text = "Error: Negative Abs. Retake Blank Reading"
binding.errorMessage.visibility = View.VISIBLE
}
}
if (led1BufferForDevice < Constants.BUFFER_LED_LOWER_BOUND
|| led2BufferForDevice < Constants.BUFFER_LED_LOWER_BOUND
|| led3BufferForDevice < Constants.BUFFER_LED_LOWER_BOUND
|| led4BufferForDevice < Constants.BUFFER_LED_LOWER_BOUND
) {
validationError = true
activity?.runOnUiThread {
binding.errorMessage.text = "Error: Invalid Test. Blank reading is too low"
binding.errorMessage.visibility = View.VISIBLE
}
}
if (led1BufferForDevice > Constants.BUFFER_LED_HIGHER_BOUND
|| led2BufferForDevice > Constants.BUFFER_LED_HIGHER_BOUND
|| led3BufferForDevice > Constants.BUFFER_LED_HIGHER_BOUND
|| led4BufferForDevice > Constants.BUFFER_LED_HIGHER_BOUND
) {
validationError = true
activity?.runOnUiThread {
binding.errorMessage.text = "Error: Invalid Test. Blank reading is too high"
binding.errorMessage.visibility = View.VISIBLE
}
}
@@ -444,11 +471,13 @@ class HemoCubeFragment : Fragment() {
apply()
}
}
activity?.runOnUiThread {
binding.btnSubmit.visibility = View.VISIBLE
binding.btnSubmit.isEnabled = true
binding.btnSubmit.isClickable = true
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
if (!validationError) {
activity?.runOnUiThread {
binding.btnSubmit.visibility = View.VISIBLE
binding.btnSubmit.isEnabled = true
binding.btnSubmit.isClickable = true
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
}
}
}
} catch (e: Exception) {
@@ -480,14 +509,14 @@ class HemoCubeFragment : Fragment() {
if (calculatedRatio > 0.35)
return "Inconclusive. Repeat with test with lower volume of blood"
} else {
return "NULL"
return "INVALID"
}
} catch (e: Exception) {
showToast("error while performing classification")
Firebase.crashlytics.recordException(e)
return "ERROR"
}
return "NULL"
return "INVALID"
}
private fun showToast(message: String) {