Exemple #1
0
        private void AddStatInfo(MediaList medialist)
        {
            foreach (string genre in medialist.Media.Genres)
            {
                GenreStatInfo cgsi = GenresStatInfo.Find(gsi => gsi.Name == genre);
                if (cgsi == null)
                {
                    // Invalid genre.
                    continue;
                }
                else
                {
                    cgsi.Count          += 1;
                    cgsi.MinutesWatched += medialist.Media.Duration * medialist.Progress;
                }
            }

            foreach (MediaTag tag in medialist.Media.Tags)
            {
                TagStatInfo ctsi = TagsStatInfo.Find(tsi => tsi.Name == tag.Name);
                if (ctsi == null)
                {
                    // Invalid tag.
                    continue;
                }
                else
                {
                    ctsi.Count          += 1;
                    ctsi.MinutesWatched += medialist.Media.Duration * medialist.Progress;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Metric function based on minutes watched between genre and tag.
        /// </summary>
        /// <param name="g">Genre</param>
        /// <param name="t">Tag</param>
        /// <remarks>By defining symmetry in the arguments this turns the set of genres and tags in a metric space.</remarks>
        /// <returns>The distance between the genre and the tag.</returns>
        private int MinutesWatchedMetric(GenreStatInfo g, TagStatInfo t)
        {
            if (g == null)
            {
                throw new ArgumentNullException(nameof(g));
            }
            if (t == null)
            {
                throw new ArgumentNullException(nameof(t));
            }

            return(Math.Abs(g.MinutesWatched - t.MinutesWatched) + constNonRelevancy);
        }
Exemple #3
0
        /// <summary>
        /// Metric function based on count between genre and tag.
        /// </summary>
        /// <param name="g">Genre</param>
        /// <param name="t">Tag</param>
        /// <remarks>By defining symmetry in the arguments this turns the set of genres and tags in a metric space.</remarks>
        /// <returns>The distance between the genre and the tag.</returns>
        private int CountMetric(GenreStatInfo g, TagStatInfo t)
        {
            if (g == null)
            {
                throw new ArgumentNullException(nameof(g));
            }
            if (t == null)
            {
                throw new ArgumentNullException(nameof(t));
            }

            return(Math.Abs(g.Count - t.Count) + constNonRelevancy);
        }
Exemple #4
0
        /// <summary>
        /// Metric function based on minutes watched for genres.
        /// </summary>
        /// <param name="g1">Genre 1</param>
        /// <param name="g2">Genre 2</param>
        /// <returns>The distance between the two genres (in terms of minutes watched).</returns>
        private int MinutesWatchedMetric(GenreStatInfo g1, GenreStatInfo g2)
        {
            if (g1 == null)
            {
                throw new ArgumentNullException(nameof(g1));
            }
            if (g2 == null)
            {
                throw new ArgumentNullException(nameof(g2));
            }

            if (g1.Name == g2.Name)
            {
                return(0);
            }
            return(Math.Abs(g1.MinutesWatched - g2.MinutesWatched) + constNonRelevancy);
        }
Exemple #5
0
        /// <summary>
        /// Metric function based on minutes watched for genres or tags.
        /// Determines what each parameter is, either a genre or tag, and applies the correct metric function.
        /// </summary>
        /// <param name="got1">Genre or Tag 1</param>
        /// <param name="got2">Genre or Tag 2</param>
        /// <remarks>May throw an InvalidGenreOrTagException.</remarks>
        /// <returns>The distance between got1 and got2 (in terms of minutes watched).</returns>
        private int MinutesWatchedMetric(string got1, string got2)
        {
            GenreStatInfo gsi1 = genreAndTagStatInfo.GenresStatInfo.Find(gsi => gsi.Name == got1);

            if (gsi1 != null)
            {
                GenreStatInfo gsi2 = genreAndTagStatInfo.GenresStatInfo.Find(gsi => gsi.Name == got2);
                if (gsi2 != null)
                {
                    return(MinutesWatchedMetric(gsi1, gsi2));
                }

                TagStatInfo tsi2 = genreAndTagStatInfo.TagsStatInfo.Find(tsi => tsi.Name == got2);
                if (tsi2 != null)
                {
                    return(MinutesWatchedMetric(gsi1, tsi2));
                }

                throw new InvalidGenreOrTagException(got2 + " is not a valid genre or tag.");
            }

            TagStatInfo tsi1 = genreAndTagStatInfo.TagsStatInfo.Find(tsi => tsi.Name == got1);

            if (tsi1 != null)
            {
                GenreStatInfo gsi2 = genreAndTagStatInfo.GenresStatInfo.Find(gsi => gsi.Name == got2);
                if (gsi2 != null)
                {
                    return(MinutesWatchedMetric(tsi1, gsi2));
                }

                TagStatInfo tsi2 = genreAndTagStatInfo.TagsStatInfo.Find(tsi => tsi.Name == got2);
                if (tsi2 != null)
                {
                    return(MinutesWatchedMetric(tsi1, tsi2));
                }

                throw new InvalidGenreOrTagException(got2 + " is not a valid genre or tag.");
            }
            throw new InvalidGenreOrTagException(got1 + " is not a valid genre or tag.");
        }
Exemple #6
0
 /// <summary>
 /// Symmetry for MinutesWatchedMetric(g, t).
 /// </summary>
 /// <param name="t">Tag</param>
 /// <param name="g">Genre</param>
 /// <returns>Distance between g and t (in terms of minutes watched).</returns>
 private int MinutesWatchedMetric(TagStatInfo t, GenreStatInfo g)
 {
     return(MinutesWatchedMetric(g, t));
 }
Exemple #7
0
 /// <summary>
 /// Symmetry for CountMetric(g, t).
 /// </summary>
 /// <param name="t">Tag</param>
 /// <param name="g">Genre</param>
 /// <returns>Distance between g and t.</returns>
 private int CountMetric(TagStatInfo t, GenreStatInfo g)
 {
     return(CountMetric(g, t));
 }