Exemple #1
0
        public void DislikeTrack(HubblUser user, int entryId)
        {
            foreach (var userMarkedId in _usersMarkedByEntryId[entryId])
                if (userMarkedId == user.Id)
                    return;
            _usersMarkedByEntryId[entryId].Add(user.Id);

            UpdateUserPriorities();
            if (!_usersActivities.ContainsKey(user.Id))
            {
                var newActivity = new UserActivitiesRecord
                {
                    basePriority = 1.0,
                    activitiesCount = 0,
                    lastActivityTime = DateTime.Now
                };
                _usersActivities.Add(user.Id, newActivity);
            }
            var activitiesRecord = _usersActivities[user.Id];
            if (activitiesRecord.activitiesCount++ == 0)
                ++_activeUsersCount;

            var entry = _playlistEntries[entryId];
            ++entry.DislikesNum;
            entry.Priority *= (_activeUsersCount - 1.0)/_activeUsersCount;

            Playlist.Sort(comparePlaylistEntries);
        }
Exemple #2
0
        public PlaylistEntry QueueTrack(HubblUser user, Track track)
        {
            UpdateUserPriorities();

            if (!_usersActivities.ContainsKey(user.Id))
            {
                var newActivity = new UserActivitiesRecord
                {
                    basePriority = 1.0,
                    activitiesCount = 0,
                    lastActivityTime = DateTime.Now
                };
                _usersActivities.Add(user.Id, newActivity);
            }
            var activitiesRecord = _usersActivities[user.Id];

            if (activitiesRecord.activitiesCount++ == 0)
                ++_activeUsersCount;

            var entry = new PlaylistEntry
            {
                User = user,
                Track = track,
                Id = _freeEntryId++,
                LikesNum = 0,
                DislikesNum = 0,
                Priority = activitiesRecord.basePriority
            };
            activitiesRecord.basePriority *= Math.Pow(0.5, track.Duration.TotalMilliseconds/AVG_TRACK_LENGTH_MS);
            _usersMarkedByEntryId.Add(entry.Id, new List<string>());
            _usersMarkedByEntryId[entry.Id].Add(user.Id);

            Playlist.Add(entry);
            Playlist.Sort(comparePlaylistEntries);

            _playlistEntries.Add(entry);

            if (!_playing)
                Play();

            return entry;
        }