<commit_before>package org.team2471.frc.lib.motion_profiling

import edu.wpi.first.wpilibj.networktables.NetworkTable
import edu.wpi.first.wpilibj.tables.ITable

private fun Path2DPoint.remainingPoints(): List<Path2DPoint> {
    val result = ArrayList<Path2DPoint>()

    var currentPoint = this
    while (true) {
        result.add(currentPoint)
        currentPoint = currentPoint.nextPoint
        if (currentPoint == null) break
    }

    return result
}

private fun MotionKey.remainingKeys(): List<MotionKey> {
    val result = ArrayList<MotionKey>()

    var currentKey = this
    while (true) {
        result.add(currentKey)
        currentKey = currentKey.nextKey
        if (currentKey == null) break
    }

    return result
}

private fun Path2D.dumpToTable(table: ITable) {
    table.putStringArray("XyCurvePoints", when (this.xyCurve.headPoint) {
        null -> emptyArray()
        else -> this.xyCurve.headPoint.remainingPoints().map { point ->
            point.toString()
        }.toTypedArray()
    })

    table.putStringArray("EaseCurveKeys", when (this.easeCurve.headKey) {
        null -> emptyArray()
        else -> this.easeCurve.headKey.remainingKeys().map { point ->
            point.toString()
        }.toTypedArray()
    })

    // make sure all values are persistent
    table.setPersistent("XyCurvePoints")
    table.setPersistent("EaseCurveKeys")
}

internal val pathVisualizerTable = NetworkTable.getTable("PathVisualizer")

class SharedAutonomousConfig(val name: String) {
    companion object {
        private val configTable = pathVisualizerTable.getSubTable("Configs")

        val configNames: Set<String>
            get() = configTable.subTables
                    .filterNotNull()
                    .toSet()
    }

    private val paths: MutableMap<String, Path2D> = HashMap()
    private val table = configTable.getSubTable(name)
    private val pathsTable = table.getSubTable("Paths")

    fun putPath(pathName: String, path: Path2D) = paths.put(pathName, path)

    fun getPath(pathName: String): Path2D? = paths[pathName]

    fun deletePath(pathName: String) = paths.remove(pathName)

    fun renamePath(prevPathName: String, newPathName: String) = paths.put(newPathName, paths.remove(prevPathName)!!)<commit_msg>Update SharedAutonomousConfig confignames and pathnames<commit_after>package org.team2471.frc.lib.motion_profiling

import edu.wpi.first.wpilibj.networktables.NetworkTable
import edu.wpi.first.wpilibj.tables.ITable
import java.util.*

private fun Path2DPoint.remainingPoints(): List<Path2DPoint> {
    val result = ArrayList<Path2DPoint>()

    var currentPoint = this
    while (true) {
        result.add(currentPoint)
        currentPoint = currentPoint.nextPoint
        if (currentPoint == null) break
    }

    return result
}

private fun MotionKey.remainingKeys(): List<MotionKey> {
    val result = ArrayList<MotionKey>()

    var currentKey = this
    while (true) {
        result.add(currentKey)
        currentKey = currentKey.nextKey
        if (currentKey == null) break
    }

    return result
}

private fun Path2D.dumpToTable(table: ITable) {
    table.putStringArray("XyCurvePoints", when (this.xyCurve.headPoint) {
        null -> emptyArray()
        else -> this.xyCurve.headPoint.remainingPoints().map { point ->
            point.toString()
        }.toTypedArray()
    })

    table.putStringArray("EaseCurveKeys", when (this.easeCurve.headKey) {
        null -> emptyArray()
        else -> this.easeCurve.headKey.remainingKeys().map { point ->
            point.toString()
        }.toTypedArray()
    })

    // make sure all values are persistent
    table.setPersistent("XyCurvePoints")
    table.setPersistent("EaseCurveKeys")
}

internal val pathVisualizerTable = NetworkTable.getTable("PathVisualizer")

class SharedAutonomousConfig(val name: String) {
    companion object {
        private val configTable = pathVisualizerTable.getSubTable("Configs")

        val configNames: Array<String>
            get() = configTable.subTables
                    .filterNotNull()
                    .toTypedArray()
    }

    private val paths: MutableMap<String, Path2D> = HashMap()
    private val table = configTable.getSubTable(name)
    private val pathsTable = table.getSubTable("Paths")


    val pathNames: Array<String>
        get() = pathsTable.subTables
                .filterNotNull()
                .toTypedArray()

    fun putPath(pathName: String, path: Path2D) = paths.put(pathName, path)

    fun getPath(pathName: String): Path2D? = paths[pathName]

    fun deletePath(pathName: String) = paths.remove(pathName)

    fun renamePath(prevPathName: String, newPathName: String) = paths.put(newPathName, paths.remove(prevPathName)!!)
{'fraction_non_alphanumeric': 0.1065487471046536, 'fraction_numerical': 0.004632554221941461, 'mean_word_length': 3.066780821917808, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 28, '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': '1376662', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1397, 'n_words': 288}