Issues fixed
This commit is contained in:
@@ -114,8 +114,8 @@ object Constants {
|
||||
|
||||
val COEFFICIENTS: Map<String, List<List<Double>>> = mapOf(
|
||||
"HC-V1-005" to listOf(
|
||||
listOf(1.5),
|
||||
listOf(0.0)
|
||||
listOf(1.5,0.0),
|
||||
listOf(0.0,0.0)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class HemoCubeFragment : Fragment() {
|
||||
private var currentDeviceData: DeviceData? = null
|
||||
private var resultData: String = ""
|
||||
private var deviceSerialNo: String = ""
|
||||
private var coefficients: String? = ""
|
||||
private var coefficient: String? = ""
|
||||
private var isUsingExistingBuffer = false
|
||||
private var isTestOngoing = false
|
||||
private var startListening = MutableLiveData<Boolean>(false)
|
||||
@@ -118,7 +118,7 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||
apply {
|
||||
if (isNetworkAvailable) {
|
||||
// if (isNetworkAvailable) {
|
||||
// Online mode
|
||||
DataHolder.hemoCubeTestData?.let {
|
||||
currentDeviceData?.coefficients?.let { coefficients ->
|
||||
@@ -128,14 +128,14 @@ class HemoCubeFragment : Fragment() {
|
||||
// Process result in online mode
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Offline mode
|
||||
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 result = coefficient1 * coefficient2
|
||||
|
||||
// Process result in offline mode
|
||||
}
|
||||
// } else {
|
||||
// // Offline mode
|
||||
// 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 result = coefficient1 * coefficient2
|
||||
//
|
||||
// // Process result in offline mode
|
||||
// }
|
||||
|
||||
isOnline = isNetworkAvailable
|
||||
}
|
||||
@@ -358,15 +358,24 @@ class HemoCubeFragment : Fragment() {
|
||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
||||
val deviceRatio = led1Average / led2Average
|
||||
|
||||
if (isOnline) {
|
||||
// Online mode, use coefficients from the server
|
||||
coefficients = currentDeviceData?.coefficients?.get(0)
|
||||
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
||||
val coefficientsList = Constants.COEFFICIENTS[deviceSerialNo]
|
||||
if (coefficientsList != null) {
|
||||
val coefficient1 = coefficientsList.getOrNull(0)?.get(0) ?: 0.0
|
||||
val coefficient2 = coefficientsList.getOrNull(1)?.get(0) ?: 0.0
|
||||
coefficient = "$coefficient1,$coefficient2"
|
||||
// Now, you can use 'coefficients' to store in Firebase.
|
||||
} else {
|
||||
// Offline mode, provide default coefficients or handle as needed
|
||||
coefficients = Constants.COEFFICIENTS[loginId]?.get(0).toString() + "," + Constants.COEFFICIENTS[loginId]?.get(1).toString()
|
||||
coefficient = currentDeviceData?.coefficients?.get(0)
|
||||
.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 (led1Sample!! < led1BufferForDevice && led1Sample < 24000 && led2Sample!! < led2BufferForDevice && led2Sample < 24000) {
|
||||
// if (deviceRatio < 0.08) {
|
||||
@@ -396,7 +405,7 @@ class HemoCubeFragment : Fragment() {
|
||||
this.deviceRatio = deviceRatio
|
||||
this.calculatedRatio = calculateRatio(deviceRatio)
|
||||
// this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
||||
this.coefficients = coefficients
|
||||
this.coefficients = coefficient
|
||||
this.classificationResult = findResult(calculatedRatio)
|
||||
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
||||
this.resultData = deviceLog
|
||||
|
||||
@@ -166,6 +166,8 @@ class HemoCubeViewModel @Inject constructor(
|
||||
fireBaseUpload.postValue("Error")
|
||||
hemoCubeDao.insertAll(testDetails)
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
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")
|
||||
fireBaseUpload.postValue("Error")
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||
|
||||
Reference in New Issue
Block a user