Skip to content

Instantly share code, notes, and snippets.

@gregorriegler
Last active January 28, 2021 19:46
Show Gist options
  • Save gregorriegler/5c4295873519e13e02e467c6cef318c1 to your computer and use it in GitHub Desktop.
Save gregorriegler/5c4295873519e13e02e467c6cef318c1 to your computer and use it in GitHub Desktop.
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