diff --git a/app/src/main/java/com/example/refactoredapp/presentation/testRight/TestRightViewModel.kt b/app/src/main/java/com/example/hpos/presentation/testRight/TestRightViewModel.kt similarity index 85% rename from app/src/main/java/com/example/refactoredapp/presentation/testRight/TestRightViewModel.kt rename to app/src/main/java/com/example/hpos/presentation/testRight/TestRightViewModel.kt index 9cdc274..768d982 100644 --- a/app/src/main/java/com/example/refactoredapp/presentation/testRight/TestRightViewModel.kt +++ b/app/src/main/java/com/example/hpos/presentation/testRight/TestRightViewModel.kt @@ -12,6 +12,9 @@ import com.example.refactoredapp.domain.ResultCalculationWithMaxImpl import com.example.refactoredapp.domain.SaveRawData import com.example.refactoredapp.domain.TestRightResultCalculation import java.lang.Exception +import java.text.SimpleDateFormat +import java.util.* +import kotlin.collections.ArrayList import kotlin.math.log10 import kotlin.math.pow @@ -42,6 +45,7 @@ class TestRightViewModel : ViewModel() { val wavelengthToAbsorbance = ArrayList>() + val calculationVariableList = ArrayList() fun mapDeviceConstants(string: String) { Log.d(TAG, "mapDeviceConstants() called") @@ -71,13 +75,13 @@ class TestRightViewModel : ViewModel() { DataHolder.wavelengthToPixelArray.clear() if (DataHolder.deviceConstant != null) { for (x in 1..Constants.TEST_RIGHT_TOTAL_PIXEL) { - val index = x - 1 +// val index = x - 1 val wavelength: Double = - (DataHolder.deviceConstant!!.a.toDouble() * (index.toDouble() + (DataHolder.deviceConstant!!.a.toDouble() * (x.toDouble() .pow((3).toDouble()))) + - (DataHolder.deviceConstant!!.b.toDouble() * (index.toDouble() + (DataHolder.deviceConstant!!.b.toDouble() * (x.toDouble() .pow((2).toDouble()))) + - (DataHolder.deviceConstant!!.c.toDouble() * index) + + (DataHolder.deviceConstant!!.c.toDouble() * x) + (DataHolder.deviceConstant!!.d.toDouble()) DataHolder.wavelengthToPixelArray.add(wavelength) @@ -94,6 +98,18 @@ class TestRightViewModel : ViewModel() { if (isReference) DataHolder.intensityReferenceArray.clear() else intensitySampleArray.clear() + // Todo: Remove + var fileName: String = + "test_log_" + SimpleDateFormat("ddMMyyyy HHmmss").format(Date()) + ".txt" + fileName = if (isReference) { + "reference_$fileName" + } else { + "sample_$fileName" + } + saveLogTest(DataHolder.appFolderPath, fileName, isReference, fullString) + + Log.d(TAG, fullString) + val listOfString = fullString.split("\n") // Log.d(TAG, "inside mapIntensityValues() -> isReference = $isReference") @@ -107,7 +123,7 @@ class TestRightViewModel : ViewModel() { /* Removing trailing spaces and "Buf" from the string then taking lhs & rhs of ':' */ val numbers = line.trim() .substring(3).split(":") - Log.d(TAG, line) +// Log.d(TAG, line) if (numbers.size >= 2) { // val temp = ArrayList(2) // temp.add(numbers[0].toDouble()) @@ -164,6 +180,7 @@ class TestRightViewModel : ViewModel() { } wavelengthToAbsorbance.clear() + // Index pointing to last of the array // var indexInIntensityArrays = intensityReferenceArray.size - 1 // for ((index,wavelength) in wavelengthToPixelArray.withIndex()) { @@ -201,7 +218,16 @@ class TestRightViewModel : ViewModel() { temp.add(absorbance) wavelengthToAbsorbance.add(temp) -// indexInIntensityArrays-- + + // Todo: Remove + val calculationVariableForTest = CalculationVariableForTest() + calculationVariableForTest.pixelNo = index + 1 + calculationVariableForTest.invertedPixelNo = invertedPixelIndex+1 // 0-based indexing + calculationVariableForTest.wavelength = wavelength + calculationVariableForTest.I0 = i0 + calculationVariableForTest.I = i1 + calculationVariableForTest.absorbance = absorbance + calculationVariableList.add(calculationVariableForTest) } } @@ -222,8 +248,21 @@ class TestRightViewModel : ViewModel() { SaveRawData().saveCsv(folderPath, filename, wavelengthToAbsorbance) } + fun saveCsvForTesting(folderPath: String, filename: String) { + SaveRawDataTest().saveCsv(folderPath, filename, calculationVariableList) + } + fun saveLog(appFolderPath: String, fileName: String) { SaveRawData().saveLog(appFolderPath, fileName, calculationData) } + fun saveLogTest( + appFolderPath: String, + fileName: String, + isReference: Boolean, + fullString: String + ) { + SaveRawDataTest().saveLog(appFolderPath, fileName, isReference, fullString) + } + } \ No newline at end of file