<commit_before>external fun car_sonar_init()
external fun car_sonar_get_dist(degree: Byte): Short

object Sonar {
    private var ATTEMPTS_COUNT = 5
    private var DEVIATION = 10
    private var SCAN_STEP = 1

    fun init() {
        car_sonar_init()
    }

    fun getDistance(angle: Int): Int {
        return car_sonar_get_dist(angle.toByte()).toInt()
    }

    fun getSmoothDistance(angle: Int): Int {
        val distance = getDistance(angle)
        if (distance != -1) {
            return distance
        }

        val start = if (angle - DEVIATION < 0) 0 else angle - DEVIATION
        return getOneOfRange(start, angle + DEVIATION, SCAN_STEP)
    }

    fun getOneOfRange(start: Int, stop: Int, step: Int): Int {
        var i = start
        var distance = getDistance(start)
        while (i <= stop && distance == -1) {
            distance = getDistance(i)

            i += step
        }

        return distance
    }

    fun calibrate() {
        getDistance(180)
    }
}<commit_msg>car_fmw: multiple attempts when scan failing<commit_after>external fun car_sonar_init()
external fun car_sonar_get_dist(degree: Byte): Short

object Sonar {
    private var ATTEMPTS_COUNT = 5
    private var DEVIATION = 10
    private var SCAN_STEP = 1

    fun init() {
        car_sonar_init()
    }

    fun getDistance(angle: Int): Int {
        return car_sonar_get_dist(angle.toByte()).toInt()
    }

    fun getSmoothDistance(angle: Int): Int {
        val distance = getDistance(angle)
        if (distance != -1) {
            return distance
        }

        val start = if (angle - DEVIATION < 0) 0 else angle - DEVIATION
        return getOneOfRange(start, angle + DEVIATION, SCAN_STEP)
    }

    fun getOneOfRange(start: Int, stop: Int, step: Int): Int {
        var i = start
        var distance = getDistance(start)
        while (i <= stop && distance == -1) {
            distance = getDistance(i)
            i += step
        }

        while (i >= start && distance == -1) {
            distance = getDistance(i)
            i -= step
        }

        return distance
    }

    fun calibrate() {
        getDistance(180)
    }
}
{'fraction_non_alphanumeric': 0.09759481961147086, 'fraction_numerical': 0.010638297872340425, 'mean_word_length': 2.0294117647058822, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4199675', 'n_tokens_mistral': 691, 'n_tokens_neox': 653, 'n_words': 186}