Skip to content

Commit

Permalink
Export now prints relative time as first column
Browse files Browse the repository at this point in the history
  • Loading branch information
franksn90 committed May 29, 2024
1 parent 5277682 commit b024dca
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 203 deletions.
12 changes: 10 additions & 2 deletions src/main/kotlin/cambio/monitoring/mosim/export/CSVFileExporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.FileReader

class CSVFileExporter(private val monitoringCSVLoc: String, private val config: SearchConfiguration) : Exporter {
private val columnSeparator: String = ","
private val relativeTeamHeader = "time_relative"

private data class MonitoringData(
val headers: String,
Expand All @@ -24,7 +25,7 @@ class CSVFileExporter(private val monitoringCSVLoc: String, private val config:
val endValue = occurrence.value.second.time
val (startIndex, endIndex) = findIndices(startValue, endValue, monitoringData)
val writer = prepareOutputFile(occurrence.index)
writeMonitoringData(startIndex, endIndex, monitoringData, writer)
writeMonitoringData(startValue, startIndex, endIndex, monitoringData, writer)
}
}

Expand Down Expand Up @@ -73,15 +74,22 @@ class CSVFileExporter(private val monitoringCSVLoc: String, private val config:
}

private fun writeMonitoringData(
startValue: Double,
startIndex: Int,
endIndex: Int,
monitoringData: MonitoringData,
writer: BufferedWriter
) {
writer.write(monitoringData.headers)
writer.write(relativeTeamHeader + columnSeparator + monitoringData.headers)
val endIndexInclusive = (endIndex + 1).coerceAtMost(monitoringData.data.size)
for (line in monitoringData.data.subList(startIndex, endIndexInclusive)) {
val valueInLine = line.split(columnSeparator)
val time = valueInLine[0].toDouble()
val relativeTime = time - startValue

writer.newLine()
writer.write(relativeTime.toString())
writer.write(columnSeparator)
writer.write(line)
}
writer.close()
Expand Down
Loading

0 comments on commit b024dca

Please sign in to comment.