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)