From 750fb67ff9a13aceca595bb07078b91433f14bb5 Mon Sep 17 00:00:00 2001 From: "smileomi18@gmail.com" Date: Thu, 3 Aug 2023 15:41:57 +0530 Subject: [PATCH] calibration calculation done --- .../data/model/patient/DeviceData.kt | 17 ++++++--- .../presentation/hemocube/HemoCubeFragment.kt | 35 ++++++++++++------- .../hemocube/HemoCubeViewModel.kt | 18 +++------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/example/hpostesting/data/model/patient/DeviceData.kt b/app/src/main/java/com/example/hpostesting/data/model/patient/DeviceData.kt index d5aae42..94ef8ee 100644 --- a/app/src/main/java/com/example/hpostesting/data/model/patient/DeviceData.kt +++ b/app/src/main/java/com/example/hpostesting/data/model/patient/DeviceData.kt @@ -1,8 +1,15 @@ package com.example.hpostesting.data.model.patient -data class DeviceData ( - val deviceId: String? = "", - val deviceType: String? = "", - val coefficients: List? = null, - val calibratedAt: String +import com.google.firebase.firestore.PropertyName + + +data class DeviceData( + @get:PropertyName("deviceId") @set:PropertyName("deviceId") + var deviceId: String = "", + @get:PropertyName("deviceType") @set:PropertyName("deviceType") + var deviceType: String = "", + @get:PropertyName("coefficients") @set:PropertyName("coefficients") + var coefficients: List = emptyList(), + @get:PropertyName("calibratedAt") @set:PropertyName("calibratedAt") + var calibratedAt: String = "" ) \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt index 5208978..9935e20 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt @@ -37,7 +37,7 @@ class HemoCubeFragment : Fragment() { private val ACTION_USB_PERMISSION = "com.example.usbpermission" private val TIMEOUT = 0 - private var deviceData = listOf() + private var deviceData: DeviceData? = null private val usbManager: UsbManager by lazy { requireContext().getSystemService(Context.USB_SERVICE) as UsbManager @@ -72,11 +72,12 @@ class HemoCubeFragment : Fragment() { binding.progressBar.visibility = View.GONE } - hemoCubeViewModel.getDeviceData() - + hemoCubeViewModel.getDeviceData("DEVICE1") hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) { deviceData = it + Toast.makeText(requireContext(), calculateRatio(0.17).toString(), Toast.LENGTH_SHORT).show() + } hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable -> @@ -87,16 +88,16 @@ class HemoCubeFragment : Fragment() { } } - if (checkBufferValue()) { - TODO("Call S command") - //We have to store the buffer value like this - with(sharedPreference.edit()) { - putInt(Constants.BUFFER_VALUE, 2000) - apply() - } - } else { - TODO("Call B command") - } +// if (checkBufferValue()) { +// TODO("Call S command") +// //We have to store the buffer value like this +// with(sharedPreference.edit()) { +// putInt(Constants.BUFFER_VALUE, 2000) +// apply() +// } +// } else { +// TODO("Call B command") +// } } private fun checkBufferValue(): Boolean { @@ -311,4 +312,12 @@ class HemoCubeFragment : Fragment() { } }) } + + private fun calculateRatio(ratio: Double): Double { +// val c1 = deviceData?.coefficients?.get(0)!! +// val c2 = deviceData?.coefficients?.get(1)!! + val c1 = deviceData?.coefficients?.get(0)!! + val c2 = deviceData?.coefficients?.get(1)!! + return c1 * ratio - c2 + } } diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt index 77719a7..fbd3c77 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt @@ -1,5 +1,6 @@ package com.example.hpostesting.presentation.hemocube +import android.annotation.SuppressLint import android.content.Context import android.util.Log import androidx.lifecycle.LiveData @@ -34,8 +35,7 @@ class HemoCubeViewModel @Inject constructor( // Get the device ID of the device you want to retrieve data for (e.g., the first device in the list) private val _networkStatusLiveData = NetworkStatusLiveData(context) - val deviceData = MutableLiveData>() - val deviceIdToRetrieve = deviceData.value?.firstOrNull()?.deviceId + val deviceData = MutableLiveData() val networkStatusLiveData: LiveData get() = _networkStatusLiveData val fireBaseUpload = MutableLiveData() @@ -68,20 +68,10 @@ class HemoCubeViewModel @Inject constructor( } } - - - - fun getDeviceData() = viewModelScope.launch { - deviceIdToRetrieve?.let { deviceId -> - val deviceIdinfo = repository.getDeviceDataById(deviceId) - deviceData.postValue(listOf(deviceIdinfo!!)) - } + fun getDeviceData(deviceId: String) = viewModelScope.launch { + deviceData.postValue(repository.getDeviceDataById(deviceId)) } - - - - private fun addResultTestToDb() { testDetails?.deviceRatio = DataHolder.hemocubeResult testDetails?.resultData = DataHolder.hemoCubeTestData?.resultData.toString()