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); }
public void IsAssetDemoSyntaxPlayableTest() { DemographicData demographicData = null; DemographicRangeVerifier target = new DemographicRangeVerifier(demographicData); string[] inputConditionCollection = null; bool expected = false; bool actual; actual = target.IsAssetDemoSyntaxPlayable(inputConditionCollection); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
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; }
public void IsAssetDemoSyntaxPlayableIndividualLineTestSuccessfulConditionsInclude() { DemographicData demographicData = new DemographicData(); demographicData.SocioEconomicgroup = new string[] { "a1", "a2" }; demographicData.MaxAge = 35; demographicData.MinAge = 30; demographicData.GeoDefinition = "0.1.2"; demographicData.Gender = new string[] { "male" }; DemographicRangeVerifier demographicRangeVerifier = new DemographicRangeVerifier(demographicData); PrivateObject demographicRangeVerifierPrivate = new PrivateObject(demographicRangeVerifier); DemographicRangeVerifier_Accessor target = new DemographicRangeVerifier_Accessor(demographicRangeVerifierPrivate); string ie = "age=34 and gender=male,female and socioeconomicgroup=a3,a2"; bool expected = true; bool actual; actual = target.IsAssetDemoSyntaxPlayableIndividualLine(ie); Assert.AreEqual(expected, actual); }
public void IsAssetPlayableIndividualLineTestLeadingTrailingConjunction() { DemographicData demographicData = null; DemographicRangeVerifier demographicRangeVerifier = null; demographicData = new DemographicData(); demographicData.SocioEconomicgroup = new string[] { "a1", "a2" }; demographicData.MaxAge = 30; demographicData.MinAge = 20; demographicData.GeoDefinition = "0.1.2"; demographicData.Gender = new string[] { "Male" }; demographicRangeVerifier = new DemographicRangeVerifier(demographicData); PrivateObject demographicRangeVerifierPrivate = new PrivateObject(demographicRangeVerifier); DemographicRangeVerifier_Accessor target = new DemographicRangeVerifier_Accessor(demographicRangeVerifierPrivate); bool expected = false; bool actual; actual = target.IsAssetDemoSyntaxPlayableIndividualLine("age=20 and gender=male,female and socioeconomicgroup=a3,a2"); Assert.AreEqual(expected, actual, "Verify the correctness of this test method."); }
public void IsAssetDemoSyntaxPlayableTestSuccessfulConditionsExcludeIncludeSameMet() { DemographicData demographicData = new DemographicData(); demographicData.SocioEconomicgroup = new string[] { "a1", "a2" }; demographicData.MaxAge = 35; demographicData.MinAge = 30; demographicData.GeoDefinition = "0.1.2"; demographicData.Gender = new string[] { "male" }; DemographicRangeVerifier demographicRangeVerifier = new DemographicRangeVerifier(demographicData); string[] inputConditionCollection = new string[3]; inputConditionCollection[0] = "age > 30 and gender=male and socioeconomicgroup=a2 and geo=0.1"; // will be met and excluded inputConditionCollection[1] = "age > 30 and gender=male and socioeconomicgroup=a2 and geo=0.1"; // will be met and excluded inputConditionCollection[2] = "age > 35 and gender=male and socioeconomicgroup=a2 and geo=0.3"; // will be not met and included bool expected = true; bool actual; actual = demographicRangeVerifier.IsAssetDemoSyntaxPlayable(inputConditionCollection); Assert.AreEqual(expected, actual, "Verify the correctness of this test method."); }
/// <summary> /// Creates the playlist for the user /// </summary> /// <param name="channelDataPath">Directory on the end user's computer where channel content files reside</param> /// <param name="advertListPath">Fully qualified path of the advert list file on the end user's computer</param> /// <param name="demographicDataPath">Fully qualified path of the demographic data path on the end user's computer</param> /// <param name="playlistDataPath">Fully qualified path on the end user's computer to save the playlist to</param> /// <param name="password">Encryption password</param> /// <param name="channelSubscriptions">ChannelSubscriptions object with the user's channel subscriptions</param> /// <param name="logger">Logger to log debug/error messages</param> /// <exception cref="System.Runtime.Serialization.SerializationException">Thrown when an error occurs during serialization/deserializaton</exception> /// <exception cref="InvalidOperationException">Thrown when file to be serialized don't match the deserializer's expected type</exception> /// <exception cref="DirectoryNotFoundException">thrown when directory to save or load a file from is not found</exception> /// <exception cref="FileNotFoundException">thrown when a file is not found</exception> /// <exception cref="CryptographicException">thrown when a serialized file is corrupted</exception> public static Playlist CreatePlaylist(string channelDataPath, string advertListPath, string demographicDataPath, string playlistDataPath, string password, float defaultDisplayDuration, ChannelSubscriptions channelSubscriptions, Logger logger) { Playlist playlist = new Playlist(); // holds the channels to which the user is subscribed ChannelData channelData = new ChannelData(); // check if channel data directory exists! if (!Directory.Exists(channelDataPath)) { return(null); } string[] fileEntries = Directory.GetFiles(channelDataPath, "*.dat"); if (channelSubscriptions.SubscriptionSet.Count == 0 || fileEntries.Length == 0) { return(playlist); } foreach (string file in fileEntries) { channelData.Channels.Add((Channel)Serializer.Deserialize(typeof(Channel), file, "password")); } if (!File.Exists(demographicDataPath)) { return(null); } DateTime now = DateTime.Now; DemographicData demographicData = (DemographicData)Serializer.Deserialize(typeof(DemographicData), demographicDataPath, password); DemographicRangeVerifier demographicRangeVerifier = new DemographicRangeVerifier(demographicData); GetNonAdvertisingPlaylist(channelData, password, playlist, demographicRangeVerifier, channelSubscriptions, now, defaultDisplayDuration, logger); // advertising playlist GetAdvertisingPlaylist(advertListPath, demographicDataPath, demographicRangeVerifier, password, playlist, channelData, channelSubscriptions, now, logger); Serializer.Serialize(playlist, playlistDataPath, password); return(playlist); }
/// <summary> /// Creates a HashSet of assets to be included in the user's playlist. /// Uses the Channel's ChannelAsset HashSet. /// </summary> /// <returns>a HashSet of PlayListAsset objects</returns> private static HashSet <ContentPlaylistAsset> ConvertChannelAssetsToPlayListAssetsIfDateTimeDemoPermits(Channel channel, DemographicRangeVerifier demographicRangeVerifier, DateTime now) { HashSet <ContentPlaylistAsset> playlistAssets = new HashSet <ContentPlaylistAsset>(); ContentPlaylistAsset playlistAsset = null; foreach (ChannelAsset chAsset in channel.ChannelAssets) { if (now >= chAsset.StartDateTime && now <= chAsset.EndDateTime && demographicRangeVerifier.IsAssetDemoSyntaxPlayable(chAsset.DemoRequirements)) { playlistAsset = new ContentPlaylistAsset { AssetID = chAsset.AssetID, AssetFilename = chAsset.AssetFilename, ClickDestination = chAsset.ClickDestination, AssetWebSite = chAsset.AssetWebSite, DisplayLength = chAsset.DisplayDuration, PlayerType = chAsset.PlayerType, ScheduleInfo = chAsset.ScheduleInfo, AssetLevel = chAsset.AssetLevel == ChannelDataAssetLevel.Normal ? PlaylistAssetLevel.Normal : PlaylistAssetLevel.Premium, StartDateTime = chAsset.StartDateTime, EndDateTime = chAsset.EndDateTime }; playlistAssets.Add(playlistAsset); } } return(playlistAssets); }