Last active
January 28, 2021 19:46
-
-
Save gregorriegler/5c4295873519e13e02e467c6cef318c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import java.time.Duration | |
import java.time.LocalDateTime | |
import java.time.format.DateTimeFormatter | |
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS") | |
fun main() { | |
File("log.txt") | |
.readLines() | |
.asSequence() | |
.withIndex() | |
.filter { it.value.startsWith('[') } | |
.map { Pair(it.index + 1, LocalDateTime.parse(it.value.substring(1, 24), formatter)) } | |
.windowed(6, 2) | |
.map { Pair(lineSet(it), Duration.between(it.last().second, it.first().second)) } | |
.sortedBy { it.second } | |
.take(25) | |
.toList() | |
.forEach { println(it) } | |
} | |
private fun lineSet(it: List<Pair<Int, LocalDateTime>>) = | |
"" + it.first().first + "-" + it.last().first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment