"""Schema for channel metrics endpoint.""" from marshmallow import fields from analytics.schemas.common import BaseSchema, SourceSchema class ChannelTrafficSourcesSubSchema(BaseSchema): """Marshmallow schema for traffic sources.""" source = fields.String() views = fields.Integer() premium_views = fields.Integer(data_key="premiumViews") average_view_duration_seconds = fields.Float(data_key="averageViewDurationSeconds") average_view_duration_percentage = fields.Float( data_key="averageViewDurationPercentage" ) watch_time_minutes = fields.Float(data_key="watchTimeMinutes") premium_watch_time_minutes = fields.Float(data_key="premiumWatchTimeMinutes") class ChannelTrafficSourcesSchema(BaseSchema): """Marshmallow schema for channel traffic sources.""" channel_id = fields.String() top_channel_traffic_sources = fields.Nested( nested=ChannelTrafficSourcesSubSchema, many=True ) sources = fields.Nested(SourceSchema, many=True)