using System; using System.Collections.Generic; using System.Linq; using Nancy; using Newtonsoft.Json; using Sony.Filtr.AppleMusic; using Sony.Filtr.Contracts.Abstractions; using Sony.Filtr.Utility; using Sony.Filtr.Utility.Serialization; namespace Sony.Filtr.AdminAPI.Modules.AppleMusic { public class AppleMusicTrackStreamsModule : BaseModule { public AppleMusicTrackStreamsModule(IApplicationInstanceManager applicationInstanceManager, AppleMusicTrackStreamsManager appleMusicTrackStreamsManager) : base(applicationInstanceManager) { Get["GetAppleMusicAnalyticsTrackDemographics", "/appleMusic/analytics/track/demographics", true] = async (parameters, cx) => { DateTime startDate = Maybe.ToDateTimeOrFallback((string)Request.Query.startDate, DateTime.Today.AddDays(-30)); DateTime endDate = Maybe.ToDateTimeOrFallback((string)Request.Query.endDate, DateTime.Today); string countryCode = (string)Request.Query.countryCode; var isrcParameter = (string)Request.Query.isrc; var isrcs = isrcParameter?.Split(',').ToList(); if (isrcs == null || !isrcs.Any()) return HttpStatusCode.BadRequest; var demographics = await appleMusicTrackStreamsManager.GetTrackStreamDemographicsAsync(isrcs, startDate, endDate, countryCode); var viewModels = AutoMapper.Mapper.Instance.Map>(demographics); return Response.AsJson(viewModels); }; Get["GetAppleMusicAnalyticsTrackStreams", "/appleMusic/analytics/track/streams", true] = async (parameters, cx) => { DateTime startDate = Maybe.ToDateTimeOrFallback((string)Request.Query.startDate, DateTime.Today.AddDays(-30)); DateTime endDate = Maybe.ToDateTimeOrFallback((string)Request.Query.endDate, DateTime.Today); string countryCode = (string)Request.Query.countryCode; var isrcParameter = (string)Request.Query.isrc; var isrcs = isrcParameter?.Split(',').ToList(); if (isrcs == null || !isrcs.Any()) return HttpStatusCode.BadRequest; var streams = await appleMusicTrackStreamsManager.GetTrackStreamAsync(isrcs, startDate, endDate, countryCode); var viewModels = AutoMapper.Mapper.Instance.Map>(streams); return Response.AsJson(viewModels); }; Get["GetAppleMusicAnalyticsTrackStreamContainer", "/appleMusic/analytics/trackContainer/streams", true] = async (parameters, cx) => { DateTime startDate = Maybe.ToDateTimeOrFallback((string)Request.Query.startDate, DateTime.Today.AddDays(-30)); DateTime endDate = Maybe.ToDateTimeOrFallback((string)Request.Query.endDate, DateTime.Today); string countryCode = (string)Request.Query.countryCode; var isrc = (string)Request.Query.isrc; var containerId = (string)Request.Query.containerId; if (string.IsNullOrWhiteSpace(isrc) || string.IsNullOrWhiteSpace(containerId)) return HttpStatusCode.BadRequest; var streams = await appleMusicTrackStreamsManager.GetTrackContainerStreamAsync(isrc, containerId, startDate, endDate, countryCode); var viewModels = AutoMapper.Mapper.Instance.Map>(streams); return Response.AsJson(viewModels); }; } } public class AppleMusicTrackStreamViewModel { [JsonConverter(typeof(DateNoTimeConverter))] public DateTime Date { get; set; } public string CountryCode { get; set; } public string ReportVendorId { get; set; } public string Isrc { get; set; } public DateTime ReportDate { get; set; } public long ActionType1 { get; set; } public long ContainerSubtype0 { get; set; } public long ContainerSubtype1 { get; set; } public long ContainerSubtype10 { get; set; } public long ContainerSubtype11 { get; set; } public long ContainerSubtype2 { get; set; } public long ContainerSubtype3 { get; set; } public long ContainerSubtype4 { get; set; } public long ContainerSubtype5 { get; set; } public long ContainerSubtype6 { get; set; } public long ContainerSubtype7 { get; set; } public long ContainerSubtype8 { get; set; } public long ContainerSubtype9 { get; set; } public long ContainerType0 { get; set; } public long ContainerType1 { get; set; } public long ContainerType2 { get; set; } public long ContainerType3 { get; set; } public long ContainerType4 { get; set; } public long DeviceOs0 { get; set; } public long DeviceOs1 { get; set; } public long DeviceOs2 { get; set; } public long DeviceOs3 { get; set; } public long DeviceOs4 { get; set; } public long DeviceOs5 { get; set; } public long DeviceOs6 { get; set; } public long DeviceType0 { get; set; } public long DeviceType1 { get; set; } public long DeviceType2 { get; set; } public long EndReason0 { get; set; } public long EndReason1 { get; set; } public long EndReason2 { get; set; } public long Offline0 { get; set; } public long Offline1 { get; set; } public long Source0 { get; set; } public long Source1 { get; set; } public long Source2 { get; set; } public long Source3 { get; set; } public long Source4 { get; set; } public long Streams { get; set; } } public class AppleMusicTrackContainerStreamViewModel { [JsonConverter(typeof(DateNoTimeConverter))] public DateTime Date { get; set; } public string CountryCode { get; set; } public string Isrc { get; set; } public string ContainerId { get; set; } public string ContainerName { get; set; } public string ContainerSubType { get; set; } public long ActionType1 { get; set; } public long ContainerType0 { get; set; } public long ContainerType1 { get; set; } public long ContainerType2 { get; set; } public long ContainerType3 { get; set; } public long ContainerType4 { get; set; } public long DeviceOs0 { get; set; } public long DeviceOs1 { get; set; } public long DeviceOs2 { get; set; } public long DeviceOs3 { get; set; } public long DeviceOs4 { get; set; } public long DeviceOs5 { get; set; } public long DeviceOs6 { get; set; } public long DeviceType0 { get; set; } public long DeviceType1 { get; set; } public long DeviceType2 { get; set; } public long EndReason0 { get; set; } public long EndReason1 { get; set; } public long EndReason2 { get; set; } public long Offline0 { get; set; } public long Offline1 { get; set; } public long Source0 { get; set; } public long Source1 { get; set; } public long Source2 { get; set; } public long Source3 { get; set; } public long Source4 { get; set; } public long Streams { get; set; } } public class AppleMusicTrackDemographicsViewModel { [JsonConverter(typeof(DateNoTimeConverter))] public DateTime Date { get; set; } public string CountryCode { get; set; } public string ISRC { get; set; } public DateTime ReportDate { get; set; } public int StreamsGenderFemaleAge0_17 { get; set; } public int StreamsGenderMaleAge0_17 { get; set; } public int StreamsGenderUnknownAge0_17 { get; set; } public int StreamsGenderFemaleAge18_24 { get; set; } public int StreamsGenderMaleAge18_24 { get; set; } public int StreamsGenderUnknownAge18_24 { get; set; } public int StreamsGenderFemaleAge25_34 { get; set; } public int StreamsGenderMaleAge25_34 { get; set; } public int StreamsGenderUnknownAge_25_34 { get; set; } public int StreamsGenderFemaleAge35_44 { get; set; } public int StreamsGenderMaleAge35_44 { get; set; } public int StreamsGenderUnknownAge35_44 { get; set; } public int StreamsGenderFemaleAge45_54 { get; set; } public int StreamsGenderMaleAge45_54 { get; set; } public int StreamsGenderUnknownAge45_54 { get; set; } public int StreamsGenderFemaleAge55_64 { get; set; } public int StreamsGenderMaleAge55_64 { get; set; } public int StreamsGenderUnknownAge55_64 { get; set; } public int StreamsGenderFemaleAge60_plus { get; set; } public int StreamsGenderMaleAge60_plus { get; set; } public int StreamsGenderUnknownAge60_plus { get; set; } public int StreamsGenderFemaleAgeUnknown { get; set; } public int StreamsGenderMaleAgeUnknown { get; set; } public int StreamsGenderUnknownAgeUnknown { get; set; } } }