18
18
package tools.aqua.stars.core.metric.metrics.evaluation
19
19
20
20
import java.util.logging.Logger
21
+ import tools.aqua.stars.core.metric.metrics.utils.getNTimes
22
+ import tools.aqua.stars.core.metric.metrics.utils.plotDataAsLineChart
21
23
import tools.aqua.stars.core.metric.providers.Loggable
24
+ import tools.aqua.stars.core.metric.providers.Plottable
22
25
import tools.aqua.stars.core.metric.providers.ProjectionAndTSCInstanceNodeMetricProvider
23
26
import tools.aqua.stars.core.metric.providers.Stateful
24
27
import tools.aqua.stars.core.tsc.TSCInstance
@@ -28,14 +31,16 @@ import tools.aqua.stars.core.types.EntityType
28
31
import tools.aqua.stars.core.types.SegmentType
29
32
import tools.aqua.stars.core.types.TickDataType
30
33
34
+ const val VALID_TSC_INSTANCES_PER_PROJECTION_METRIC_NAME = " valid-tsc-instances-per-projection"
35
+
31
36
/* *
32
37
* This class implements the [ProjectionAndTSCInstanceNodeMetricProvider] and tracks the occurred
33
38
* valid [TSCInstance] for each [TSCProjection].
34
39
*/
35
40
class ValidTSCInstancesPerProjectionMetric <
36
41
E : EntityType <E , T , S >, T : TickDataType <E , T , S >, S : SegmentType <E , T , S >>(
37
- override val logger: Logger = Loggable .getLogger(" valid-tsc-instances-per-projection " )
38
- ) : ProjectionAndTSCInstanceNodeMetricProvider <E , T , S >, Stateful , Loggable {
42
+ override val logger: Logger = Loggable .getLogger(VALID_TSC_INSTANCES_PER_PROJECTION_METRIC_NAME )
43
+ ) : ProjectionAndTSCInstanceNodeMetricProvider <E , T , S >, Stateful , Loggable , Plottable {
39
44
/* *
40
45
* Map a [TSCProjection] to a map in which the occurrences of valid [TSCInstanceNode]s are stored:
41
46
* Map<projection,Map<referenceInstance,List<TSCInstance>>>
@@ -46,6 +51,13 @@ class ValidTSCInstancesPerProjectionMetric<
46
51
MutableMap <TSCInstanceNode <E , T , S >, MutableList <TSCInstance <E , T , S >>>> =
47
52
mutableMapOf ()
48
53
54
+ /* *
55
+ * Map a [TSCProjection] to a list of increasing counts of occurrences of valid [TSCInstanceNode]
56
+ * s. Map<projection,List<increasing count>>
57
+ */
58
+ private val uniqueTimedInstances: MutableMap <TSCProjection <E , T , S >, MutableList <Int >> =
59
+ mutableMapOf ()
60
+
49
61
/* *
50
62
* Track the valid [TSCInstance]s for each [TSCProjection] in the [validInstancesMap]. If the
51
63
* current [tscInstance] is invalid it is skipped.
@@ -55,11 +67,19 @@ class ValidTSCInstancesPerProjectionMetric<
55
67
*/
56
68
override fun evaluate (projection : TSCProjection <E , T , S >, tscInstance : TSCInstance <E , T , S >) {
57
69
validInstancesMap.putIfAbsent(projection, mutableMapOf ())
70
+ // Get current count of unique and valid TSC instance for the current projection
71
+ val projectionValidInstances = validInstancesMap.getValue(projection)
72
+
73
+ // Track current TSC instance even if it is not valid
74
+ uniqueTimedInstances.putIfAbsent(projection, mutableListOf ())
75
+ val projectionValidInstancesCount = uniqueTimedInstances.getValue(projection)
76
+ // Add current count of observed instances to list of timed instance counts
77
+ projectionValidInstancesCount.add(projectionValidInstances.size)
78
+
58
79
// Check if given tscInstance is valid
59
80
if (! projection.possibleTSCInstances.contains(tscInstance.rootNode)) {
60
81
return
61
82
}
62
- val projectionValidInstances = validInstancesMap.getValue(projection)
63
83
projectionValidInstances.putIfAbsent(tscInstance.rootNode, mutableListOf ())
64
84
// Get already observed instances for current projection
65
85
val projectionValidInstanceList = projectionValidInstances.getValue(tscInstance.rootNode)
@@ -96,4 +116,80 @@ class ValidTSCInstancesPerProjectionMetric<
96
116
}
97
117
}
98
118
}
119
+
120
+ override fun plotData () {
121
+ val xAxisName = " unique and valid TSC instances"
122
+ val yAxisName = " instance count"
123
+ val yAxisNamePercentage = " $yAxisName (in %)"
124
+ val plotFileName = " validTSCInstancesPerProjection"
125
+
126
+ val combinedXValues = mutableListOf<Int >()
127
+ val combinedYValues = mutableListOf<Int >()
128
+ val combinedYPercentageValues = mutableListOf<Float >()
129
+ val combinedLegendEntries = mutableListOf<String >()
130
+
131
+ uniqueTimedInstances.keys.forEach { projection ->
132
+ // Get list of timed instances for current projection. If not existing: return
133
+ val projectionTimedInstances = uniqueTimedInstances[projection] ? : return @forEach
134
+ val xValues: List <Int > = List (projectionTimedInstances.size) { it }
135
+ val possibleTscInstancesForProjection = projection.possibleTSCInstances.size
136
+ val lastYValue = projectionTimedInstances.last()
137
+ val legendEntries: List <String > =
138
+ getNTimes(
139
+ " ${projection.id} ($lastYValue /$possibleTscInstancesForProjection )" , xValues.size)
140
+
141
+ // Plot the timed absolute count of unique TSC instances for the current projection
142
+ plotDataAsLineChart(
143
+ xValues = xValues,
144
+ xAxisName = xAxisName,
145
+ yValues = projectionTimedInstances,
146
+ yAxisName = yAxisName,
147
+ legendEntries = legendEntries,
148
+ legendHeader = " Projection" ,
149
+ metricName = VALID_TSC_INSTANCES_PER_PROJECTION_METRIC_NAME ,
150
+ plotFileName = " ${plotFileName} _${projection.id} " ,
151
+ plotFileSubFolder = projection.id.toString())
152
+
153
+ // Plot the timed percentage count of unique TSC instances for the current projection
154
+ val yValuesPercentage: List <Float > =
155
+ projectionTimedInstances.map { (it.toFloat() / possibleTscInstancesForProjection) * 100 }
156
+ plotDataAsLineChart(
157
+ xValues = xValues,
158
+ xAxisName = xAxisName,
159
+ yValues = yValuesPercentage,
160
+ yAxisName = yAxisNamePercentage,
161
+ legendEntries = legendEntries,
162
+ legendHeader = " Projection" ,
163
+ metricName = VALID_TSC_INSTANCES_PER_PROJECTION_METRIC_NAME ,
164
+ plotFileName = " ${plotFileName} _${projection.id} _percentages" ,
165
+ plotFileSubFolder = projection.id.toString())
166
+
167
+ combinedXValues + = xValues
168
+ combinedYValues + = projectionTimedInstances
169
+ combinedLegendEntries + = legendEntries
170
+ combinedYPercentageValues + = yValuesPercentage
171
+ }
172
+
173
+ // Plot the timed absolute count of unique TSC instances for all projections combined
174
+ plotDataAsLineChart(
175
+ xValues = combinedXValues,
176
+ xAxisName = xAxisName,
177
+ yValues = combinedYValues,
178
+ yAxisName = yAxisName,
179
+ legendEntries = combinedLegendEntries,
180
+ legendHeader = " Projection" ,
181
+ metricName = VALID_TSC_INSTANCES_PER_PROJECTION_METRIC_NAME ,
182
+ plotFileName = " ${plotFileName} _combined" )
183
+
184
+ // Plot the timed percentage count of unique TSC instances for all projections combined
185
+ plotDataAsLineChart(
186
+ xValues = combinedXValues,
187
+ xAxisName = xAxisName,
188
+ yValues = combinedYPercentageValues,
189
+ yAxisName = yAxisNamePercentage,
190
+ legendEntries = combinedLegendEntries,
191
+ legendHeader = " Projection" ,
192
+ metricName = VALID_TSC_INSTANCES_PER_PROJECTION_METRIC_NAME ,
193
+ plotFileName = " ${plotFileName} _combined_percentage" )
194
+ }
99
195
}
0 commit comments