private static void UpdateStatsTest() { AnimeGroupRepository repGroups = new AnimeGroupRepository(); foreach (AnimeGroup grp in repGroups.GetAllTopLevelGroups()) { grp.UpdateStatsFromTopLevel(true, true); } }
public List<Contract_GroupFilterExtended> GetAllGroupFiltersExtended(int userID) { List<Contract_GroupFilterExtended> gfs = new List<Contract_GroupFilterExtended>(); try { DateTime start = DateTime.Now; GroupFilterRepository repGF = new GroupFilterRepository(); JMMUserRepository repUsers = new JMMUserRepository(); JMMUser user = repUsers.GetByID(userID); if (user == null) return gfs; List<GroupFilter> allGfs = repGF.GetAll(); TimeSpan ts = DateTime.Now - start; logger.Info("GetAllGroupFilters (Database) in {0} ms", ts.TotalMilliseconds); start = DateTime.Now; AnimeGroupRepository repGroups = new AnimeGroupRepository(); List<AnimeGroup> allGrps = repGroups.GetAllTopLevelGroups(); ts = DateTime.Now - start; logger.Info("GetAllGroups (Database) in {0} ms", ts.TotalMilliseconds); start = DateTime.Now; foreach (GroupFilter gf in allGfs) { Contract_GroupFilter gfContract = gf.ToContract(); Contract_GroupFilterExtended gfeContract = new Contract_GroupFilterExtended(); gfeContract.GroupFilter = gfContract; gfeContract.GroupCount = 0; gfeContract.SeriesCount = 0; if ((StatsCache.Instance.StatUserGroupFilter.ContainsKey(user.JMMUserID)) && (StatsCache.Instance.StatUserGroupFilter[userID].ContainsKey(gf.GroupFilterID))) { HashSet<int> groups = StatsCache.Instance.StatUserGroupFilter[user.JMMUserID][gf.GroupFilterID]; foreach (AnimeGroup grp in allGrps) { if (groups.Contains(grp.AnimeGroupID)) { // calculate stats gfeContract.GroupCount++; } } } gfs.Add(gfeContract); } ts = DateTime.Now - start; logger.Info("GetAllGroupFiltersExtended (FILTER) in {0} ms", ts.TotalMilliseconds); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return gfs; }
public System.IO.Stream GetFilters(string uid) { JMMUser user = KodiHelper.GetUser(uid); if (user==null) return new MemoryStream(); int userid = user.JMMUserID; KodiObject ret =new KodiObject(KodiHelper.NewMediaContainer("Anime", false)); if (!ret.Init()) return new MemoryStream(); List<Video> dirs = new List<Video>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { GroupFilterRepository repGF = new GroupFilterRepository(); List<GroupFilter> allGfs = repGF.GetAll(session); Dictionary<int, HashSet<int>> gstats = StatsCache.Instance.StatUserGroupFilter[userid]; foreach (GroupFilter gg in allGfs.ToArray()) { if ((!StatsCache.Instance.StatUserGroupFilter.ContainsKey(userid)) || (!StatsCache.Instance.StatUserGroupFilter[userid].ContainsKey(gg.GroupFilterID))) { allGfs.Remove(gg); } } AnimeGroupRepository repGroups = new AnimeGroupRepository(); allGfs.Insert(0, new GroupFilter() {GroupFilterName = "All", GroupFilterID = -999}); foreach (GroupFilter gg in allGfs) { Random rnd = new Random(123456789); Directory pp = new Directory(); pp.Key = KodiHelper.ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressKodi + "/GetMetadata/" + userid + "/" + (int) JMMType.GroupFilter + "/" + gg.GroupFilterID); pp.PrimaryExtraKey = pp.Key; pp.Title = gg.GroupFilterName; HashSet<int> groups; groups = gg.GroupFilterID == -999 ? new HashSet<int>(repGroups.GetAllTopLevelGroups(session).Select(a => a.AnimeGroupID)) : gstats[gg.GroupFilterID]; if (groups.Count != 0) { bool repeat; int nn = 0; pp.LeafCount = groups.Count.ToString(); pp.ViewedLeafCount = "0"; do { repeat = true; int grp = groups.ElementAt(rnd.Next(groups.Count)); AnimeGroup ag = repGroups.GetByID(grp); List<AnimeSeries> sers = ag.GetSeries(session); if (sers.Count > 0) { AnimeSeries ser = sers[rnd.Next(sers.Count)]; AniDB_Anime anim = ser.GetAnime(session); if (anim != null) { ImageDetails poster = anim.GetDefaultPosterDetailsNoBlanks(session); ImageDetails fanart = anim.GetDefaultFanartDetailsNoBlanks(session); if (poster != null) pp.Thumb = poster.GenPoster(); if (fanart != null) pp.Art = fanart.GenArt(); if (poster != null) repeat = false; } } nn++; if ((repeat) && (nn == 15)) repeat = false; } while (repeat); dirs.Add(pp); } } VideoLocalRepository repVids = new VideoLocalRepository(); List<VideoLocal> vids = repVids.GetVideosWithoutEpisode(); if (vids.Count > 0) { JMMContracts.KodiContracts.Directory pp = new JMMContracts.KodiContracts.Directory(); pp.Key = pp.PrimaryExtraKey = KodiHelper.ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressKodi + "/GetMetadata/0/" + (int) JMMType.GroupUnsort + "/0"); pp.Title = "Unsort"; pp.Thumb = KodiHelper.ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressKodi + "/GetSupportImage/plex_unsort.png"); pp.LeafCount = vids.Count.ToString(); pp.ViewedLeafCount = "0"; dirs.Add(pp); } dirs = dirs.OrderBy(a => a.Title).ToList(); } ret.Childrens = dirs; return ret.GetStream(); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return new MemoryStream(); } }
public void UpdateGroupFilterUsingUser(int userid) { AnimeGroupRepository repGroups = new AnimeGroupRepository(); AnimeGroup_UserRepository repUserGroups = new AnimeGroup_UserRepository(); JMMUserRepository repUser = new JMMUserRepository(); GroupFilterRepository repGrpFilter = new GroupFilterRepository(); JMMUser user = repUser.GetByID(userid); if (user == null) return; Dictionary<int, HashSet<int>> groupfilters; if (StatUserGroupFilter.ContainsKey(user.JMMUserID)) groupfilters = StatUserGroupFilter[user.JMMUserID]; else { groupfilters = new Dictionary<int, HashSet<int>>(); StatUserGroupFilter.Add(user.JMMUserID, groupfilters); } List<GroupFilter> gfs = repGrpFilter.GetAll(); GroupFilter gfgf = new GroupFilter(); gfgf.GroupFilterName = "All"; gfs.Add(gfgf); foreach(GroupFilter gf in gfs) { HashSet<int> groups; if (groupfilters.ContainsKey(gf.GroupFilterID)) groups = groupfilters[gf.GroupFilterID]; else { groups = new HashSet<int>(); groupfilters.Add(gf.GroupFilterID, groups); } groups.Clear(); List<AnimeGroup> allGrps = repGroups.GetAllTopLevelGroups(); // No Need of subgroups foreach (AnimeGroup grp in allGrps) { AnimeGroup_User userRec = repUserGroups.GetByUserAndGroupID(user.JMMUserID, grp.AnimeGroupID); if (EvaluateGroupFilter(gf, grp, user, userRec)) groups.Add(grp.AnimeGroupID); } } }
public System.IO.Stream GetFilters(string uid) { int t = 0; int.TryParse(uid, out t); JMMUser user = t > 0 ? PlexHelper.GetJMMUser(uid) : PlexHelper.GetUser(uid); if (user==null) return new MemoryStream(); int userid = user.JMMUserID; HistoryInfo info = new HistoryInfo { Key = PlexHelper.ConstructFiltersUrl(userid), Title = "Anime" }; PlexObject ret = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.Show,info,false)); if (!ret.Init()) return new MemoryStream(); List<Video> dirs = new List<Video>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { GroupFilterRepository repGF = new GroupFilterRepository(); List<GroupFilter> allGfs = repGF.GetAll(session); Dictionary<int, HashSet<int>> gstats = StatsCache.Instance.StatUserGroupFilter[userid]; foreach (GroupFilter gg in allGfs.ToArray()) { if ((!StatsCache.Instance.StatUserGroupFilter.ContainsKey(userid)) || (!StatsCache.Instance.StatUserGroupFilter[userid].ContainsKey(gg.GroupFilterID))) { allGfs.Remove(gg); } } AnimeGroupRepository repGroups = new AnimeGroupRepository(); allGfs.Insert(0, new GroupFilter() {GroupFilterName = "All", GroupFilterID = -999}); foreach (GroupFilter gg in allGfs) { Random rnd = new Random(123456789); Directory pp = new Directory { Type="show" }; pp.Key = PlexHelper.ConstructFilterIdUrl(userid, gg.GroupFilterID); pp.Title = gg.GroupFilterName; HashSet<int> groups; groups = gg.GroupFilterID == -999 ? new HashSet<int>(repGroups.GetAllTopLevelGroups(session).Select(a => a.AnimeGroupID)) : gstats[gg.GroupFilterID]; if (groups.Count != 0) { bool repeat; int nn = 0; pp.LeafCount = groups.Count.ToString(); pp.ViewedLeafCount = "0"; do { repeat = true; int grp = groups.ElementAt(rnd.Next(groups.Count)); AnimeGroup ag = repGroups.GetByID(grp); List<AnimeSeries> sers = ag.GetSeries(session); if (sers.Count > 0) { AnimeSeries ser = sers[rnd.Next(sers.Count)]; AniDB_Anime anim = ser.GetAnime(session); if (anim != null) { ImageDetails poster = anim.GetDefaultPosterDetailsNoBlanks(session); ImageDetails fanart = anim.GetDefaultFanartDetailsNoBlanks(session); if (poster != null) pp.Thumb = poster.GenPoster(); if (fanart != null) pp.Art = fanart.GenArt(); if (poster != null) repeat = false; } } nn++; if ((repeat) && (nn == 15)) repeat = false; } while (repeat); dirs.Add(pp,info); } } VideoLocalRepository repVids = new VideoLocalRepository(); List<VideoLocal> vids = repVids.GetVideosWithoutEpisode(); if (vids.Count > 0) { Directory pp = new Directory() { Type = "show" }; pp.Key = PlexHelper.ConstructUnsortUrl(userid); pp.Title = "Unsort"; pp.Thumb = PlexHelper.ConstructSupportImageLink("plex_unsort.png"); pp.LeafCount = vids.Count.ToString(); pp.ViewedLeafCount = "0"; dirs.Add(pp, info); } var repPlaylist = new PlaylistRepository(); var playlists = repPlaylist.GetAll(); if (playlists.Count > 0) { Directory pp = new Directory() { Type="show" }; pp.Key = PlexHelper.ConstructPlaylistUrl(userid); pp.Title = "Playlists"; pp.Thumb = PlexHelper.ConstructSupportImageLink("plex_playlists.png"); pp.LeafCount = playlists.Count.ToString(); pp.ViewedLeafCount = "0"; dirs.Add(pp, info); } dirs = dirs.OrderBy(a => a.Title).ToList(); } ret.Childrens = dirs; return ret.GetStream(); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return new MemoryStream(); } }