-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.kt
48 lines (36 loc) · 1.28 KB
/
Helper.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.io.File
import java.io.FileInputStream
object Helper {
private const val BASE_PATH = "../resources/"
private lateinit var indexesMapped: Map<String, Int>
fun summaryReport(
newLine: List<String>,
selectedColumns: ArrayList<Int>,
columnsMapped: Map<String, Int> = indexesMapped,
report: Report): Report {
val sum = hashMapOf<String, Float>()
val mean = hashMapOf<String, Float>()
report.sum = sum
report.mean = mean
return report
}
fun createFileInputStream(basePath: String = BASE_PATH, filePath: String): FileInputStream {
val file = File(basePath + filePath)
return FileInputStream(file)
}
fun indexesFromSelectedColumns(headerLine: String, selectedColumns: String, delimiter: String): ArrayList<Int> {
indexesMapped = mapIndex(headerLine.split(delimiter))
val indexes = arrayListOf<Int>()
selectedColumns.split(delimiter).forEach { column ->
indexesMapped[column]?.let { indexes.add(it) }
}
return indexes
}
private fun mapIndex(line: List<String>): Map<String, Int> {
var index = 0
val map = line.map {item ->
Pair(item, index++)
}
return map.toMap()
}
}