<commit_before>package com.rimmer.metrics

import com.rimmer.metrics.generated.type.*

/** A metrics sender that writes to stdout. */
class ConsoleSender: Sender {
    override fun sendProfile(profile: ProfilePacket) {
        println("Profile of path ${profile.path} at ${profile.time}:")
        println("   start at ${profile.start}")
        for(e in profile.events) {
            println("   event in ${e.event} (${e.type.take(50)}) at ${e.startTime} (duration ${(e.endTime - e.startTime) / 1000000.0} ms)")
        }

        println("   end at ${profile.end} (total duration: ${(profile.end - profile.start) / 1000000.0} ms)")
    }

    override fun sendStatistic(stat: StatPacket) {
        println("Stats for path ${stat.path} at ${stat.time} over ${stat.intervals.size} calls:")
        if(stat.intervals.isNotEmpty()) {
            println("   average time: ${stat.totalElapsed / stat.intervals.size / 1000000.0} ms")
            println("   median time: ${percentile(stat.intervals, 0.5) / 1000000.0} ms")
            println("   95th percentile: ${percentile(stat.intervals, 0.95) / 1000000.0} ms")
            println("   99th percentile: ${percentile(stat.intervals, 0.99) / 1000000.0} ms")
            println("   min time: ${percentile(stat.intervals, 0.0) / 1000000.0} ms")
            println("   max time: ${percentile(stat.intervals, 1.0) / 1000000.0} ms")
        }
    }

    override fun sendError(error: ErrorPacket) {
        println("An error occurred in the path ${error.path} at ${error.time}:")
        println(error.cause)
    }

    fun percentile(intervals: List<Interval>, percentile: Double): Long {
        val e = intervals[Math.ceil((intervals.size - 1) * percentile).toInt()]
        return e.end - e.start
    }
}<commit_msg>Update metrics console sender<commit_after>package com.rimmer.metrics

import com.rimmer.metrics.generated.type.*

/** A metrics sender that writes to stdout. */
class ConsoleSender: Sender {
    override fun sendProfile(profile: ProfilePacket) {
        println("Profile of path ${profile.location} at ${profile.time}:")
        println("   start at ${profile.start}")
        for((type, description, startTime, endTime) in profile.events) {
            println("   $startTime [${(endTime - startTime) / 1000000.0} ms] $type")
            println("       $description")
        }

        println("   end at ${profile.end} (total duration: ${(profile.end - profile.start) / 1000000.0} ms)")
    }

    override fun sendStatistic(stat: StatPacket) {
        println("Stats for path ${stat.location} at ${stat.time} over ${stat.sampleCount} calls:")
        println("   average time: ${stat.total / stat.sampleCount / 1000000.0} ms")
        println("   median time: ${stat.median / 1000000.0} ms")
        println("   95th percentile: ${stat.average95 / 1000000.0} ms")
        println("   99th percentile: ${stat.average99 / 1000000.0} ms")
        println("   min time: ${stat.min / 1000000.0} ms")
        println("   max time: ${stat.max / 1000000.0} ms")
    }

    override fun sendError(error: ErrorPacket) {
        println("An error occurred in the path ${error.location} at ${error.time}:")
        println(error.cause)
    }
}
{'fraction_non_alphanumeric': 0.15048392132375898, 'fraction_numerical': 0.048392132375897595, 'mean_word_length': 2.7473684210526317, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6806920', 'n_tokens_mistral': 1116, 'n_tokens_neox': 941, 'n_words': 257}