private void UpdateMixTokRanks() { // The min age a clip can be. TimeSpan s_minClipAge = new TimeSpan(0, 10, 0); // For each clip, update the rank DateTime nowUtc = DateTime.UtcNow; foreach (KeyValuePair <string, MixerClip> p in m_clipMine) { MixerClip clip = p.Value; // Compute the view rank double viewRank = (double)clip.ViewCount; // Decay the view rank by time TimeSpan age = (nowUtc - clip.UploadDate); // Clamp by the min age to give all clips some time // to pick up viewers. if (age < s_minClipAge) { age = s_minClipAge; } double decayedRank = viewRank / (Math.Pow(age.TotalDays, 1.5)); clip.MixTokRank = decayedRank; } }
private void InsertSort(ref LinkedList <MixerClip> list, MixerClip c, ClipMineSortTypes type) { LinkedListNode <MixerClip> node = list.First; while (node != null) { bool result = false; switch (type) { case ClipMineSortTypes.MostRecent: result = c.UploadDate > node.Value.UploadDate; break; case ClipMineSortTypes.MixTokRank: result = c.MixTokRank > node.Value.MixTokRank; break; default: case ClipMineSortTypes.ViewCount: result = c.ViewCount > node.Value.ViewCount; break; } if (result) { list.AddBefore(node, c); return; } node = node.Next; } list.AddLast(c); }
public List <MixerClip> GetClips(ClipMineSortTypes sortType, int limit = 100, DateTime?fromTime = null, DateTime?toTime = null, int?ViewCountMin = null, int?channelIdFilter = null, string channelName = null, int?hypeZoneChannelId = null, bool?currentlyLive = null, bool?partnered = null, string gameTitle = null, int?gameId = null, string languageFilter = null) { // Get the pre-sorted list we want. LinkedList <MixerClip> list; object lockObj; switch (sortType) { default: case ClipMineSortTypes.ViewCount: list = m_viewCountSortedList; lockObj = m_viewCountSortedLock; break; case ClipMineSortTypes.MixTokRank: list = m_mixTockSortedList; lockObj = m_mixTockSortedLock; break; case ClipMineSortTypes.MostRecent: list = m_mostRecentList; lockObj = m_mostRecentSortedLock; break; } List <MixerClip> output = new List <MixerClip>(); // Lock the list so it doesn't change while we are using it. lock (lockObj) { // Go through the current sorted list from the highest to the lowest. // Apply the filtering and then build the output list. LinkedListNode <MixerClip> node = list.First; while (output.Count < limit && node != null) { // Get the node and advance here, becasue this will continue early // if the search filters it out. MixerClip c = node.Value; node = node.Next; if (channelIdFilter.HasValue) { // Check if this is the channel we want. if (c.Channel.Id != channelIdFilter.Value) { continue; } } if (!String.IsNullOrWhiteSpace(channelName)) { // Check if the channel name has the current filter. if (c.Channel.Name.IndexOf(channelName, 0, StringComparison.InvariantCultureIgnoreCase) == -1) { continue; } } if (!String.IsNullOrWhiteSpace(gameTitle)) { // Check if the game title has the current filter string. if (c.GameTitle.IndexOf(gameTitle, 0, StringComparison.InvariantCultureIgnoreCase) == -1) { continue; } } if (gameId.HasValue) { if (c.TypeId != gameId) { continue; } } if (fromTime.HasValue) { // Check if this is in the time range we want. if (c.UploadDate < fromTime.Value) { continue; } } if (toTime.HasValue) { // Check if this is in the time range we want. if (c.UploadDate > toTime.Value) { continue; } } if (ViewCountMin.HasValue) { if (c.ViewCount < ViewCountMin) { continue; } } if (partnered.HasValue) { if (partnered.Value != c.Channel.Partnered) { continue; } } if (currentlyLive.HasValue) { if (currentlyLive.Value != c.Channel.Online) { continue; } } if (hypeZoneChannelId.HasValue) { if (hypeZoneChannelId.Value != c.HypeZoneChannelId) { continue; } } if (!String.IsNullOrWhiteSpace(languageFilter)) { if (!c.Channel.Language.Equals(languageFilter, StringComparison.OrdinalIgnoreCase)) { continue; } } // If we got to then end this didn't get filtered. // So add it. output.Add(c); } } return(output); }
public void UpdateFromNewer(MixerClip fresh) { ViewCount = fresh.ViewCount; Channel.UpdateFromNewer(fresh.Channel); }