Fixed string error

This commit is contained in:
Kaif
2023-12-01 16:22:13 +05:30
parent 8a22b44496
commit fb5e6f3b49

View File

@@ -1,6 +1,5 @@
package com.example.hpostesting.presentation.hemocube
import com.example.hpostesting.presentation.dashboard.DashboardActivity
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
@@ -19,7 +18,7 @@ import com.example.hpostesting.data.constant.HemoCubeCommands
import com.example.hpostesting.data.model.patient.DeviceData
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
import com.example.hpostesting.presentation.UsbServiceListener
import com.example.hpostesting.presentation.dashboard.DashboardActivity
import com.example.hpostesting.presentation.utils.MyDialogListener
import com.example.hpostesting.presentation.utils.UIUtils
import com.google.firebase.crashlytics.ktx.crashlytics
@@ -231,7 +230,7 @@ class HemoCubeFragment : Fragment() {
activity?.runOnUiThread {
binding.btnPlacebuffer.visibility = View.GONE
binding.btnSamplestart.visibility = View.VISIBLE
binding.tvSubtitle4.text = R.string.place_sample.toString()
binding.tvSubtitle4.text = getString(R.string.place_sample)
}
isUsingExistingBuffer = true
}
@@ -308,36 +307,37 @@ class HemoCubeFragment : Fragment() {
activity?.runOnUiThread {
binding.btnPlacebuffer.visibility = View.VISIBLE
}
hemoCubeViewModel.messages.postValue(R.string.start.toString())
hemoCubeViewModel.messages.postValue(getString(R.string.start))
}
stringData.contains("#BS") -> {
hemoCubeViewModel.messages.postValue(R.string.buffer_started.toString())
hemoCubeViewModel.messages.postValue(getString(R.string.buffer_started))
}
stringData.contains("#BC") -> {
activity?.runOnUiThread {
binding.tvSubtitle4.text = R.string.buffer_completed.toString()
binding.tvSubtitle4.text = getString(R.string.buffer_completed)
binding.btnSamplestart.visibility = View.VISIBLE
}
}
stringData.contains("#SS") -> {
activity?.runOnUiThread {
binding.tvSubtitle4.text = R.string.sample_started.toString()
binding.tvSubtitle4.text = getString(R.string.sample_started)
binding.btnSamplestart.visibility = View.GONE
}
}
stringData.contains("#SC") -> {
hemoCubeViewModel.messages.postValue(R.string.sample_completed.toString() +"\n" + R.string.gathering_data.toString())
hemoCubeViewModel.messages.postValue(
getString(R.string.sample_completed) + "\n" + getString(R.string.gathering_data))
fetchResult()
testingTrace.stop()
}
resultData.contains("REND") -> {
hemoCubeViewModel.messages.postValue(
R.string.data_collected_processing_data.toString()
getString(R.string.data_collected_processing_data)
)
val resultLines = resultData.split("\\s+(?=LB|LS)".toRegex())
var bufferIntensity = resultLines[1].split(' ')[1].trim()
@@ -410,7 +410,7 @@ class HemoCubeFragment : Fragment() {
private fun processResult() {
try {
hemoCubeViewModel.messages.postValue(R.string.processing_result.toString())
hemoCubeViewModel.messages.postValue(getString(R.string.processing_result))
val deviceLog = resultData
val pInfo = requireActivity().packageManager.getPackageInfo(
@@ -418,35 +418,49 @@ class HemoCubeFragment : Fragment() {
)
val version = pInfo.versionName
val led1Average = log10(led1BufferForDevice?.div(led1SampleForDevice!!) ?: 0.0)
val led2Average = log10(led2BufferForDevice?.div(led2SampleForDevice!!) ?: 0.0)
val led3Average = log10(led3BufferForDevice?.div(led3SampleForDevice!!) ?: 0.0)
val led4Average = log10(led4BufferForDevice?.div(led4SampleForDevice!!) ?: 0.0)
val led1Average = log10(led1BufferForDevice.div(led1SampleForDevice))
val led2Average = log10(led2BufferForDevice.div(led2SampleForDevice))
val led3Average = log10(led3BufferForDevice.div(led3SampleForDevice))
val led4Average = log10(led4BufferForDevice.div(led4SampleForDevice))
val deviceRatio = led3Average / led1Average
if (led1BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)?.get(0)!!
|| led2BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(1)?.get(0)!!
|| led3BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(2)?.get(0)!!
|| led4BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(3)?.get(0)!!
if (led1BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)
?.get(0)!!
|| led2BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(
1
)?.get(0)!!
|| led3BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(
2
)?.get(0)!!
|| led4BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(
3
)?.get(0)!!
) {
validationError = true
allErrorMessages += "Error: Invalid Test. Improper buffer reading (low)"
activity?.runOnUiThread {
binding.errorMessage.text = R.string.error_improper_buffer_low.toString()
binding.errorMessage.text = getString(R.string.error_improper_buffer_low)
binding.errorMessage.visibility = View.VISIBLE
}
}
if (led1BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)?.get(1)!!
|| led2BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(1)?.get(1)!!
|| led3BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(2)?.get(1)!!
|| led4BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(3)?.get(1)!!
if (led1BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)
?.get(1)!!
|| led2BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(
1
)?.get(1)!!
|| led3BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(
2
)?.get(1)!!
|| led4BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(
3
)?.get(1)!!
) {
validationError = true
allErrorMessages += "Error: Invalid Test. Improper buffer reading (high)" + "\n"
activity?.runOnUiThread {
binding.errorMessage.text =
R.string.error_improper_buffer_high.toString()
getString(R.string.error_improper_buffer_high)
binding.errorMessage.visibility = View.VISIBLE
binding.btnSubmit.isEnabled = true
binding.btnSubmit.isClickable = true
@@ -469,13 +483,13 @@ class HemoCubeFragment : Fragment() {
constant = Constants.DEVICE_CONFIGURATION[deviceHardwareId]?.get(3)?.get(1)
fittedAbs4 = gradient?.times(led4Average)?.plus(constant!!)!!
_predictedDenovixRatio = fittedAbs3?.div(fittedAbs1!!)!!
_predictedDenovixRatio = fittedAbs3.div(fittedAbs1)
if (fittedAbs1!! <= fittedAbs2!!) {
if (fittedAbs1 <= fittedAbs2) {
validationError = true
allErrorMessages += "Error: Invalid Test. Problem with de-oxygenation" + "\n"
activity?.runOnUiThread {
binding.errorMessage.text = R.string.error_invalid_test.toString()
binding.errorMessage.text = getString(R.string.error_invalid_test)
binding.errorMessage.visibility = View.VISIBLE
}
}
@@ -483,7 +497,7 @@ class HemoCubeFragment : Fragment() {
if (fittedAbs1 < 0 || fittedAbs2 < 0 || fittedAbs3 < 0 || fittedAbs4 < 0) {
validationError = true
activity?.runOnUiThread {
binding.errorMessage.text = R.string.error_negative_abs.toString()
binding.errorMessage.text = getString(R.string.error_negative_abs)
binding.errorMessage.visibility = View.VISIBLE
}
}
@@ -527,10 +541,13 @@ class HemoCubeFragment : Fragment() {
this.errorMessages = allErrorMessages
this.resultData = deviceLog
this.batteryLevel = hemoCubeViewModel.getBatteryLevel().toString()
this.batteryCapacity = hemoCubeViewModel.getBatteryCapacity(requireContext()).toString()
this.batteryMaxCapacity = hemoCubeViewModel.getBatteryMaxCapacity(requireContext()).toString()
this.batteryCapacity =
hemoCubeViewModel.getBatteryCapacity(requireContext()).toString()
this.batteryMaxCapacity =
hemoCubeViewModel.getBatteryMaxCapacity(requireContext()).toString()
this.batteryTemperature = hemoCubeViewModel.getBatteryTemperature().toString()
this.batteryVoltage = hemoCubeViewModel.getBatteryVoltage(requireContext()).toString()
this.batteryVoltage =
hemoCubeViewModel.getBatteryVoltage(requireContext()).toString()
}
if (!isUsingExistingBuffer) {
@@ -566,28 +583,28 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.messages.postValue("result classification")
if (calculatedRatio != null) {
if (calculatedRatio < 0.05)
return R.string.error_repeat_test_higher_volume.toString()
return getString(R.string.error_repeat_test_higher_volume)
if (calculatedRatio in 0.05..0.155)
return R.string.normal.toString()
return getString(R.string.normal)
if (calculatedRatio in 0.155..0.175)
return R.string.negative_borderline.toString()
return getString(R.string.negative_borderline)
if (calculatedRatio in 0.175..0.22)
return R.string.sickle_cell_trait.toString()
return getString(R.string.sickle_cell_trait)
if (calculatedRatio in 0.22..0.25)
return R.string.positive_for_sickle_cell.toString()
return getString(R.string.positive_for_sickle_cell)
if (calculatedRatio in 0.25..0.35)
return R.string.sickle_cell_disease.toString()
return getString(R.string.sickle_cell_disease)
if (calculatedRatio > 0.35)
return R.string.error_repeat_test_lower_volume.toString()
return getString(R.string.error_repeat_test_lower_volume)
} else {
return R.string.invalid.toString()
return getString(R.string.invalid)
}
} catch (e: Exception) {
showToast(R.string.error_classification)
Firebase.crashlytics.recordException(e)
return R.string.error.toString()
return getString(R.string.error)
}
return R.string.invalid.toString()
return getString(R.string.invalid)
}
private fun absorbanceBasedClassification(predictedDenovixRatio: Double?): String {
@@ -595,24 +612,24 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.messages.postValue("result classification")
if (predictedDenovixRatio != null) {
if (predictedDenovixRatio in 0.0..0.16)
return R.string.normal.toString()
return getString(R.string.normal)
if (predictedDenovixRatio in 0.16..0.165)
return R.string.negative_borderline.toString()
return getString(R.string.negative_borderline)
if (predictedDenovixRatio in 0.165..0.235)
return R.string.sickle_cell_trait.toString()
return getString(R.string.sickle_cell_trait)
if (predictedDenovixRatio in 0.235..0.24)
return R.string.positive_borderline.toString()
return getString(R.string.positive_borderline)
if (predictedDenovixRatio in 0.24..1.0)
return R.string.sickle_cell_disease.toString()
return getString(R.string.sickle_cell_disease)
} else {
return R.string.invalid.toString()
return getString(R.string.invalid)
}
} catch (e: Exception) {
showToast(R.string.error_classification)
Firebase.crashlytics.recordException(e)
return R.string.error.toString()
return getString(R.string.error)
}
return R.string.invalid.toString()
return getString(R.string.invalid)
}
private fun showToast(messageResId: Int) {