|
1 | 1 | import java.io.File |
| 2 | +import kotlin.sequences.flatMap |
2 | 3 | import kotlin.system.exitProcess |
3 | 4 |
|
4 | 5 | fun exit() { |
5 | 6 | println("arg1 is folder with csv's") |
6 | 7 | exitProcess(1) |
7 | 8 | } |
8 | 9 |
|
| 10 | +fun parseCsv(csvFile: File): List<Pair<String, Double>> { |
| 11 | + return csvFile.readLines() |
| 12 | + .filterNot { it.startsWith("\"Benchmark\"") } |
| 13 | + .map { it.split(",") } |
| 14 | + .map { it[0] to it[4].toDouble() } |
| 15 | +} |
| 16 | + |
| 17 | +fun parseJson(jsonFile: File): List<Pair<String, Double>> { |
| 18 | + val singleLineJson = jsonFile.readText().replace("\n", "") |
| 19 | + |
| 20 | + val benchmarks = Regex(".+?(\"benchmark\".+?scoreError)+.+?").findAll(singleLineJson).map { it.groupValues[1] }.toList() |
| 21 | + |
| 22 | + val benchmarkRegex = Regex("\"benchmark\"\\s:\\s(\".+?\").+?\"score\":\\s(.+?),.+") |
| 23 | + val benchmarkValues = benchmarks.map { |
| 24 | + benchmarkRegex.find(it)!!.groupValues |
| 25 | + } |
| 26 | + |
| 27 | + return benchmarkValues.map { |
| 28 | + it[1] to it[2].toDouble() |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | + |
9 | 33 | fun main(args: Array<String>) { |
10 | 34 | if (args.isEmpty()) exit() |
11 | 35 | val directory = File(args[0]) |
12 | 36 | if (!directory.exists()) exit() |
13 | 37 |
|
14 | | - directory |
| 38 | + val values = directory |
15 | 39 | .walk() |
16 | | - .filter { it.extension == "csv" } |
17 | | - .flatMap { it.readLines() } |
18 | | - .filterNot { it.startsWith("\"Benchmark\"") } |
19 | | - .map { it.split(",") } |
20 | | - .map { it[0] to it[4].toDouble() } |
| 40 | + .filter { it.extension == "json" } //csv |
| 41 | + .flatMap { file -> parseJson(file) } //parseCsv |
| 42 | + |
| 43 | + values |
21 | 44 | .groupBy({ it.first}, { it.second }) |
22 | 45 | .map { it.key to (it.value.minOf { x -> x } to it.value.maxOf { x -> x })} |
23 | 46 | .forEach { |
|
0 commit comments