Exemple #1
0
 public List<string> GetAllUniqueVideoQuality()
 {
     try
     {
         AdhocRepository rep = new AdhocRepository();
         return rep.GetAllVideoQuality();
     }
     catch (Exception ex)
     {
         logger.ErrorException(ex.ToString(), ex);
         return new List<string>();
     }
 }
Exemple #2
0
 public List<string> GetAllUniqueSubtitleLanguages()
 {
     try
     {
         AdhocRepository rep = new AdhocRepository();
         return rep.GetAllUniqueSubtitleLanguages();
     }
     catch (Exception ex)
     {
         logger.ErrorException(ex.ToString(), ex);
         return new List<string>();
     }
 }
Exemple #3
0
        public List<Contract_AniDB_AnimeDetailed> GetAllAnimeDetailed()
        {
            List<Contract_AniDB_AnimeDetailed> contracts = new List<Contract_AniDB_AnimeDetailed>();
            int countElements = 0;
            try
            {
                DateTime start = DateTime.Now;

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();

                // build a dictionary of titles
                AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();

                List<AniDB_Anime_Title> allTitles = repTitles.GetAll();
                Dictionary<int, List<AniDB_Anime_Title>> allTitlesDict = new Dictionary<int, List<AniDB_Anime_Title>>();
                foreach (AniDB_Anime_Title title in allTitles)
                {
                    if (!allTitlesDict.ContainsKey(title.AnimeID))
                        allTitlesDict[title.AnimeID] = new List<AniDB_Anime_Title>();

                    allTitlesDict[title.AnimeID].Add(title);
                }

                // build a dictionary of tags
                AniDB_TagRepository repTags = new AniDB_TagRepository();
                AniDB_Anime_TagRepository repAnimeTag = new AniDB_Anime_TagRepository();

                List<AniDB_Tag> allTags = repTags.GetAll();
                Dictionary<int, AniDB_Tag> allTagsDict = new Dictionary<int, AniDB_Tag>();
                foreach (AniDB_Tag tag in allTags)
                    allTagsDict[tag.TagID] = tag;

                List<AniDB_Anime_Tag> allAnimeTags = repAnimeTag.GetAll();
                Dictionary<int, List<AniDB_Anime_Tag>> allAnimeTagsDict = new Dictionary<int, List<AniDB_Anime_Tag>>(); //
                foreach (AniDB_Anime_Tag aniTag in allAnimeTags)
                {
                    if (!allAnimeTagsDict.ContainsKey(aniTag.AnimeID))
                        allAnimeTagsDict[aniTag.AnimeID] = new List<AniDB_Anime_Tag>();

                    allAnimeTagsDict[aniTag.AnimeID].Add(aniTag);
                }

                // build a dictionary of custom tags
                CustomTagRepository repCustomTags = new CustomTagRepository();
                CrossRef_CustomTagRepository repXRefCustomTags = new CrossRef_CustomTagRepository();

                List<CustomTag> allCustomTags = repCustomTags.GetAll();
                Dictionary<int, CustomTag> allCustomTagsDict = new Dictionary<int, CustomTag>();
                foreach (CustomTag tag in allCustomTags)
                    allCustomTagsDict[tag.CustomTagID] = tag;

                List<CrossRef_CustomTag> allCustomTagsXRefs = repXRefCustomTags.GetAll();
                Dictionary<int, List<CrossRef_CustomTag>> allCustomTagsXRefDict = new Dictionary<int, List<CrossRef_CustomTag>>(); //
                foreach (CrossRef_CustomTag aniTag in allCustomTagsXRefs)
                {
                    if (!allCustomTagsXRefDict.ContainsKey(aniTag.CrossRefID))
                        allCustomTagsXRefDict[aniTag.CrossRefID] = new List<CrossRef_CustomTag>();

                    allCustomTagsXRefDict[aniTag.CrossRefID].Add(aniTag);
                }

                // build a dictionary of languages
                AdhocRepository rep = new AdhocRepository();
                Dictionary<int, LanguageStat> dictAudioStats = rep.GetAudioLanguageStatsForAnime();
                Dictionary<int, LanguageStat> dictSubtitleStats = rep.GetSubtitleLanguageStatsForAnime();

                Dictionary<int, string> dictAnimeVideoQualStats = rep.GetAllVideoQualityByAnime();
                Dictionary<int, AnimeVideoQualityStat> dictAnimeEpisodeVideoQualStats = rep.GetEpisodeVideoQualityStatsByAnime();

                List<AniDB_Anime> animes = repAnime.GetAll();

                // user votes
                AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
                List<AniDB_Vote> allVotes = repVotes.GetAll();

                int i = 0;

                foreach (AniDB_Anime anime in animes)
                {
                    i++;
                    //if (i >= 10) continue;

                    countElements++;

                    Contract_AniDB_AnimeDetailed contract = new Contract_AniDB_AnimeDetailed();

                    contract.AnimeTitles = new List<Contract_AnimeTitle>();
                    contract.Tags = new List<Contract_AnimeTag>();
                    contract.CustomTags = new List<Contract_CustomTag>();
                    contract.UserVote = null;

                    contract.AniDBAnime = anime.ToContract();

                    if (dictAnimeVideoQualStats.ContainsKey(anime.AnimeID))
                        contract.Stat_AllVideoQuality = dictAnimeVideoQualStats[anime.AnimeID];
                    else contract.Stat_AllVideoQuality = "";

                    contract.Stat_AllVideoQuality_Episodes = "";

                    // All Video Quality Episodes
                    // Try to determine if this anime has all the episodes available at a certain video quality
                    // e.g.  the series has all episodes in blu-ray
                    if (dictAnimeEpisodeVideoQualStats.ContainsKey(anime.AnimeID))
                    {
                        AnimeVideoQualityStat stat = dictAnimeEpisodeVideoQualStats[anime.AnimeID];
                        foreach (KeyValuePair<string, int> kvp in stat.VideoQualityEpisodeCount)
                        {
                            if (kvp.Value >= anime.EpisodeCountNormal)
                            {
                                if (contract.Stat_AllVideoQuality_Episodes.Length > 0) contract.Stat_AllVideoQuality_Episodes += ",";
                                contract.Stat_AllVideoQuality_Episodes += kvp.Key;
                            }
                        }
                    }

                    List<string> audioLanguageList = new List<string>();
                    List<string> subtitleLanguageList = new List<string>();

                    // get audio languages
                    if (dictAudioStats.ContainsKey(anime.AnimeID))
                    {
                        foreach (string lanName in dictAudioStats[anime.AnimeID].LanguageNames)
                        {
                            if (!audioLanguageList.Contains(lanName)) audioLanguageList.Add(lanName);
                        }
                    }

                    // get subtitle languages
                    if (dictSubtitleStats.ContainsKey(anime.AnimeID))
                    {
                        foreach (string lanName in dictSubtitleStats[anime.AnimeID].LanguageNames)
                        {
                            if (!subtitleLanguageList.Contains(lanName)) subtitleLanguageList.Add(lanName);
                        }
                    }

                    contract.Stat_AudioLanguages = "";
                    foreach (string audioLan in audioLanguageList)
                    {
                        if (contract.Stat_AudioLanguages.Length > 0) contract.Stat_AudioLanguages += ",";
                        contract.Stat_AudioLanguages += audioLan;
                    }

                    contract.Stat_SubtitleLanguages = "";
                    foreach (string subLan in subtitleLanguageList)
                    {
                        if (contract.Stat_SubtitleLanguages.Length > 0) contract.Stat_SubtitleLanguages += ",";
                        contract.Stat_SubtitleLanguages += subLan;
                    }

                    if (allTitlesDict.ContainsKey(anime.AnimeID))
                    {
                        foreach (AniDB_Anime_Title title in allTitlesDict[anime.AnimeID])
                        {
                            Contract_AnimeTitle ctitle = new Contract_AnimeTitle();
                            ctitle.AnimeID = title.AnimeID;
                            ctitle.Language = title.Language;
                            ctitle.Title = title.Title;
                            ctitle.TitleType = title.TitleType;
                            contract.AnimeTitles.Add(ctitle);
                            countElements++;
                        }
                    }

                    if (allAnimeTagsDict.ContainsKey(anime.AnimeID))
                    {
                        List<AniDB_Anime_Tag> aniTags = allAnimeTagsDict[anime.AnimeID];
                        foreach (AniDB_Anime_Tag aniTag in aniTags)
                        {
                            if (allTagsDict.ContainsKey(aniTag.TagID))
                            {
                                AniDB_Tag tag = allTagsDict[aniTag.TagID];

                                Contract_AnimeTag ctag = new Contract_AnimeTag();
                                ctag.Weight = aniTag.Weight;
                                ctag.GlobalSpoiler = tag.GlobalSpoiler;
                                ctag.LocalSpoiler = tag.LocalSpoiler;
                                //ctag.Spoiler = tag.Spoiler;
                                //ctag.TagCount = tag.TagCount;
                                ctag.TagDescription = tag.TagDescription;
                                ctag.TagID = tag.TagID;
                                ctag.TagName = tag.TagName;
                                contract.Tags.Add(ctag);
                                countElements++;
                            }
                        }
                    }

                    //TODO - Custom Tags: add custom tags

                    if (allCustomTagsXRefDict.ContainsKey(anime.AnimeID))
                    {
                        List<CrossRef_CustomTag> aniTags = allCustomTagsXRefDict[anime.AnimeID];
                        foreach (CrossRef_CustomTag aniTag in aniTags)
                        {
                            if (allCustomTagsDict.ContainsKey(aniTag.CustomTagID))
                            {
                                contract.CustomTags.Add(allCustomTagsDict[aniTag.CustomTagID].ToContract());
                                countElements++;
                            }
                        }
                    }

                    // get user vote
                    foreach (AniDB_Vote vote in allVotes)
                    {
                        if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
                        {
                            contract.UserVote = vote.ToContract();
                            break;
                        }
                    }

                    contracts.Add(contract);

                }

                TimeSpan ts = DateTime.Now - start;
                logger.Info("GetAllAnimeDetailed in {0} ms {1}", ts.TotalMilliseconds, countElements);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return contracts;
        }
Exemple #4
0
		public void InitStats()
		{
			try
			{

				DateTime start = DateTime.Now;

				ClearAllData();

				#region Get the data
				AnimeGroupRepository repGroups = new AnimeGroupRepository();
				AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
				AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
				AniDB_CategoryRepository repCats = new AniDB_CategoryRepository();
				AniDB_Anime_CategoryRepository repAnimeCat = new AniDB_Anime_CategoryRepository();
				AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();

				List<AnimeGroup> allGrps = repGroups.GetAll();

				Dictionary<int, AnimeGroup> allGroupsDict = new Dictionary<int, AnimeGroup>();
				foreach (AnimeGroup agrp in allGrps)
					allGroupsDict[agrp.AnimeGroupID] = agrp;
				TimeSpan ts = DateTime.Now - start;
				logger.Info("Get All GROUPS (Database) in {0} ms", ts.TotalMilliseconds);
				

				// anime
				start = DateTime.Now;
				List<AniDB_Anime> allAnime = repAnime.GetAll();
				Dictionary<int, AniDB_Anime> allAnimeDict = new Dictionary<int, AniDB_Anime>();
				foreach (AniDB_Anime anime in allAnime)
					allAnimeDict[anime.AnimeID] = anime;

				ts = DateTime.Now - start;
				logger.Info("Get All ANIME (Database) in {0} ms", ts.TotalMilliseconds);

				// categories
				start = DateTime.Now;
				List<AniDB_Category> allCatgeories = repCats.GetAll();
				Dictionary<int, AniDB_Category> allCatgeoriesDict = new Dictionary<int, AniDB_Category>();
				foreach (AniDB_Category cat in allCatgeories)
					allCatgeoriesDict[cat.CategoryID] = cat;


				List<AniDB_Anime_Category> allAnimeCatgeories = repAnimeCat.GetAll();
				Dictionary<int, List<int>> allAnimeCatgeoriesDict = new Dictionary<int, List<int>>(); // animeid / list of category id's
				foreach (AniDB_Anime_Category aniCat in allAnimeCatgeories)
				{
					if (!allAnimeCatgeoriesDict.ContainsKey(aniCat.AnimeID))
						allAnimeCatgeoriesDict[aniCat.AnimeID] = new List<int>();

					allAnimeCatgeoriesDict[aniCat.AnimeID].Add(aniCat.CategoryID);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All CATEGORIES (Database) in {0} ms", ts.TotalMilliseconds);

				// titles
				start = DateTime.Now;
				List<AniDB_Anime_Title> allTitles = repTitles.GetAll();
				Dictionary<int, List<AniDB_Anime_Title>> allTitlesDict = new Dictionary<int, List<AniDB_Anime_Title>>(); // animeid / list of titles
				foreach (AniDB_Anime_Title aniTitle in allTitles)
				{
					if (!allTitlesDict.ContainsKey(aniTitle.AnimeID))
						allTitlesDict[aniTitle.AnimeID] = new List<AniDB_Anime_Title>();

					allTitlesDict[aniTitle.AnimeID].Add(aniTitle);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All TITLES (Database) in {0} ms", ts.TotalMilliseconds);

				// user votes
				start = DateTime.Now;
				AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
				List<AniDB_Vote> allVotes = repVotes.GetAll();
				ts = DateTime.Now - start;
				logger.Info("Get All VOTES (Database) in {0} ms", ts.TotalMilliseconds);

				// video quality
				start = DateTime.Now;
				AdhocRepository rep = new AdhocRepository();
				Dictionary<int, string> allVidQuality = rep.GetAllVideoQualityByGroup();

				ts = DateTime.Now - start;
				logger.Info("Get VIDEO QUALITY STATS (Database) in {0} ms", ts.TotalMilliseconds);

				// video quality episode stats
				start = DateTime.Now;
				Dictionary<int, AnimeVideoQualityStat> dictStats = rep.GetEpisodeVideoQualityStatsByAnime();
				ts = DateTime.Now - start;
				logger.Info("Get VIDEO QUALITY EPISODE STATS (Database) in {0} ms", ts.TotalMilliseconds);

				// audio and subtitle language stats
				start = DateTime.Now;
				Dictionary<int, LanguageStat> dictAudioStats = rep.GetAudioLanguageStatsForAnime();
				Dictionary<int, LanguageStat> dictSubtitleStats = rep.GetSubtitleLanguageStatsForAnime();
				ts = DateTime.Now - start;
				logger.Info("Get LANGUAGE STATS (Database) in {0} ms", ts.TotalMilliseconds);

				start = DateTime.Now;
				List<AnimeSeries> allSeries = repSeries.GetAll();
				ts = DateTime.Now - start;
				logger.Info("Get All Series (Database) in {0} ms", ts.TotalMilliseconds);

				// TvDB
				start = DateTime.Now;
				CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
				List<CrossRef_AniDB_TvDBV2> allCrossRefs = repCrossRef.GetAll();
				List<int> animeWithTvDBCrossRef = new List<int>();
				foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
				{
					if (!animeWithTvDBCrossRef.Contains(xref.AnimeID)) animeWithTvDBCrossRef.Add(xref.AnimeID);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All AniDB->TvDB Cross Refs (Database) in {0} ms", ts.TotalMilliseconds);

				// MovieDB
				start = DateTime.Now;
				CrossRef_AniDB_OtherRepository repOtherCrossRef = new CrossRef_AniDB_OtherRepository();
				List<CrossRef_AniDB_Other> allOtherCrossRefs = repOtherCrossRef.GetAll();
				List<int> animeWithMovieCrossRef = new List<int>();
				foreach (CrossRef_AniDB_Other xref in allOtherCrossRefs)
				{
					if (!animeWithMovieCrossRef.Contains(xref.AnimeID) && xref.CrossRefType == (int)CrossRefType.MovieDB)
						animeWithMovieCrossRef.Add(xref.AnimeID);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All AniDB->MovieDB Cross Refs (Database) in {0} ms", ts.TotalMilliseconds);


				// MAL
				start = DateTime.Now;
				CrossRef_AniDB_MALRepository repMALCrossRef = new CrossRef_AniDB_MALRepository();
				List<CrossRef_AniDB_MAL> allMALCrossRefs = repMALCrossRef.GetAll();
				List<int> animeWithMALCrossRef = new List<int>();
				foreach (CrossRef_AniDB_MAL xref in allMALCrossRefs)
				{
					if (!animeWithMALCrossRef.Contains(xref.AnimeID))
						animeWithMALCrossRef.Add(xref.AnimeID);
				}
				ts = DateTime.Now - start;
				logger.Info("Get All AniDB->MAL Cross Refs (Database) in {0} ms", ts.TotalMilliseconds);

				#endregion

				start = DateTime.Now;
			    var session = JMMService.SessionFactory.OpenSession();
				foreach (AnimeGroup ag in allGrps)
				{
					// get all the series for this group
					List<AnimeSeries> seriesForGroup = new List<AnimeSeries>();
					GetAnimeSeriesRecursive(ag, ref seriesForGroup, allSeries, allGroupsDict);
                    /*
					if (ag.AnimeGroupID == 915)
					{
						Console.Write("");
					}

                    */
					DateTime? Stat_AirDate_Min = null;
					DateTime? Stat_AirDate_Max = null;
					DateTime? Stat_EndDate = new DateTime(1980, 1, 1);
					DateTime? Stat_SeriesCreatedDate = null;
					bool isComplete = false;
					bool hasFinishedAiring = false;
					bool isCurrentlyAiring = false;

					List<int> categoryIDList = new List<int>();
					List<string> audioLanguageList = new List<string>();
					List<string> subtitleLanguageList = new List<string>();
					string Stat_AllTitles = "";
					string Stat_AllCategories = "";
					string Stat_AllVideoQualityEpisodes = "";
					

					decimal totalVotesPerm = 0, totalVotesTemp = 0, totalVotes = 0;
					int countVotesPerm = 0, countVotesTemp = 0, countVotes = 0;

					bool hasTvDB = true;
					bool hasMAL = true;
					bool hasMovieDB = true;
					bool hasMovieDBOrTvDB = true;

					int seriesCount = 0;
					int epCount = 0;

					foreach (AnimeSeries series in seriesForGroup)
					{
						seriesCount++;
						if (allAnimeDict.ContainsKey(series.AniDB_ID))
						{
							AniDB_Anime thisAnime = allAnimeDict[series.AniDB_ID];

							epCount = epCount + thisAnime.EpisodeCountNormal;

							// All Video Quality Episodes
							// Try to determine if this anime has all the episodes available at a certain video quality
							// e.g.  the series has all episodes in blu-ray
							if (dictStats.ContainsKey(series.AniDB_ID))
							{
								if (series.AniDB_ID == 7656)
								{
									Debug.Print("");
								}

								AnimeVideoQualityStat stat = dictStats[series.AniDB_ID];
								foreach (KeyValuePair<string, int> kvp in stat.VideoQualityEpisodeCount)
								{
									if (kvp.Value >= thisAnime.EpisodeCountNormal)
									{
										if (Stat_AllVideoQualityEpisodes.Length > 0) Stat_AllVideoQualityEpisodes += ",";
										Stat_AllVideoQualityEpisodes += kvp.Key;
									}
								}
							}

							// Calculate Air Date 
							DateTime? thisDate = thisAnime.AirDate;
							if (thisDate.HasValue)
							{
								if (Stat_AirDate_Min.HasValue)
								{
									if (thisDate.Value < Stat_AirDate_Min.Value) Stat_AirDate_Min = thisDate;
								}
								else
									Stat_AirDate_Min = thisDate;

								if (Stat_AirDate_Max.HasValue)
								{
									if (thisDate.Value > Stat_AirDate_Max.Value) Stat_AirDate_Max = thisDate;
								}
								else
									Stat_AirDate_Max = thisDate;
							}

							// calculate end date
							// if the end date is NULL it actually means it is ongoing, so this is the max possible value
							thisDate = thisAnime.EndDate;
							if (thisDate.HasValue && Stat_EndDate.HasValue)
							{
								if (thisDate.Value > Stat_EndDate.Value) Stat_EndDate = thisDate;
							}
							else
								Stat_EndDate = null;

							// Calculate Series Created Date 
							thisDate = series.DateTimeCreated;
							if (thisDate.HasValue)
							{
								if (Stat_SeriesCreatedDate.HasValue)
								{
									if (thisDate.Value < Stat_SeriesCreatedDate.Value) Stat_SeriesCreatedDate = thisDate;
								}
								else
									Stat_SeriesCreatedDate = thisDate;
							}
                            /*
							if (series.AniDB_ID == 2369)
								Debug.Write("Test");
                            */
							// Note - only one series has to be finished airing to qualify
							if (thisAnime.EndDate.HasValue && thisAnime.EndDate.Value < DateTime.Now)
								hasFinishedAiring = true;

							// Note - only one series has to be currently airing to qualify
							if (!thisAnime.EndDate.HasValue || thisAnime.EndDate.Value > DateTime.Now)
								isCurrentlyAiring = true;

							// We evaluate IsComplete as true if
							// 1. series has finished airing
							// 2. user has all episodes locally
							// Note - only one series has to be complete for the group to be considered complete
							if (thisAnime.EndDate.HasValue)
							{
								if (thisAnime.EndDate.Value < DateTime.Now && series.MissingEpisodeCount == 0 && series.MissingEpisodeCountGroups == 0)
								{
									isComplete = true;
								}
							}

							// get categories
							if (allAnimeCatgeoriesDict.ContainsKey(series.AniDB_ID))
							{
								foreach (int catID in allAnimeCatgeoriesDict[series.AniDB_ID])
								{
									if (!categoryIDList.Contains(catID)) categoryIDList.Add(catID);
								}
							}

							// get audio languages
							if (dictAudioStats.ContainsKey(series.AniDB_ID))
							{
								foreach (string lanName in dictAudioStats[series.AniDB_ID].LanguageNames)
								{
									if (!audioLanguageList.Contains(lanName)) audioLanguageList.Add(lanName);
								}
							}

							// get subtitle languages
							if (dictSubtitleStats.ContainsKey(series.AniDB_ID))
							{
								foreach (string lanName in dictSubtitleStats[series.AniDB_ID].LanguageNames)
								{
									if (!subtitleLanguageList.Contains(lanName)) subtitleLanguageList.Add(lanName);
								}
							}

							// get titles
							if (allTitlesDict.ContainsKey(series.AniDB_ID))
							{
								foreach (AniDB_Anime_Title title in allTitlesDict[series.AniDB_ID])
								{
									if (Stat_AllTitles.Length > 0) Stat_AllTitles += ",";
									Stat_AllTitles += title.Title;
								}
							}

							// get votes
							foreach (AniDB_Vote vote in allVotes)
							{
								if (vote.EntityID == series.AniDB_ID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
								{
									countVotes++;
									totalVotes += (decimal)vote.VoteValue;

									if (vote.VoteType == (int)AniDBVoteType.Anime)
									{
										countVotesPerm++;
										totalVotesPerm += (decimal)vote.VoteValue;
									}
									if (vote.VoteType == (int)AniDBVoteType.AnimeTemp)
									{
										countVotesTemp++;
										totalVotesTemp += (decimal)vote.VoteValue;
									}

									break;
								}
							}
						}

						// for the group, if any of the series don't have a tvdb link
						// we will consider the group as not having a tvdb link
						if (!animeWithTvDBCrossRef.Contains(series.AniDB_ID)) hasTvDB = false;
						if (!animeWithMovieCrossRef.Contains(series.AniDB_ID)) hasMovieDB = false;
						if (!animeWithMALCrossRef.Contains(series.AniDB_ID)) hasMAL = false;

						if (!animeWithTvDBCrossRef.Contains(series.AniDB_ID) && !animeWithMovieCrossRef.Contains(series.AniDB_ID)) hasMovieDBOrTvDB = false;
					}

					if (allVidQuality.ContainsKey(ag.AnimeGroupID))
						StatGroupVideoQuality[ag.AnimeGroupID] = allVidQuality[ag.AnimeGroupID];
					else
						StatGroupVideoQuality[ag.AnimeGroupID] = "";

					StatGroupVideoQualityEpisodes[ag.AnimeGroupID] = Stat_AllVideoQualityEpisodes;

					StatGroupIsComplete[ag.AnimeGroupID] = isComplete;
					StatGroupIsFinishedAiring[ag.AnimeGroupID] = hasFinishedAiring;
					StatGroupIsCurrentlyAiring[ag.AnimeGroupID] = isCurrentlyAiring;
					StatGroupSeriesCount[ag.AnimeGroupID] = seriesCount;
					StatGroupEpisodeCount[ag.AnimeGroupID] = epCount;

					StatGroupTitles[ag.AnimeGroupID] = Stat_AllTitles;
					StatGroupAirDate_Max[ag.AnimeGroupID] = Stat_AirDate_Max;
					StatGroupAirDate_Min[ag.AnimeGroupID] = Stat_AirDate_Min;
					StatGroupEndDate[ag.AnimeGroupID] = Stat_EndDate;
					StatGroupSeriesCreatedDate[ag.AnimeGroupID] = Stat_SeriesCreatedDate;
					StatGroupHasTvDB[ag.AnimeGroupID] = hasTvDB;
					StatGroupHasMAL[ag.AnimeGroupID] = hasMAL;
					StatGroupHasMovieDB[ag.AnimeGroupID] = hasMovieDB;
					StatGroupHasMovieDBOrTvDB[ag.AnimeGroupID] = hasMovieDBOrTvDB;

					decimal? Stat_UserVoteOverall = null;
					if (countVotes > 0) 
						Stat_UserVoteOverall = totalVotes / (decimal)countVotes / (decimal)100;
					StatGroupUserVoteOverall[ag.AnimeGroupID] = Stat_UserVoteOverall;

					decimal? Stat_UserVotePermanent = null;
					if (countVotesPerm > 0)
						Stat_UserVotePermanent = totalVotesPerm / (decimal)countVotesPerm / (decimal)100;
					StatGroupUserVotePermanent[ag.AnimeGroupID] = Stat_UserVotePermanent;

					decimal? Stat_UserVoteTemporary = null;
					if (countVotesTemp > 0)
						Stat_UserVoteTemporary = totalVotesTemp / (decimal)countVotesTemp / (decimal)100;
					StatGroupUserVoteTemporary[ag.AnimeGroupID] = Stat_UserVoteTemporary;

					StatGroupAniDBRating[ag.AnimeGroupID] = ag.AniDBRating;

					Stat_AllCategories = "";

					foreach (int catID in categoryIDList)
					{
						if (!allCatgeoriesDict.ContainsKey(catID)) continue;

						string catName = allCatgeoriesDict[catID].CategoryName;
						if (Stat_AllCategories.Length > 0)
							Stat_AllCategories += "|";

						Stat_AllCategories += catName;
					}
					this.StatGroupCategories[ag.AnimeGroupID] = Stat_AllCategories;

					string Stat_AudioLanguages = "";
					foreach (string audioLan in audioLanguageList)
					{
						if (Stat_AudioLanguages.Length > 0) Stat_AudioLanguages += ",";
						Stat_AudioLanguages += audioLan;
					}
					this.StatGroupAudioLanguages[ag.AnimeGroupID] = Stat_AudioLanguages;

					string Stat_SubtitleLanguages = "";
					foreach (string subLan in subtitleLanguageList)
					{
						if (Stat_SubtitleLanguages.Length > 0) Stat_SubtitleLanguages += ",";
						Stat_SubtitleLanguages += subLan;
					}
					this.StatGroupSubtitleLanguages[ag.AnimeGroupID] = Stat_SubtitleLanguages;

                    UpdateGroupFilterUsingGroup(ag.AnimeGroupID);
                    UpdatePlexAnimeGroup(session, ag, allSeries);
				}


				ts = DateTime.Now - start;
				logger.Info("GetAllGroups (Contracts) in {0} ms", ts.TotalMilliseconds);

				//UpdateAllAnimeContracts();

			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
			}
		}
Exemple #5
0
		public void UpdateUsingGroup(ISession session, int animeGroupID)
		{
			try
			{
				DateTime start = DateTime.Now;

				AnimeGroupRepository repGroups = new AnimeGroupRepository();
				AnimeGroup thisgrp = repGroups.GetByID(session, animeGroupID);
				
				if (thisgrp == null) return;

				AdhocRepository repAdHoc = new AdhocRepository();

				// get a list of all the groups including this one and everthing above it the heirarchy
				List<AnimeGroup> allgroups = new List<AnimeGroup>();
				allgroups.Add(thisgrp);

				int? groupID = thisgrp.AnimeGroupParentID;
				while (groupID.HasValue)
				{
					AnimeGroup grpTemp = repGroups.GetByID(session, groupID.Value);
					if (grpTemp != null)
					{
						allgroups.Add(grpTemp);
						groupID = grpTemp.AnimeGroupParentID;
					}
					else
						groupID = null;
				}

				TimeSpan ts = DateTime.Now - start;
				logger.Trace("Updating cached stats for GROUP - STEP 1 ({0}) in {1} ms", thisgrp.GroupName, ts.TotalMilliseconds);
				start = DateTime.Now;

				VideoLocalRepository repVids = new VideoLocalRepository();
				CrossRef_File_EpisodeRepository repXrefs = new CrossRef_File_EpisodeRepository();

				foreach (AnimeGroup grp in allgroups)
				{
					StatGroupCategories[grp.AnimeGroupID] = grp.CategoriesString;
					StatGroupTitles[grp.AnimeGroupID] = grp.TitlesString;
					StatGroupVideoQuality[grp.AnimeGroupID] = grp.VideoQualityString;

					ts = DateTime.Now - start;
					logger.Trace("Updating cached stats for GROUP - STEP 2 ({0}) in {1} ms", grp.GroupName, ts.TotalMilliseconds);
					start = DateTime.Now;

					DateTime? airDate_Min = null;
					DateTime? airDate_Max = null;
					DateTime? endDate = new DateTime(1980, 1, 1);
					DateTime? seriesCreatedDate = null;
					bool isComplete = false;
					bool hasFinishedAiring = false;
					bool isCurrentlyAiring = false;
					string videoQualityEpisodes = "";

					List<string> audioLanguages = new List<string>();
					List<string> subtitleLanguages = new List<string>();

					bool hasTvDB = true;
					bool hasMAL = true;
					bool hasMovieDB = true;
					bool hasMovieDBOrTvDB = true;

					int seriesCount = 0;
					int epCount = 0;


					foreach (AnimeSeries series in grp.GetAllSeries(session))
					{
						seriesCount++;

						List<VideoLocal> vidsTemp = repVids.GetByAniDBAnimeID(session, series.AniDB_ID);
						List<CrossRef_File_Episode> crossRefs = repXrefs.GetByAnimeID(session, series.AniDB_ID);

						Dictionary<int, List<CrossRef_File_Episode>> dictCrossRefs = new Dictionary<int, List<CrossRef_File_Episode>>();
						foreach (CrossRef_File_Episode xref in crossRefs)
						{
							if (!dictCrossRefs.ContainsKey(xref.EpisodeID))
								dictCrossRefs[xref.EpisodeID] = new List<CrossRef_File_Episode>();
							dictCrossRefs[xref.EpisodeID].Add(xref);
						}

						Dictionary<string, VideoLocal> dictVids = new Dictionary<string, VideoLocal>();
						foreach (VideoLocal vid in vidsTemp)
							dictVids[vid.Hash] = vid;

						// All Video Quality Episodes
						// Try to determine if this anime has all the episodes available at a certain video quality
						// e.g.  the series has all episodes in blu-ray
						// Also look at languages
						Dictionary<string, int> vidQualEpCounts = new Dictionary<string,int>(); // video quality, count of episodes

						foreach (AnimeEpisode ep in series.GetAnimeEpisodes(session))
						{
							if (ep.EpisodeTypeEnum != AniDBAPI.enEpisodeType.Episode) continue;


							List<VideoLocal> epVids = new List<VideoLocal>();
							if (dictCrossRefs.ContainsKey(ep.AniDB_EpisodeID))
							{
								foreach (CrossRef_File_Episode xref in dictCrossRefs[ep.AniDB_EpisodeID])
								{
									if (xref.EpisodeID == ep.AniDB_EpisodeID)
									{
										if (dictVids.ContainsKey(xref.Hash))
											epVids.Add(dictVids[xref.Hash]);
									}
								}
							}

							List<string> qualityAddedSoFar = new List<string>(); // handle mutliple files of the same quality for one episode
							foreach (VideoLocal vid in epVids)
							{
								AniDB_File anifile = vid.GetAniDBFile(session);
								if (anifile == null) continue;

								if (!qualityAddedSoFar.Contains(anifile.File_Source))
								{
									if (!vidQualEpCounts.ContainsKey(anifile.File_Source))
										vidQualEpCounts[anifile.File_Source] = 1;
									else
										vidQualEpCounts[anifile.File_Source]++;

									qualityAddedSoFar.Add(anifile.File_Source);
								}
							}
						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 3 ({0}/{1}) in {2} ms",grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;



						AniDB_Anime anime = series.GetAnime(session);

						epCount = epCount + anime.EpisodeCountNormal;

						foreach (KeyValuePair<string, int> kvp in vidQualEpCounts)
						{
							int index = videoQualityEpisodes.IndexOf(kvp.Key, 0, StringComparison.InvariantCultureIgnoreCase);
							if (index > -1) continue; // don't add if we already have it

							if (anime.EpisodeCountNormal == kvp.Value)
							{
								if (videoQualityEpisodes.Length > 0) videoQualityEpisodes += ",";
								videoQualityEpisodes += kvp.Key;
							}

						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 4 ({0}/{1}) in {2} ms", grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;

						// audio languages
						Dictionary<int, LanguageStat> dicAudio = repAdHoc.GetAudioLanguageStatsByAnime(session, anime.AnimeID);
						foreach (KeyValuePair<int, LanguageStat> kvp in dicAudio)
						{
							foreach (string lanName in kvp.Value.LanguageNames)
							{
								if (!audioLanguages.Contains(lanName))
									audioLanguages.Add(lanName);
							}
						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 5 ({0}/{1}) in {2} ms", grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;

						// subtitle languages
						Dictionary<int, LanguageStat> dicSubtitle = repAdHoc.GetSubtitleLanguageStatsByAnime(session, anime.AnimeID);
						foreach (KeyValuePair<int, LanguageStat> kvp in dicSubtitle)
						{
							foreach (string lanName in kvp.Value.LanguageNames)
							{
								if (!subtitleLanguages.Contains(lanName))
									subtitleLanguages.Add(lanName);
							}
						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 6 ({0}/{1}) in {2} ms", grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;

						// Calculate Air Date 
						DateTime? thisDate = series.AirDate;
						if (thisDate.HasValue)
						{
							if (airDate_Min.HasValue)
							{
								if (thisDate.Value < airDate_Min.Value) airDate_Min = thisDate;
							}
							else
								airDate_Min = thisDate;

							if (airDate_Max.HasValue)
							{
								if (thisDate.Value > airDate_Max.Value) airDate_Max = thisDate;
							}
							else
								airDate_Max = thisDate;
						}

						// calculate end date
						// if the end date is NULL it actually means it is ongoing, so this is the max possible value
						thisDate = series.EndDate;
						if (thisDate.HasValue && endDate.HasValue)
						{
							if (thisDate.Value > endDate.Value) endDate = thisDate;
						}
						else
							endDate = null;

						// Note - only one series has to be finished airing to qualify
						if (series.EndDate.HasValue && series.EndDate.Value < DateTime.Now)
							hasFinishedAiring = true;

						// Note - only one series has to be finished airing to qualify
						if (!series.EndDate.HasValue || series.EndDate.Value > DateTime.Now)
							isCurrentlyAiring = true;

						// We evaluate IsComplete as true if
						// 1. series has finished airing
						// 2. user has all episodes locally
						// Note - only one series has to be complete for the group to be considered complete
						if (series.EndDate.HasValue)
						{
							if (series.EndDate.Value < DateTime.Now && series.MissingEpisodeCount == 0 && series.MissingEpisodeCountGroups == 0)
							{
								isComplete = true;
							}
						}

						// Calculate Series Created Date 
						thisDate = series.DateTimeCreated;
						if (thisDate.HasValue)
						{
							if (seriesCreatedDate.HasValue)
							{
								if (thisDate.Value < seriesCreatedDate.Value) seriesCreatedDate = thisDate;
							}
							else
								seriesCreatedDate = thisDate;
						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 7 ({0}/{1}) in {2} ms", grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;

						// for the group, if any of the series don't have a tvdb link
						// we will consider the group as not having a tvdb link

						List<CrossRef_AniDB_TvDBV2> tvXrefs = series.GetCrossRefTvDBV2();

						if (tvXrefs == null || tvXrefs.Count == 0) hasTvDB = false;
						if (series.CrossRefMovieDB == null) hasMovieDB = false;
						if (series.CrossRefMAL == null) hasMAL = false;

						if ((tvXrefs == null || tvXrefs.Count == 0) && series.CrossRefMovieDB == null) hasMovieDBOrTvDB = false;
					}


					StatGroupIsComplete[grp.AnimeGroupID] = isComplete;
					StatGroupIsFinishedAiring[grp.AnimeGroupID] = hasFinishedAiring;
					StatGroupIsCurrentlyAiring[grp.AnimeGroupID] = isCurrentlyAiring;
					StatGroupHasTvDB[grp.AnimeGroupID] = hasTvDB;
					StatGroupHasMAL[grp.AnimeGroupID] = hasMAL;
					StatGroupHasMovieDB[grp.AnimeGroupID] = hasMovieDB;
					StatGroupHasMovieDBOrTvDB[grp.AnimeGroupID] = hasMovieDBOrTvDB;
					StatGroupSeriesCount[grp.AnimeGroupID] = seriesCount;
					StatGroupEpisodeCount[grp.AnimeGroupID] = epCount;

					StatGroupVideoQualityEpisodes[grp.AnimeGroupID] = videoQualityEpisodes;

					StatGroupAirDate_Min[grp.AnimeGroupID] = airDate_Min;
					StatGroupAirDate_Max[grp.AnimeGroupID] = airDate_Max;
					StatGroupEndDate[grp.AnimeGroupID] = endDate;
					StatGroupSeriesCreatedDate[grp.AnimeGroupID] = seriesCreatedDate;

					StatGroupUserVoteOverall[grp.AnimeGroupID] = grp.UserVote;
					StatGroupUserVotePermanent[grp.AnimeGroupID] = grp.UserVotePermanent;
					StatGroupUserVoteTemporary[grp.AnimeGroupID] = grp.UserVoteTemporary;
					StatGroupAniDBRating[grp.AnimeGroupID] = grp.AniDBRating;

					ts = DateTime.Now - start;
					logger.Trace("Updating cached stats for GROUP - STEP 8 ({0}) in {1} ms", grp.GroupName, ts.TotalMilliseconds);
					start = DateTime.Now;

					string Stat_AudioLanguages = "";
					foreach (string audioLan in audioLanguages)
					{
						if (Stat_AudioLanguages.Length > 0) Stat_AudioLanguages += ",";
						Stat_AudioLanguages += audioLan;
					}
					this.StatGroupAudioLanguages[grp.AnimeGroupID] = Stat_AudioLanguages;

					string Stat_SubtitleLanguages = "";
					foreach (string subLan in subtitleLanguages)
					{
						if (Stat_SubtitleLanguages.Length > 0) Stat_SubtitleLanguages += ",";
						Stat_SubtitleLanguages += subLan;
					}
					this.StatGroupSubtitleLanguages[grp.AnimeGroupID] = Stat_SubtitleLanguages;

                    ts = DateTime.Now - start;
                    logger.Trace("Updating cached stats for GROUP - STEP 9 ({0}) in {1} ms", grp.GroupName, ts.TotalMilliseconds);
                    start = DateTime.Now;
                    UpdateGroupFilterUsingGroup(grp.AnimeGroupID);
                    UpdatePlexAnimeGroup(session, grp,grp.GetAllSeries());
                    ts = DateTime.Now - start;
                    logger.Trace("Updating cached stats for GROUP - END ({0}) in {1} ms", grp.GroupName, ts.TotalMilliseconds);
                }
			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
			}
		}
Exemple #6
0
        public Contract_AniDB_AnimeDetailed ToContractDetailed(ISession session)
        {
            AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();
            AniDB_TagRepository repTags = new AniDB_TagRepository();

            Contract_AniDB_AnimeDetailed contract = new Contract_AniDB_AnimeDetailed();

            contract.AnimeTitles = new List<Contract_AnimeTitle>();
            contract.Tags = new List<Contract_AnimeTag>();
            contract.CustomTags = new List<Contract_CustomTag>();
            contract.AniDBAnime = this.ToContract(session);

            // get all the anime titles
            List<AniDB_Anime_Title> animeTitles = repTitles.GetByAnimeID(session, AnimeID);
            if (animeTitles != null)
            {
                foreach (AniDB_Anime_Title title in animeTitles)
                {
                    Contract_AnimeTitle ctitle = new Contract_AnimeTitle();
                    ctitle.AnimeID = title.AnimeID;
                    ctitle.Language = title.Language;
                    ctitle.Title = title.Title;
                    ctitle.TitleType = title.TitleType;
                    contract.AnimeTitles.Add(ctitle);
                }
            }

            Dictionary<int, AniDB_Anime_Tag> dictAnimeTags = new Dictionary<int, AniDB_Anime_Tag>();
            foreach (AniDB_Anime_Tag animeTag in GetAnimeTags(session))
                dictAnimeTags[animeTag.TagID] = animeTag;

            foreach (AniDB_Tag tag in GetAniDBTags(session))
            {
                Contract_AnimeTag ctag = new Contract_AnimeTag();

                ctag.GlobalSpoiler = tag.GlobalSpoiler;
                ctag.LocalSpoiler = tag.LocalSpoiler;
                //ctag.Spoiler = tag.Spoiler;
                //ctag.TagCount = tag.TagCount;
                ctag.TagDescription = tag.TagDescription;
                ctag.TagID = tag.TagID;
                ctag.TagName = tag.TagName;

                if (dictAnimeTags.ContainsKey(tag.TagID))
                    ctag.Weight = dictAnimeTags[tag.TagID].Weight;
                else
                    ctag.Weight = 0;

                contract.Tags.Add(ctag);
            }

            // Get all the custom tags
            foreach (CustomTag custag in GetCustomTagsForAnime(session))
                contract.CustomTags.Add(custag.ToContract());

            if (this.UserVote != null)
                contract.UserVote = this.UserVote.ToContract();

            AdhocRepository repAdHoc = new AdhocRepository();
            List<string> audioLanguages = new List<string>();
            List<string> subtitleLanguages = new List<string>();

            //logger.Trace(" XXXX 06");

            // audio languages
            Dictionary<int, LanguageStat> dicAudio = repAdHoc.GetAudioLanguageStatsByAnime(session, this.AnimeID);
            foreach (KeyValuePair<int, LanguageStat> kvp in dicAudio)
            {
                foreach (string lanName in kvp.Value.LanguageNames)
                {
                    if (!audioLanguages.Contains(lanName))
                        audioLanguages.Add(lanName);
                }
            }

            //logger.Trace(" XXXX 07");

            // subtitle languages
            Dictionary<int, LanguageStat> dicSubtitle = repAdHoc.GetSubtitleLanguageStatsByAnime(session, this.AnimeID);
            foreach (KeyValuePair<int, LanguageStat> kvp in dicSubtitle)
            {
                foreach (string lanName in kvp.Value.LanguageNames)
                {
                    if (!subtitleLanguages.Contains(lanName))
                        subtitleLanguages.Add(lanName);
                }
            }

            //logger.Trace(" XXXX 08");

            contract.Stat_AudioLanguages = "";
            foreach (string audioLan in audioLanguages)
            {
                if (contract.Stat_AudioLanguages.Length > 0) contract.Stat_AudioLanguages += ",";
                contract.Stat_AudioLanguages += audioLan;
            }

            //logger.Trace(" XXXX 09");

            contract.Stat_SubtitleLanguages = "";
            foreach (string subLan in subtitleLanguages)
            {
                if (contract.Stat_SubtitleLanguages.Length > 0) contract.Stat_SubtitleLanguages += ",";
                contract.Stat_SubtitleLanguages += subLan;
            }

            //logger.Trace(" XXXX 10");
            contract.Stat_AllVideoQuality = repAdHoc.GetAllVideoQualityForAnime(session, this.AnimeID);

            contract.Stat_AllVideoQuality_Episodes = "";
            AnimeVideoQualityStat stat = repAdHoc.GetEpisodeVideoQualityStatsForAnime(session, this.AnimeID);
            if (stat != null && stat.VideoQualityEpisodeCount.Count > 0)
            {
                foreach (KeyValuePair<string, int> kvp in stat.VideoQualityEpisodeCount)
                {
                    if (kvp.Value >= EpisodeCountNormal)
                    {
                        if (contract.Stat_AllVideoQuality_Episodes.Length > 0) contract.Stat_AllVideoQuality_Episodes += ",";
                        contract.Stat_AllVideoQuality_Episodes += kvp.Key;
                    }
                }
            }

            //logger.Trace(" XXXX 11");

            return contract;
        }