From a985417f83d6e52a9e8593f1ca2024b173d2b022 Mon Sep 17 00:00:00 2001 From: dtookey Date: Tue, 5 Sep 2023 09:54:54 -0400 Subject: [PATCH] last change, promise --- src/main/kotlin/simulation/reporting/Metric.kt | 18 +++++++++--------- src/main/kotlin/simulation/reporting/Report.kt | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/simulation/reporting/Metric.kt b/src/main/kotlin/simulation/reporting/Metric.kt index 92d0d77..e79bf87 100644 --- a/src/main/kotlin/simulation/reporting/Metric.kt +++ b/src/main/kotlin/simulation/reporting/Metric.kt @@ -6,46 +6,46 @@ import kotlin.math.pow interface Metric { val metricName: String - fun mapToMetric(results: List): T + fun computeMetricFromResults(results: List): T - fun formatResults(result: T): String + fun formatResultLabel(result: T): String fun toResult(results: T): MetricResult { - return MetricResult(this.metricName, this.formatResults(results), results.toDouble()) + return MetricResult(this.metricName, this.formatResultLabel(results), results.toDouble()) } } private fun Boolean.toInt(): Int = if (this) 1 else 0 class AverageMetric(override val metricName: String, private val fieldMapFn: (AttackResult) -> Long) : Metric { - override fun mapToMetric(results: List): Double { + override fun computeMetricFromResults(results: List): Double { return results.map(fieldMapFn).average() } - override fun formatResults(result: Double): String { + override fun formatResultLabel(result: Double): String { return "$metricName: %.2f".format(result) } } class RateMetric(override val metricName: String, private val fieldMapFn: (AttackResult) -> Boolean) : Metric { - override fun mapToMetric(results: List): Double { + override fun computeMetricFromResults(results: List): Double { return results.map(fieldMapFn).map(Boolean::toInt).average() * 100.0 } - override fun formatResults(result: Double): String { + override fun formatResultLabel(result: Double): String { return "$metricName: %.2f".format(result) + "%" } } class StdDevMetric(override val metricName: String, private val fieldMapFn: (AttackResult) -> Long) : Metric { - override fun mapToMetric(results: List): Double { + override fun computeMetricFromResults(results: List): Double { val mean = results.map(fieldMapFn).average() return results.map(fieldMapFn).map { (it - mean).pow(2) }.average().pow(0.5) } - override fun formatResults(result: Double): String { + override fun formatResultLabel(result: Double): String { return "$metricName: %.2f".format(result) } diff --git a/src/main/kotlin/simulation/reporting/Report.kt b/src/main/kotlin/simulation/reporting/Report.kt index 95fe4d5..70b94ed 100644 --- a/src/main/kotlin/simulation/reporting/Report.kt +++ b/src/main/kotlin/simulation/reporting/Report.kt @@ -42,7 +42,7 @@ interface Report { fun computeResults(results: List): MetricReport { val m = ArrayList(metrics.size) metrics.forEach { - val value = it.mapToMetric(results) + val value = it.computeMetricFromResults(results) m.add(it.toResult(value)) } return MetricReport(name, m)