SRGSSR / pillarbox-android

The modern SRG SSR Pillarbox player targeting Android platforms
MIT License
12 stars 1 forks source link

Consolidate metrics management #625

Closed defagos closed 2 months ago

defagos commented 3 months ago

As a developer I need to get rid of the metrics gathering mess that my code has tuned into.

Hints

Specs: https://github.com/SRGSSR/pillarbox-documentation/issues/70

Acceptance criteria

Tasks

StaehliJ commented 3 months ago

Proposition

/**
 * Playback stats metrics
 * Role
 *  - Gather playback metrics, likes stalls, total play times.
 *  - Request metrics anytime.
 *  - Metrics are reset when current item is changed.
 */
class PlaybackStatsMetrics : PillarboxAnalyticsListener {

    private var stalls = 0

    override fun onStallChanged(eventTime: AnalyticsListener.EventTime, isStalls: Boolean) {
        stalls++
    }

    fun getCurrentMetrics(): Any? = null
}

class RemoteService {
    suspend fun send(payload: Any) {
        //ktor
    }
}

class LocalService {
    suspend fun store(entity: Any) {

    }

    suspend fun getNotSendData(): Any = Any()

}

interface QosSender {
    fun sendEvent(event: Any)
}

class QoS(
    remote: RemoteService,
    databaseService: LocalService,
)

class PillarboxQos(
    val timingMetrics: QoSSessionAnalyticsListener,
    val metrics: PlaybackStatsMetrics,
    val service: QosSender,
) : PillarboxAnalyticsListener {

    lateinit var sessionManager: PlaybackSessionManager

    override fun onStallChanged(eventTime: AnalyticsListener.EventTime, isStalls: Boolean) {
        val metrics = metrics.getCurrentMetrics()
        service.sendEvent(Any())
    }
}