1 /*
<lambda>null2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package platform.test.motion.golden
18 
19 /**
20  * A multivariate time series collected by a [MotionTestRule].
21  *
22  * A [TimeSeries] contains a number of distinct [Feature]s, each of which must contain exactly one
23  * [DataPoint] per [frameIds], in the same order.
24  */
25 data class TimeSeries(val frameIds: List<FrameId>, val features: Map<String, Feature<*>>) {
26 
27     constructor(
28         frameIds: List<FrameId>,
29         features: List<Feature<*>>
30     ) : this(frameIds, features.associateBy { it.name }) {
31         require(features.size == this.features.size) { "duplicate feature names" }
32     }
33 
34     init {
35         features.forEach { (key, feature) ->
36             require(key == feature.name)
37             require(feature.dataPoints.size == frameIds.size) {
38                 "Feature [$key] includes ${feature.dataPoints.size} data points, " +
39                     "but ${frameIds.size} data points are expected"
40             }
41         }
42     }
43 }
44 
45 sealed interface FrameId {
46     val label: String
47 }
48 
49 /**
50  * ID of recorded animation frame.
51  *
52  * [milliseconds] is relative to the recording start.
53  */
54 data class TimestampFrameId(val milliseconds: Long) : FrameId {
55     override val label: String
56         get() = "${milliseconds}ms"
57 }
58 
59 /** ID of UI frame before/after the animation. */
60 data class SupplementalFrameId(override val label: String) : FrameId
61 
62 /**
63  * Recorded [dataPoints], one per frame in the [TimeSeries].
64  *
65  * All [dataPoints] must be of the same [DataPointType].
66  */
67 data class Feature<out T>(
68     /** Test-specific, human readable name identifying the feature. */
69     val name: String,
70     /** Recorded data points of the feature. */
71     val dataPoints: List<DataPoint<T>>
72 )
73