Exemplo n.º 1
0
        private static void GetNonAdvertisingPlaylist(ChannelData channelData,
                                                      string password,
                                                      Playlist playlist,
                                                      DemographicRangeVerifier demographicRangeVerifier,
                                                      ChannelSubscriptions channelSubscriptions,
                                                      DateTime now,
                                                      float defaultDisplayDuration,
                                                      Logger logger)
        {
            //
            // calculate content playlist
            //
            // calculate average play times
            var avgPlayTimeQuery = from Channel channel in channelData.Channels
                                   join channelSubscription in channelSubscriptions.SubscriptionSet on channel.ChannelID equals channelSubscription.ChannelID
                                   from ChannelAsset channelAsset in channel.ChannelAssets
                                   group channelAsset by channel.ChannelID into groupedAssets
                                   select new
            {
                ChannelID       = groupedAssets.Key,
                AveragePlayTime = (float)groupedAssets.Average(channelAsset => channelAsset.DisplayDuration == -1F ? defaultDisplayDuration : channelAsset.DisplayDuration)
            };

            float sumAveragePlayTimes = 0F;

            foreach (var channel in avgPlayTimeQuery)
            {
                sumAveragePlayTimes += channel.AveragePlayTime;
            }

            // calculate playing probability of each channel
            var channelBuckets = HashSetLinqAccess.ToHashSet <ChannelBucket>(from ChannelSubscription channelSubscription in channelSubscriptions.SubscriptionSet
                                                                             join channel in avgPlayTimeQuery on channelSubscription.ChannelID equals channel.ChannelID
                                                                             join channelDataChannel in channelData.Channels on channel.ChannelID equals channelDataChannel.ChannelID
                                                                             select new ChannelBucket
            {
                ChannelID       = channel.ChannelID,
                ChannelName     = channelSubscription.ChannelName,
                AveragePlayTime = channel.AveragePlayTime,
                PlayingProbabilityUnnormalized = channel.AveragePlayTime > 0 && sumAveragePlayTimes > 0 ? (float)channelSubscription.ChannelWeightingUnnormalised / (channel.AveragePlayTime / sumAveragePlayTimes) : 0,
                ContentAssets = ConvertChannelAssetsToPlayListAssetsIfDateTimeDemoPermits(channelDataChannel, demographicRangeVerifier, now)
            });

            if (channelBuckets.Count == 0)
            {
                return;
            }

            playlist.ChannelBuckets = channelBuckets;

            // normalize playing probabilities
            NormalizeChannelBucketPlayingProbabilities(playlist.ChannelBuckets, logger);
        }
Exemplo n.º 2
0
        private static void GetAdvertisingPlaylist(string advertListPath, string demographicDataPath,
                                                   DemographicRangeVerifier demographicRangeVerifier, string password, Playlist playlist, ChannelData channelData,
                                                   ChannelSubscriptions channelSubscriptions, DateTime now, Logger logger)
        {
            // if the advertisment or the demographic data file is not found, an exception will be thrown
            // if user has corrupted any of the files, an exception will be thrown
            AdvertList advertList = (AdvertList)Serializer.Deserialize(typeof(AdvertList), advertListPath, password);

            // flatten channel definitions
            HashSet <string> channelDefinitions = new HashSet <string>();

            foreach (Channel channel in channelData.Channels)
            {
                SplitAndInsertChannelDefinitions(ref channelDefinitions, channel.ChannelDefinitions);
            }

            // flatten advert definitions
            HashSet <string> advertDefinitions = new HashSet <string>();

            foreach (AdvertAsset advertasset in advertList.Adverts)
            {
                SplitAndInsertChannelDefinitions(ref advertDefinitions, advertasset.AdvertDefinitions);
            }

            var advertListsFiltered = HashSetLinqAccess.ToHashSet <AdvertPlaylistAsset>(from AdvertAsset advertAsset in advertList.Adverts
                                                                                        where demographicRangeVerifier.IsAssetDemoSyntaxPlayable(advertAsset.DemoRequirements) &&
                                                                                        TreeSearch.IncludeByChannelClassifications(channelDefinitions, advertAsset.InclusionExclusionList) == true &&
                                                                                        TreeSearch.IncludeByAdvertClassifications(advertDefinitions, channelData, channelSubscriptions) == true &&
                                                                                        now >= advertAsset.StartDateTime &&
                                                                                        now <= advertAsset.EndDateTime
                                                                                        select new AdvertPlaylistAsset
            {
                AssetID               = advertAsset.AssetID,
                AssetFilename         = advertAsset.AssetFilename,
                ClickDestination      = advertAsset.ClickDestination,
                AssetWebSite          = advertAsset.AssetWebSite,
                PlayerType            = advertAsset.PlayerType,
                ScheduleInfo          = advertAsset.ScheduleInfo,
                DisplayLength         = advertAsset.DisplayDuration,
                WeightingUnnormalized = advertAsset.Weighting,
                StartDateTime         = advertAsset.StartDateTime,
                EndDateTime           = advertAsset.EndDateTime
            });

            playlist.AdvertBucket.AdvertAssets = advertListsFiltered;
        }