Update in saving the csv. Sorting the data in aesc order and only taking the values between the specified range. Also adding the headers. [Working]

This commit is contained in:
vsuryakumar
2023-02-02 16:33:32 +05:30
parent 2c74675d3d
commit 92f1739c3f
2 changed files with 17 additions and 2 deletions

View File

@@ -16,6 +16,9 @@ object Constants {
const val WAVELENGTH_OF_INTEREST_ONE = 427
const val WAVELENGTH_OF_INTEREST_TWO = 555
const val MIN_WAVELENGTH_RANGE_TO_RECORD = 350
const val MAX_WAVELENGTH_RANGE_TO_RECORD = 750
const val DEVICE_PRODUCT_ID = 24597
const val DEVICE_VENDOR_ID = 1027
}

View File

@@ -1,9 +1,11 @@
package com.example.hpos.domain
import com.example.hpos.data.constant.Constants
import com.example.hpos.data.model.TestRightCalculationData
import com.opencsv.CSVWriter
import java.io.File
import java.io.FileWriter
import java.util.Collections.sort
class SaveRawData {
@@ -11,12 +13,22 @@ class SaveRawData {
val fullPath = "$folderPath/$fileName"
val writer = CSVWriter(FileWriter(fullPath))
sort(matrix) { one: ArrayList<Double>, two: ArrayList<Double> ->
one[0].compareTo(two[0])
}
val content = ArrayList<Array<String>>()
content.add(arrayOf("NM", "CA"))
for (eachRow in matrix){
if (eachRow[0] >= Constants.MIN_WAVELENGTH_RANGE_TO_RECORD && eachRow[0] < Constants.MAX_WAVELENGTH_RANGE_TO_RECORD+1) {
// val rowContent = arrayOf(String.format("%.3f", eachRow[0]), String.format("%.3f", eachRow[1]))
val rowContent = arrayOf(String.format("%.10f", eachRow[0]), String.format("%.10f", eachRow[1]))
content.add(rowContent)
val rowContent =
arrayOf(String.format("%.10f", eachRow[0]), String.format("%.10f", eachRow[1]))
content.add(rowContent)
}
}
writer.writeAll(content) // data is adding to csv