Issues fixed

This commit is contained in:
Mariya
2023-12-06 17:25:45 +05:30
parent 0903647500
commit dadddfd558
3 changed files with 33 additions and 20 deletions

View File

@@ -114,8 +114,8 @@ object Constants {
val COEFFICIENTS: Map<String, List<List<Double>>> = mapOf( val COEFFICIENTS: Map<String, List<List<Double>>> = mapOf(
"HC-V1-005" to listOf( "HC-V1-005" to listOf(
listOf(1.5), listOf(1.5,0.0),
listOf(0.0) listOf(0.0,0.0)
) )
) )

View File

@@ -39,7 +39,7 @@ class HemoCubeFragment : Fragment() {
private var currentDeviceData: DeviceData? = null private var currentDeviceData: DeviceData? = null
private var resultData: String = "" private var resultData: String = ""
private var deviceSerialNo: String = "" private var deviceSerialNo: String = ""
private var coefficients: String? = "" private var coefficient: String? = ""
private var isUsingExistingBuffer = false private var isUsingExistingBuffer = false
private var isTestOngoing = false private var isTestOngoing = false
private var startListening = MutableLiveData<Boolean>(false) private var startListening = MutableLiveData<Boolean>(false)
@@ -118,7 +118,7 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable -> hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
apply { apply {
if (isNetworkAvailable) { // if (isNetworkAvailable) {
// Online mode // Online mode
DataHolder.hemoCubeTestData?.let { DataHolder.hemoCubeTestData?.let {
currentDeviceData?.coefficients?.let { coefficients -> currentDeviceData?.coefficients?.let { coefficients ->
@@ -128,14 +128,14 @@ class HemoCubeFragment : Fragment() {
// Process result in online mode // Process result in online mode
} }
} }
} else { // } else {
// Offline mode // // Offline mode
val coefficient1 = Constants.COEFFICIENTS[deviceSerialNo]?.get(0)?.get(0).toString().toDoubleOrNull() ?: 0.0 // val coefficient1 = Constants.COEFFICIENTS[deviceSerialNo]?.get(0)?.get(0).toString().toDoubleOrNull() ?: 0.0
val coefficient2 = Constants.COEFFICIENTS[deviceSerialNo]?.get(1)?.get(0).toString().toDoubleOrNull() ?: 0.0 // val coefficient2 = Constants.COEFFICIENTS[deviceSerialNo]?.get(1)?.get(0).toString().toDoubleOrNull() ?: 0.0
val result = coefficient1 * coefficient2 // val result = coefficient1 * coefficient2
//
// Process result in offline mode // // Process result in offline mode
} // }
isOnline = isNetworkAvailable isOnline = isNetworkAvailable
} }
@@ -358,15 +358,24 @@ class HemoCubeFragment : Fragment() {
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0) val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0) val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
val deviceRatio = led1Average / led2Average val deviceRatio = led1Average / led2Average
val coefficientsList = Constants.COEFFICIENTS[deviceSerialNo]
if (isOnline) { if (coefficientsList != null) {
// Online mode, use coefficients from the server val coefficient1 = coefficientsList.getOrNull(0)?.get(0) ?: 0.0
coefficients = currentDeviceData?.coefficients?.get(0) val coefficient2 = coefficientsList.getOrNull(1)?.get(0) ?: 0.0
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString() coefficient = "$coefficient1,$coefficient2"
// Now, you can use 'coefficients' to store in Firebase.
} else { } else {
// Offline mode, provide default coefficients or handle as needed coefficient = currentDeviceData?.coefficients?.get(0)
coefficients = Constants.COEFFICIENTS[loginId]?.get(0).toString() + "," + Constants.COEFFICIENTS[loginId]?.get(1).toString() .toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
} }
// if (isOnline) {
// // Online mode, use coefficients from the server
// coefficients = currentDeviceData?.coefficients?.get(0)
// .toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
// } else {
// Offline mode, provide default coefficients or handle as needed
// }
// if (led1BufferForDevice!! > 20000 && led1BufferForDevice < 24000 && led2BufferForDevice!! > 20000 && led2BufferForDevice < 24000) { // if (led1BufferForDevice!! > 20000 && led1BufferForDevice < 24000 && led2BufferForDevice!! > 20000 && led2BufferForDevice < 24000) {
// if (led1Sample!! < led1BufferForDevice && led1Sample < 24000 && led2Sample!! < led2BufferForDevice && led2Sample < 24000) { // if (led1Sample!! < led1BufferForDevice && led1Sample < 24000 && led2Sample!! < led2BufferForDevice && led2Sample < 24000) {
// if (deviceRatio < 0.08) { // if (deviceRatio < 0.08) {
@@ -396,7 +405,7 @@ class HemoCubeFragment : Fragment() {
this.deviceRatio = deviceRatio this.deviceRatio = deviceRatio
this.calculatedRatio = calculateRatio(deviceRatio) this.calculatedRatio = calculateRatio(deviceRatio)
// this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString() // this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
this.coefficients = coefficients this.coefficients = coefficient
this.classificationResult = findResult(calculatedRatio) this.classificationResult = findResult(calculatedRatio)
hemoCubeViewModel.messages.postValue(this.classificationResult) hemoCubeViewModel.messages.postValue(this.classificationResult)
this.resultData = deviceLog this.resultData = deviceLog

View File

@@ -166,6 +166,8 @@ class HemoCubeViewModel @Inject constructor(
fireBaseUpload.postValue("Error") fireBaseUpload.postValue("Error")
hemoCubeDao.insertAll(testDetails) hemoCubeDao.insertAll(testDetails)
} }
else -> {}
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.e("Testdb", "Exception during data upload: ${e.message}") Log.e("Testdb", "Exception during data upload: ${e.message}")
@@ -190,6 +192,8 @@ class HemoCubeViewModel @Inject constructor(
Log.e("Testdb", "Error uploading data to Firestore: $response") Log.e("Testdb", "Error uploading data to Firestore: $response")
fireBaseUpload.postValue("Error") fireBaseUpload.postValue("Error")
} }
else -> {}
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.e("Testdb", "Exception during data upload: ${e.message}") Log.e("Testdb", "Exception during data upload: ${e.message}")