String Issues fixed

This commit is contained in:
Mariya
2023-12-05 17:53:46 +05:30
parent f109c52288
commit 7a2e5ead51

View File

@@ -231,7 +231,7 @@ class HemoCubeFragment : Fragment() {
activity?.runOnUiThread { activity?.runOnUiThread {
binding.btnPlacebuffer.visibility = View.GONE binding.btnPlacebuffer.visibility = View.GONE
binding.btnSamplestart.visibility = View.VISIBLE binding.btnSamplestart.visibility = View.VISIBLE
binding.tvSubtitle4.text = R.string.place_sample.toString() binding.tvSubtitle4.text = getString(R.string.place_sample)
} }
isUsingExistingBuffer = true isUsingExistingBuffer = true
} }
@@ -308,36 +308,37 @@ class HemoCubeFragment : Fragment() {
activity?.runOnUiThread { activity?.runOnUiThread {
binding.btnPlacebuffer.visibility = View.VISIBLE binding.btnPlacebuffer.visibility = View.VISIBLE
} }
hemoCubeViewModel.messages.postValue(R.string.start.toString()) hemoCubeViewModel.messages.postValue(getString(R.string.start))
} }
stringData.contains("#BS") -> { stringData.contains("#BS") -> {
hemoCubeViewModel.messages.postValue(R.string.buffer_started.toString()) hemoCubeViewModel.messages.postValue(getString(R.string.buffer_started))
} }
stringData.contains("#BC") -> { stringData.contains("#BC") -> {
activity?.runOnUiThread { activity?.runOnUiThread {
binding.tvSubtitle4.text = R.string.buffer_completed.toString() binding.tvSubtitle4.text = getString(R.string.buffer_completed)
binding.btnSamplestart.visibility = View.VISIBLE binding.btnSamplestart.visibility = View.VISIBLE
} }
} }
stringData.contains("#SS") -> { stringData.contains("#SS") -> {
activity?.runOnUiThread { activity?.runOnUiThread {
binding.tvSubtitle4.text = R.string.sample_started.toString() binding.tvSubtitle4.text = getString(R.string.sample_started)
binding.btnSamplestart.visibility = View.GONE binding.btnSamplestart.visibility = View.GONE
} }
} }
stringData.contains("#SC") -> { 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() fetchResult()
testingTrace.stop() testingTrace.stop()
} }
resultData.contains("REND") -> { resultData.contains("REND") -> {
hemoCubeViewModel.messages.postValue( 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()) val resultLines = resultData.split("\\s+(?=LB|LS)".toRegex())
var bufferIntensity = resultLines[1].split(' ')[1].trim() var bufferIntensity = resultLines[1].split(' ')[1].trim()
@@ -410,7 +411,7 @@ class HemoCubeFragment : Fragment() {
private fun processResult() { private fun processResult() {
try { try {
hemoCubeViewModel.messages.postValue(R.string.processing_result.toString()) hemoCubeViewModel.messages.postValue(getString(R.string.processing_result))
val deviceLog = resultData val deviceLog = resultData
val pInfo = requireActivity().packageManager.getPackageInfo( val pInfo = requireActivity().packageManager.getPackageInfo(
@@ -418,35 +419,49 @@ class HemoCubeFragment : Fragment() {
) )
val version = pInfo.versionName val version = pInfo.versionName
val led1Average = log10(led1BufferForDevice?.div(led1SampleForDevice!!) ?: 0.0) val led1Average = log10(led1BufferForDevice.div(led1SampleForDevice))
val led2Average = log10(led2BufferForDevice?.div(led2SampleForDevice!!) ?: 0.0) val led2Average = log10(led2BufferForDevice.div(led2SampleForDevice))
val led3Average = log10(led3BufferForDevice?.div(led3SampleForDevice!!) ?: 0.0) val led3Average = log10(led3BufferForDevice.div(led3SampleForDevice))
val led4Average = log10(led4BufferForDevice?.div(led4SampleForDevice!!) ?: 0.0) val led4Average = log10(led4BufferForDevice.div(led4SampleForDevice))
val deviceRatio = led3Average / led1Average val deviceRatio = led3Average / led1Average
if (led1BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)?.get(0)!! if (led1BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)
|| led2BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(1)?.get(0)!! ?.get(0)!!
|| led3BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(2)?.get(0)!! || led2BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(
|| led4BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(3)?.get(0)!! 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 validationError = true
allErrorMessages += "Error: Invalid Test. Improper buffer reading (low)" allErrorMessages += "Error: Invalid Test. Improper buffer reading (low)"
activity?.runOnUiThread { 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 binding.errorMessage.visibility = View.VISIBLE
} }
} }
if (led1BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)?.get(1)!! if (led1BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)
|| led2BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(1)?.get(1)!! ?.get(1)!!
|| led3BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(2)?.get(1)!! || led2BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(
|| led4BufferForDevice > Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(3)?.get(1)!! 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 validationError = true
allErrorMessages += "Error: Invalid Test. Improper buffer reading (high)" + "\n" allErrorMessages += "Error: Invalid Test. Improper buffer reading (high)" + "\n"
activity?.runOnUiThread { activity?.runOnUiThread {
binding.errorMessage.text = binding.errorMessage.text =
R.string.error_improper_buffer_high.toString() getString(R.string.error_improper_buffer_high)
binding.errorMessage.visibility = View.VISIBLE binding.errorMessage.visibility = View.VISIBLE
binding.btnSubmit.isEnabled = true binding.btnSubmit.isEnabled = true
binding.btnSubmit.isClickable = true binding.btnSubmit.isClickable = true
@@ -469,13 +484,13 @@ class HemoCubeFragment : Fragment() {
constant = Constants.DEVICE_CONFIGURATION[deviceHardwareId]?.get(3)?.get(1) constant = Constants.DEVICE_CONFIGURATION[deviceHardwareId]?.get(3)?.get(1)
fittedAbs4 = gradient?.times(led4Average)?.plus(constant!!)!! fittedAbs4 = gradient?.times(led4Average)?.plus(constant!!)!!
_predictedDenovixRatio = fittedAbs3?.div(fittedAbs1!!)!! _predictedDenovixRatio = fittedAbs3.div(fittedAbs1)
if (fittedAbs1!! <= fittedAbs2!!) { if (fittedAbs1 <= fittedAbs2) {
validationError = true validationError = true
allErrorMessages += "Error: Invalid Test. Problem with de-oxygenation" + "\n" allErrorMessages += "Error: Invalid Test. Problem with de-oxygenation" + "\n"
activity?.runOnUiThread { 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 binding.errorMessage.visibility = View.VISIBLE
} }
} }
@@ -483,7 +498,7 @@ class HemoCubeFragment : Fragment() {
if (fittedAbs1 < 0 || fittedAbs2 < 0 || fittedAbs3 < 0 || fittedAbs4 < 0) { if (fittedAbs1 < 0 || fittedAbs2 < 0 || fittedAbs3 < 0 || fittedAbs4 < 0) {
validationError = true validationError = true
activity?.runOnUiThread { 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 binding.errorMessage.visibility = View.VISIBLE
} }
} }
@@ -527,10 +542,13 @@ class HemoCubeFragment : Fragment() {
this.errorMessages = allErrorMessages this.errorMessages = allErrorMessages
this.resultData = deviceLog this.resultData = deviceLog
this.batteryLevel = hemoCubeViewModel.getBatteryLevel().toString() this.batteryLevel = hemoCubeViewModel.getBatteryLevel().toString()
this.batteryCapacity = hemoCubeViewModel.getBatteryCapacity(requireContext()).toString() this.batteryCapacity =
this.batteryMaxCapacity = hemoCubeViewModel.getBatteryMaxCapacity(requireContext()).toString() hemoCubeViewModel.getBatteryCapacity(requireContext()).toString()
this.batteryMaxCapacity =
hemoCubeViewModel.getBatteryMaxCapacity(requireContext()).toString()
this.batteryTemperature = hemoCubeViewModel.getBatteryTemperature().toString() this.batteryTemperature = hemoCubeViewModel.getBatteryTemperature().toString()
this.batteryVoltage = hemoCubeViewModel.getBatteryVoltage(requireContext()).toString() this.batteryVoltage =
hemoCubeViewModel.getBatteryVoltage(requireContext()).toString()
} }
if (!isUsingExistingBuffer) { if (!isUsingExistingBuffer) {
@@ -544,12 +562,12 @@ class HemoCubeFragment : Fragment() {
} }
// if (!validationError) { // if (!validationError) {
activity?.runOnUiThread { activity?.runOnUiThread {
binding.btnSubmit.visibility = View.VISIBLE binding.btnSubmit.visibility = View.VISIBLE
binding.btnSubmit.isEnabled = true binding.btnSubmit.isEnabled = true
binding.btnSubmit.isClickable = true binding.btnSubmit.isClickable = true
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd")) binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
} }
// } // }
} catch (e: Exception) { } catch (e: Exception) {
Toast.makeText( Toast.makeText(
@@ -566,28 +584,28 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.messages.postValue("result classification") hemoCubeViewModel.messages.postValue("result classification")
if (calculatedRatio != null) { if (calculatedRatio != null) {
if (calculatedRatio < 0.05) 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) if (calculatedRatio in 0.05..0.155)
return R.string.normal.toString() return getString(R.string.normal)
if (calculatedRatio in 0.155..0.175) 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) 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) 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) 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) if (calculatedRatio > 0.35)
return R.string.error_repeat_test_lower_volume.toString() return getString(R.string.error_repeat_test_lower_volume)
} else { } else {
return R.string.invalid.toString() return getString(R.string.invalid)
} }
} catch (e: Exception) { } catch (e: Exception) {
showToast(R.string.error_classification) showToast(R.string.error_classification)
Firebase.crashlytics.recordException(e) 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 { private fun absorbanceBasedClassification(predictedDenovixRatio: Double?): String {
@@ -595,24 +613,24 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.messages.postValue("result classification") hemoCubeViewModel.messages.postValue("result classification")
if (predictedDenovixRatio != null) { if (predictedDenovixRatio != null) {
if (predictedDenovixRatio in 0.0..0.16) if (predictedDenovixRatio in 0.0..0.16)
return R.string.normal.toString() return getString(R.string.normal)
if (predictedDenovixRatio in 0.16..0.165) 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) 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) 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) if (predictedDenovixRatio in 0.24..1.0)
return R.string.sickle_cell_disease.toString() return getString(R.string.sickle_cell_disease)
} else { } else {
return R.string.invalid.toString() return getString(R.string.invalid)
} }
} catch (e: Exception) { } catch (e: Exception) {
showToast(R.string.error_classification) showToast(R.string.error_classification)
Firebase.crashlytics.recordException(e) 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) { private fun showToast(messageResId: Int) {
@@ -674,4 +692,4 @@ class HemoCubeFragment : Fragment() {
return true return true
return false return false
} }
} }