/// <summary>Read in rating data from a TextReader</summary>
        /// <param name="reader">the <see cref="TextReader"/> to read from</param>
        /// <param name="user_mapping">mapping object for user IDs</param>
        /// <param name="item_mapping">mapping object for item IDs</param>
        /// <returns>the rating data</returns>
        public static IRatings Read(TextReader reader,	IEntityMapping user_mapping, IEntityMapping item_mapping)
        {
            var ratings = new Ratings();

            var split_chars = new char[]{ '\t', ' ', ',' };
            string line;

            while ( (line = reader.ReadLine()) != null )
            {
                if (line.Length == 0)
                    continue;

                string[] tokens = line.Split(split_chars);

                if (tokens.Length < 3)
                    throw new IOException("Expected at least three columns: " + line);

                int user_id = user_mapping.ToInternalID(int.Parse(tokens[0]));
                int item_id = item_mapping.ToInternalID(int.Parse(tokens[1]));
                double rating = double.Parse(tokens[2], CultureInfo.InvariantCulture);

                ratings.Add(user_id, item_id, rating);
            }
            return ratings;
        }
Beispiel #2
0
        public void CreateDomainsWithEvenlyDistributedUsers()
        {
            int count      = Ratings.Count;
            int numDomain1 = 1;

            foreach (var g in Ratings.GroupBy(r => r.User.Id).Shuffle())
            {
                int ratingPerDomain = g.Count() / NumDomains;

                //foreach (var r in g.Take(numDomain1))
                //{
                //    r.Domain = Domains["mlt"];
                //}

                for (int i = 0; i < NumDomains; i++)
                {
                    foreach (var r in g.Skip(i * ratingPerDomain + numDomain1).Take(ratingPerDomain))
                    {
                        r.Domain = Domains["ml" + i];
                    }
                }

                foreach (var r in g.Skip(NumDomains * ratingPerDomain))
                {
                    r.Domain = Domains["ml" + (NumDomains - 1)];
                }
            }
        }
Beispiel #3
0
        public void TestCountByUserCountByItem()
        {
            var ratings = new Ratings();
            ratings.Add(1, 4, 0.3);
            ratings.Add(1, 8, 0.2);
            ratings.Add(2, 4, 0.2);
            ratings.Add(2, 2, 0.6);
            ratings.Add(2, 5, 0.4);
            ratings.Add(3, 7, 0.2);
            ratings.Add(6, 3, 0.3);

            Assert.AreEqual(0, ratings.CountByUser[0]);
            Assert.AreEqual(2, ratings.CountByUser[1]);
            Assert.AreEqual(3, ratings.CountByUser[2]);
            Assert.AreEqual(1, ratings.CountByUser[3]);
            Assert.AreEqual(0, ratings.CountByUser[4]);
            Assert.AreEqual(0, ratings.CountByUser[5]);
            Assert.AreEqual(1, ratings.CountByUser[6]);

            Assert.AreEqual(0, ratings.CountByItem[0]);
            Assert.AreEqual(0, ratings.CountByItem[1]);
            Assert.AreEqual(1, ratings.CountByItem[2]);
            Assert.AreEqual(1, ratings.CountByItem[3]);
            Assert.AreEqual(2, ratings.CountByItem[4]);
            Assert.AreEqual(1, ratings.CountByItem[5]);
            Assert.AreEqual(0, ratings.CountByItem[6]);
            Assert.AreEqual(1, ratings.CountByItem[7]);
            Assert.AreEqual(1, ratings.CountByItem[8]);
        }
Beispiel #4
0
        public async Task <IActionResult> Edit(int id, [Bind("RatingId,BarberId,ConsumerId,RatingNumber,Comments")] Ratings ratings)
        {
            if (id != ratings.RatingId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ratings);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RatingsExists(ratings.RatingId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BarberId"]   = new SelectList(_context.Barber, "BarberId", "BarberId", ratings.BarberId);
            ViewData["ConsumerId"] = new SelectList(_context.Consumer, "ConsumerId", "ConsumerId", ratings.ConsumerId);
            return(View(ratings));
        }
 public EshuushuuOptions(Ratings rating, string tags, string source, string characters, string artist)
     : base(rating, tags, null, null)
 {
     this.Source = source;
     this.Characters = characters;
     this.Artist = artist;
 }
        [Test()] public void TestAddAndRemove()
        {
            var ratings = new Ratings();

            ratings.Add(1, 4, 0.3f);
            ratings.Add(1, 8, 0.2f);
            ratings.Add(2, 4, 0.2f);
            ratings.Add(2, 2, 0.6f);
            ratings.Add(2, 5, 0.4f);
            ratings.Add(3, 7, 0.2f);
            ratings.Add(6, 3, 0.3f);

            Assert.AreEqual(0.4f, ratings[2, 5]);
            Assert.AreEqual(0.3f, ratings[1, 4]);
            Assert.AreEqual(0.3f, ratings[6, 3]);
            Assert.AreEqual(7, ratings.Count);

            ratings.RemoveAt(ratings.GetIndex(1, 4));
            Assert.AreEqual(6, ratings.Count);
            ratings.RemoveAt(ratings.GetIndex(1, 8));
            Assert.AreEqual(5, ratings.Count);
            ratings.RemoveAt(ratings.GetIndex(2, 5));
            Assert.AreEqual(4, ratings.Count);
            ratings.RemoveAt(ratings.GetIndex(2, 2));
            Assert.AreEqual(3, ratings.Count);
            ratings.RemoveAt(ratings.GetIndex(2, 4));
            Assert.AreEqual(2, ratings.Count);
            ratings.RemoveAt(ratings.GetIndex(3, 7));
            Assert.AreEqual(1, ratings.Count);
            ratings.RemoveAt(ratings.GetIndex(6, 3));
            Assert.AreEqual(0, ratings.Count);
        }
        public ActionResult GiveRating(int id, Models.Event ratedEvent)
        {
            var thisEvent = db.events.Where(e => e.EventId == id).SingleOrDefault();

            if (DateTime.Now > thisEvent.EventDate)
            {
                Ratings rating = new Ratings();
                rating.Rating  = ratedEvent.Rating;
                rating.EventId = thisEvent.EventId;
                db.ratings.Add(rating);
                db.SaveChanges();
                var        eventsRatings   = db.ratings.Where(r => r.EventId == id).ToList();
                List <int> selectedRatings = new List <int>();
                foreach (var filteredRating in eventsRatings)
                {
                    selectedRatings.Add(filteredRating.Rating);
                }
                int sum           = selectedRatings.Sum();
                int averageRating = sum / selectedRatings.Count;
                thisEvent.Rating = averageRating;


                ratedEvent.Rating = thisEvent.Rating;

                db.SaveChanges();
            }
            return(RedirectToAction("GuestHome"));
        }
Beispiel #8
0
        public Response <bool> ReviewCourt(ReviewCourtRequest request)
        {
            var  response = new Response <bool>();
            Guid id       = Guid.NewGuid();
            var  newRate  = new Ratings()
            {
                UserId  = request.UserId,
                CourtId = request.CourtId,
                Rate    = request.Rate,
                Comment = request.Comment,
                Id      = id.ToString()
            };

            try
            {
                _ratingRepository.Add(newRate);
                _logger.LogInfo("user rated a court");
                response.Status  = System.Net.HttpStatusCode.OK;
                response.Payload = true;
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError("rating of court failed");
                response.Messages.Add(new ResponseMessage
                {
                    Type    = Contracts.Enums.ResponseMessageEnum.Exception,
                    Message = ex.Message,
                });
                response.Status = System.Net.HttpStatusCode.InternalServerError;
                return(response);
            }
        }
Beispiel #9
0
 public ImportListMovie()
 {
     Images       = new List <MediaCover.MediaCover>();
     Genres       = new List <string>();
     Translations = new List <MovieTranslation>();
     Ratings      = new Ratings();
 }
Beispiel #10
0
        Read(TextReader reader, IEntityMapping user_mapping, IEntityMapping item_mapping)
        {
            var ratings = new Ratings();

            var    split_chars = new char[] { '\t', ' ', ',' };
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length == 0)
                {
                    continue;
                }

                string[] tokens = line.Split(split_chars);

                if (tokens.Length < 3)
                {
                    throw new IOException("Expected at least three columns: " + line);
                }

                int    user_id = user_mapping.ToInternalID(int.Parse(tokens[0]));
                int    item_id = item_mapping.ToInternalID(int.Parse(tokens[1]));
                double rating  = double.Parse(tokens[2], CultureInfo.InvariantCulture);

                ratings.Add(user_id, item_id, rating);
            }
            return(ratings);
        }
Beispiel #11
0
 public EshuushuuOptions(Ratings rating, string tags, string source, string characters, string artist, int? page, int? limit)
     : base(rating, tags, page, limit)
 {
     this.Source = source;
     this.Characters = characters;
     this.Artist = artist;
 }
        public List <CharacteristicVM> getStress(int psid)
        {
            List <Ratings> Ratingm        = new List <Ratings>();
            var            countIntrovert = getIntrovert(psid);

            var countSensing = getSensitive(psid) == null ? null : getSensitive(psid);

            var countThinking = getThinking(psid);

            var countJudging = getJudging(psid);



            var extrovert = countIntrovert.Where(x => x.answer != null).Count();

            var introvert = countIntrovert.Where(x => x.altanswer != null).Count();// == 0 ? 0 : countIntrovert.Where(x => x.altanswer.Equals("X")).Count();

            //var introvert = countIntrovert.Where(x => x.altanswer.Equals("X")).Count() == 0 ? 0 : countIntrovert.Where(x => x.altanswer.Equals("X")).Count();

            var sensing = countSensing.Where(x => x.answer != null).Count();

            var intu = countSensing.Where(x => x.altanswer != null).Count();

            var thinking = countThinking.Where(x => x.answer != null).Count();

            var feeling = countThinking.Where(x => x.altanswer != null).Count();

            var judging = countJudging.Where(x => x.answer != null).Count();

            var percieving = countJudging.Where(x => x.altanswer != null).Count();


            var ieresult = extrovert > introvert == true ? "E" : "I";

            var siResult = sensing > intu == true ? "S" : "N";

            var tfResult = thinking > feeling == true ? "T" : "F";

            var jpresult = judging > percieving == true ? "J" : "P";

            string mmm = ieresult + siResult + tfResult + jpresult;

            var sss = new Ratings
            {
                Rating = ieresult + siResult + tfResult + jpresult
            };

            Ratingm.Add(sss);

            var getkey = (from m in _context.Characteristic

                          where m.Rating == mmm && m.Key == "Stress Management"

                          select new CharacteristicVM
            {
                Stress = m.Quality
            }).ToList();

            return(getkey);
        }
Beispiel #13
0
        public Ratings RateUser(int userId, int points)
        {
            /*
             * TODO ...
             *      check if user is not rating himself,
             *      check if user is not rating other user with same profession,
             *      authenticate the users that are providing rating by phone number
             */
            Users user = GetUserById(userId);

            if (user == null)
            {
                throw new NoEntryFoundException(userId, typeof(Users).Name);
            }

            Ratings rate = new Ratings
            {
                UserId           = user.Id,
                FeedbackPoints   = points,
                FeedbackDateTime = DateTime.UtcNow
            };

            FeedbackRepository.Add(rate);

            user.RatingSum += rate.FeedbackPoints;
            user.RatingCount++;
            UsersRepository.Update(user);

            return(rate);
        }
        public async Task <IActionResult> Edit(int id, [Bind("RatingId,CriticId,GameId,Mark")] Ratings ratings)
        {
            if (id != ratings.RatingId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ratings);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RatingsExists(ratings.RatingId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CriticId"] = new SelectList(_context.Critics, "CriticId", "Username", ratings.CriticId);
            ViewData["GameId"]   = new SelectList(_context.Games, "GameId", "Name", ratings.GameId);
            return(View(ratings));
        }
Beispiel #15
0
        public bool PostGame([FromBody] GameResult gameResult)
        {
            try
            {
                ValidateGameResult(gameResult);

                var winningPlayer = GetOrCreatePlayer(gameResult.Winner);
                var losingPlayer  = GetOrCreatePlayer(gameResult.Loser);

                var game = GameHandler.AddGame(new Models.Game
                {
                    Scores = new List <GameScore>
                    {
                        new GameScore
                        {
                            PlayerId = winningPlayer.Id,
                            Score    = 1.0
                        },
                        new GameScore
                        {
                            PlayerId = losingPlayer.Id,
                            Score    = 0.0
                        }
                    }
                });

                Ratings.CalculateNewRatings(game);

                return(true);
            }
            catch (Exception /*ex*/)
            {
                return(false);
            }
        }
Beispiel #16
0
        private void SaveNewRating(object x = null)
        {
            if (RatingNewDetailModel.Nick == null || RatingNewDetailModel.NumericEvaluation <= 0)
            {
                _messageDialogService.Show(
                    "Error",
                    $"Please specify correct nick and numerical rating.",
                    MessageDialogButtonConfiguration.OK,
                    MessageDialogResult.OK);

                return;
            }
            RatingNewDetailModel.RatedMovieId = DisplayDetailModel.Id;

            _ratingRepository.Create(RatingNewDetailModel);
            Ratings.Add(RatingNewDetailModel);

            AverageRating = (AverageRating == 0.0)
                ? RatingNewDetailModel.NumericEvaluation
                : (AverageRating + RatingNewDetailModel.NumericEvaluation) / 2;
            HasRatings        = Visibility.Visible;
            DoesntHaveRatings = Visibility.Collapsed;

            DiscardNewRating();
        }
Beispiel #17
0
        private void LoadRatings()
        {
            var ratingCounter = 0;
            var ratingValues  = 0;

            Ratings.Clear();
            var allRatings = _ratingRepository.GetAllByMovieId(DisplayDetailModel.Id);

            foreach (var rating in allRatings)
            {
                if (rating != null)
                {
                    Ratings.Add(rating);
                    ratingValues += rating.NumericEvaluation;
                    ratingCounter++;
                }
            }

            if (ratingCounter != 0)
            {
                AverageRating     = (double)ratingValues / ratingCounter;
                HasRatings        = Visibility.Visible;
                DoesntHaveRatings = Visibility.Collapsed;
            }
            else
            {
                AverageRating     = 0;
                HasRatings        = Visibility.Collapsed;
                DoesntHaveRatings = Visibility.Visible;
            }
        }
Beispiel #18
0
        protected void ReviewArticle_OnBeforeSave(object sender, ArticleEventArgs e)
        {
            var total = 0M;

            Ratings.Where(r_ => r_.Type != "Summary").ToList().ForEach(r => total += r.Rating);
            Ratings.Single(r_ => r_.Type == "Summary").Rating = Math.Round(total / Ratings.Count(r_ => r_.Type != "Summary"), 1);
        }
Beispiel #19
0
        private void RenderHtml()
        {
            StringBuilder writer = new StringBuilder();

            writer.Append(Ratings.Display(ThisCustomer, ProductID, 0, 0, 0, SkinID));
            ltContent.Text = writer.ToString();
        }
Beispiel #20
0
        public async Task <Response <RatingToReturnDTO> > RateComplain(string complaintId, string userId, RatingDTO ratingDTO)
        {
            Response <RatingToReturnDTO> response = new Response <RatingToReturnDTO>();

            if (await _ratingsRepo.FindUserRating(userId, complaintId) != null)
            {
                response.Message = "sorry!, you can only rate a comment once";
                return(response);
            }
            var ratingEntity = new Ratings()
            {
                Rating      = ratingDTO.Rating,
                UserId      = userId,
                ComplaintId = complaintId,
            };

            if (await _ratingsRepo.Add(ratingEntity))
            {
                var ratingToReturnDTO = new RatingToReturnDTO()
                {
                    RatingId    = ratingEntity.Id,
                    Rating      = ratingEntity.Rating,
                    UserId      = ratingEntity.UserId,
                    ComplaintId = ratingEntity.ComplaintId,
                };
                response.Success = true;
                response.Data    = ratingToReturnDTO;
                response.Message = "Rating added successfully";
                return(response);
            }
            response.Message = "Failed to add rating";
            return(response);
        }
Beispiel #21
0
        public static List<Movie> GetRecommendations(List<Movie> all, Dictionary<int, int> newRanks, List<Tuple<int, int, float>> oldRanks)
        {
            int newUserId = 0;
            Ratings ratings = new Ratings();

            foreach (var r in oldRanks)
            {
                ratings.Add(r.Item1, r.Item2, r.Item3);
                if (r.Item1 > newUserId) newUserId = r.Item1;
            }

            // this makes us sure that the new user has a unique id (bigger than all other)
            newUserId = newUserId + 1;

            foreach (var k in newRanks)
            {
                ratings.Add(newUserId, k.Key, (float)k.Value);
            }

            var engine = new BiPolarSlopeOne();

            // different algorithm:
            // var engine = new UserItemBaseline();

            engine.Ratings = ratings;

            engine.Train(); // warning: this could take some time!

            return all.Select(m =>
                                {
                                    m.Rank = engine.Predict(newUserId, m.Id); // do the prediction!
                                    return m;
                                }).ToList();
        }
Beispiel #22
0
        async Task ExecuteLoadLectionRatingsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Ratings.Clear();
                //var messages = await DataStore.GetAllMessagesAsync(true);
                var result = await DataStore.GetAllLecitonRatings();

                foreach (var rating in result)
                {
                    Ratings.Add(rating);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
            /// <summary>
            /// Generates a collection of venues from the input CSV data
            /// </summary>
            /// <param name="data"></param>
            /// <returns></returns>
            IEnumerable <Venue> CreateVenues(IEnumerable <string[]> data)
            {
                var headers = data.First();
                var rows    = data.Skip(1);

                var venues = new List <Venue>();

                foreach (var row in rows)
                {
                    var dic = new Dictionary <string, string>();
                    for (var i = 0; i < row.Count(); i++)
                    {
                        //Replace any double quotes with single quotes
                        dic[headers[i]] = row[i].Replace("\"\"", "\"");
                    }

                    var ratings = new Ratings(Convert.ToDouble(dic["stars_beer"]),
                                              Convert.ToDouble(dic["stars_atmosphere"]), Convert.ToDouble(dic["stars_amenities"]),
                                              Convert.ToDouble(dic["stars_value"]));

                    var contacts = new Contacts(dic["address"], dic["phone"], dic["twitter"]);

                    var location = new Location(Convert.ToDouble(dic["lat"]), Convert.ToDouble(dic["lng"]));

                    var tags = dic["tags"].Split(",");

                    venues.Add(new Venue(dic["name"], dic["category"], new Uri(dic["url"]), Convert.ToDateTime(dic["date"]), new Uri(dic["thumbnail"]), location, contacts, ratings, tags));
                }

                return(venues);
            }
Beispiel #24
0
 public SearchOption(Ratings rating, string tags, int? page, int? limit)
 {
     this.Rating = rating;
     this.Tags = tags;
     this.Limit = limit;
     this.Page = page;
 }
Beispiel #25
0
		[Test()] public void TestAddAndRemove()
		{
			var ratings = new Ratings();
			ratings.Add(1, 4, 0.3f);
			ratings.Add(1, 8, 0.2f);
			ratings.Add(2, 4, 0.2f);
			ratings.Add(2, 2, 0.6f);
			ratings.Add(2, 5, 0.4f);
			ratings.Add(3, 7, 0.2f);
			ratings.Add(6, 3, 0.3f);

			Assert.AreEqual(0.4f, ratings[2, 5]);
			Assert.AreEqual(0.3f, ratings[1, 4]);
			Assert.AreEqual(0.3f, ratings[6, 3]);
			Assert.AreEqual(7, ratings.Count);

			ratings.RemoveAt(ratings.GetIndex(1, 4));
			Assert.AreEqual(6, ratings.Count);
			ratings.RemoveAt(ratings.GetIndex(1, 8));
			Assert.AreEqual(5, ratings.Count);
			ratings.RemoveAt(ratings.GetIndex(2, 5));
			Assert.AreEqual(4, ratings.Count);
			ratings.RemoveAt(ratings.GetIndex(2, 2));
			Assert.AreEqual(3, ratings.Count);
			ratings.RemoveAt(ratings.GetIndex(2, 4));
			Assert.AreEqual(2, ratings.Count);
			ratings.RemoveAt(ratings.GetIndex(3, 7));
			Assert.AreEqual(1, ratings.Count);
			ratings.RemoveAt(ratings.GetIndex(6, 3));
			Assert.AreEqual(0, ratings.Count);
		}
Beispiel #26
0
        /// <summary>
        /// Добавляет рейтинг в БД
        /// </summary>
        /// <param name="rating">Рейтинг</param>
        /// <returns>Возвращает true в случае успеха</returns>
        public async Task <bool> AddRatingsOnFilm(Ratings rating)
        {
            try
            {
                return(await Task.Run(() =>
                {
                    using (UserDB db = new UserDB())
                    {
                        // Если пользователь не добавил рейтинг то добавь
                        if (GetMyRatingFilm(rating.IdFilm, rating.IdUser) != null)
                        {
                            db.Ratings.Add(rating);
                            db.SaveChanges();

                            return true;
                        }

                        return false;
                    }
                }));
            }
            catch (Exception)
            {
                // Обработать какую-нибудь ошибку (если она будет по ходу написания программы)
            }

            return(false);; // Возвращаем null, в случае, если не найдено ничего
        }
Beispiel #27
0
        public void SubmitFeedbackAsync(Song song, Ratings rating)
        {
            try
            {
                WebClient client = new WebClient();
                client.Headers.Add("content-type", "text-xml");
                client.UploadDataCompleted += new UploadDataCompletedEventHandler(SubmitFeedback_UploadDataCompleted);
                Uri uri = new Uri(String.Format(BASE_URL_LID, _rid, _lid, "addFeedback"));

                List <object> parameters = new List <object>();
                parameters.Add(GetTimestamp());
                parameters.Add(_authenticationToken);
                parameters.Add(song.StationId);
                parameters.Add(song.MusicId);
                parameters.Add(song.UserSeed);
                parameters.Add(String.Empty); //TestStrategy--wtf?
                parameters.Add(rating == Ratings.Like);
                parameters.Add(false);        //IsCreatorQuickMix
                parameters.Add(song.SongType);

                string xml          = GetXml("station.addFeedback", parameters);
                string encryptedXml = EncryptionHelper.EncryptString(xml);
                client.UploadDataAsync(uri, "POST", System.Text.Encoding.ASCII.GetBytes(encryptedXml));
            }
            catch (Exception exception)
            {
                if (ExceptionReceived != null)
                {
                    ExceptionReceived(this, new EventArgs <Exception>(exception));
                }
            }
        }
Beispiel #28
0
 public Movie(int id, String name, Genres genre, Ratings rating)
 {
     Id = id;
     Name = name;
     Genre = genre;
     Rating = rating;
 }
Beispiel #29
0
        public async Task <bool> UpdateRatingsOnFilm(Ratings rating)
        {
            try
            {
                return(await Task.Run(() =>
                {
                    using (UserDB db = new UserDB())
                    {
                        // Если у пользователя есть рейтинг то обнови
                        if (GetMyRatingFilm(rating.IdFilm, rating.IdUser) != null)
                        {
                            db.Entry(rating).State = System.Data.Entity.EntityState.Modified;;
                            db.SaveChanges();

                            return true;
                        }

                        return false;
                    }
                }));
            }
            catch (Exception)
            {
                // Обработать какую-нибудь ошибку (если она будет по ходу написания программы)
            }

            return(false);; // Возвращаем null, в случае, если не найдено ничего
        }
Beispiel #30
0
        static void Main(string[] args)
        {
            // delete all ratings and stats
            Console.WriteLine("Delete all ratings");
            PlayerHandler.DeleteAllPlayerSeasons();
            RatingHandler.DeleteAllRatings();

            // get all games in chronological order
            Console.WriteLine("Get games");
            var games = GameHandler.GetGamesAfter(int.MinValue, SortOrder.Ascending);

            // calculate new ratings
            Console.WriteLine($"Calculate new ratings for {games.Count} games");
            var completed = 0;

            foreach (var game in games)
            {
                Ratings.CalculateNewRatings(game);

                ++completed;
                Console.Write($"\rProgress: {completed}/{games.Count} ({completed / (double)games.Count:P1})");
            }

            Console.WriteLine();
        }
Beispiel #31
0
 private void CreateRatingsColumns()
 {
     foreach (string ratingsName in Ratings.GetRatingsList().Keys)
     {
         this.dgRealDrivers.Columns.Add(ratingsName + "TextBoxColumn", Ratings.GetRatingsList()[ratingsName].Group + "_" + Ratings.GetRatingsList()[ratingsName].Name);
     }
 }
        [Test()] public void TestCountByUserCountByItem()
        {
            var ratings = new Ratings();

            ratings.Add(1, 4, 0.3f);
            ratings.Add(1, 8, 0.2f);
            ratings.Add(2, 4, 0.2f);
            ratings.Add(2, 2, 0.6f);
            ratings.Add(2, 5, 0.4f);
            ratings.Add(3, 7, 0.2f);
            ratings.Add(6, 3, 0.3f);

            Assert.AreEqual(0, ratings.CountByUser[0]);
            Assert.AreEqual(2, ratings.CountByUser[1]);
            Assert.AreEqual(3, ratings.CountByUser[2]);
            Assert.AreEqual(1, ratings.CountByUser[3]);
            Assert.AreEqual(0, ratings.CountByUser[4]);
            Assert.AreEqual(0, ratings.CountByUser[5]);
            Assert.AreEqual(1, ratings.CountByUser[6]);

            Assert.AreEqual(0, ratings.CountByItem[0]);
            Assert.AreEqual(0, ratings.CountByItem[1]);
            Assert.AreEqual(1, ratings.CountByItem[2]);
            Assert.AreEqual(1, ratings.CountByItem[3]);
            Assert.AreEqual(2, ratings.CountByItem[4]);
            Assert.AreEqual(1, ratings.CountByItem[5]);
            Assert.AreEqual(0, ratings.CountByItem[6]);
            Assert.AreEqual(1, ratings.CountByItem[7]);
            Assert.AreEqual(1, ratings.CountByItem[8]);
        }
        public void Update(RatingsBO rating)
        {
            Ratings editRating = AutoMapper <RatingsBO, Ratings> .Map(rating);

            Database.RatingsUowRepository.Update(editRating);
            Database.Save();
        }
Beispiel #34
0
 public Gravatar(string email, IconSets iconset, Ratings rating, int size)
 {
     Email = email;
     IconSet = iconset;
     Rating = rating;
     Size = size;
 }
Beispiel #35
0
        public ActionResult newReact(postDetailsViewModel model)
        {
            var usertmp = User.Identity.GetUserId();
            var rated   = db.Ratings.Single(x => x.PostsID == model.postId && x.UserId == usertmp);

            if (rated == null)
            {
                var newReact = new Ratings()
                {
                    PostsID = model.postId,
                    UserId  = User.Identity.GetUserId(),
                    reacted = true
                };

                db.Ratings.Add(newReact);
                var result = db.SaveChanges();

                if (result > 0)
                {
                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
 /// <summary>
 /// Create a point from a sparse set of (x,y) pairs where the x is the MovieId minus one (to make it zero-based) and the
 /// y is the Rating.
 /// </summary>
 /// <param name="dimensions">Total number of dimensions, including those which are missing a value, hence have
 /// no corresponding pair (MovieId,Rating).</param>
 /// <returns>A new HyperContrastedPoint or SparsePoint, whose UniqueId is the ReviewerId.</returns>
 public UnsignedPoint ToPoint(int dimensions)
 {
     if (Point == null)
     {
         var useHyperContrastedPoints = true;
         if (useHyperContrastedPoints)
         {
             Point = new HyperContrastedPoint(
                 MovieIds.Select(movieId => movieId - 1).ToList(),
                 Ratings.Select(rating => (uint)rating).ToList(),
                 dimensions,
                 new[] { 0U, 6U },
                 ReviewerId
                 );
         }
         else
         {
             Point = new SparsePoint(
                 MovieIds.Select(movieId => movieId - 1).ToList(),
                 Ratings.Select(rating => (uint)rating).ToList(),
                 dimensions,
                 0U,
                 ReviewerId
                 );
         }
     }
     return(Point);
 }
Beispiel #37
0
        private void Render()
        {
            StringBuilder writer = new StringBuilder();

            writer.Append(Ratings.DisplayForCustomer(TargetCustomer.CustomerID, SkinID));
            ltContent.Text = writer.ToString();
        }
Beispiel #38
0
        public async Task <IActionResult> DeleteRate(Ratings ratings)
        {
            db.Ratings.Remove(ratings);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #39
0
        public virtual bool PassesFilter(FilterProperties filters)
        {
            if (filters == null)
            {
                return(true);
            }

            if (Ratings.Level(ParentalRating) > filters.RatedLessThan)
            {
                return(false);
            }
            if (Ratings.Level(ParentalRating) < filters.RatedGreaterThan)
            {
                return(false);
            }
            if (filters.IsFavorite != null && UserData != null && UserData.IsFavorite != filters.IsFavorite)
            {
                return(false);
            }
            if (!filters.OfTypes.Contains(DisplayMediaType))
            {
                return(false);
            }

            return(true);
        }
Beispiel #40
0
        /// <summary>Read in rating data from a TextReader</summary>
        /// <param name="reader">the <see cref="TextReader"/> to read from</param>
        /// <param name="user_mapping">mapping object for user IDs</param>
        /// <param name="item_mapping">mapping object for item IDs</param>
        /// <param name="ignore_first_line">if true, ignore the first line</param>
        /// <returns>the rating data</returns>
        public static IRatings Read(TextReader reader, IMapping user_mapping = null, IMapping item_mapping = null, bool ignore_first_line = false)
        {
            if (user_mapping == null)
                user_mapping = new IdentityMapping();
            if (item_mapping == null)
                item_mapping = new IdentityMapping();
            if (ignore_first_line)
                reader.ReadLine();

            var ratings = new Ratings();

            string line;
            while ( (line = reader.ReadLine()) != null )
            {
                if (line.Length == 0)
                    continue;

                string[] tokens = line.Split(Constants.SPLIT_CHARS);

                if (tokens.Length < 3)
                    throw new FormatException("Expected at least 3 columns: " + line);

                int user_id = user_mapping.ToInternalID(tokens[0]);
                int item_id = item_mapping.ToInternalID(tokens[1]);
                float rating = float.Parse(tokens[2], CultureInfo.InvariantCulture);

                ratings.Add(user_id, item_id, rating);
            }
            ratings.InitScale();
            return ratings;
        }
Beispiel #41
0
		public Movie(int id, String name, Genres genre, Ratings rating, string imageUrl, string synopsis)
		{
			Id = id;
			Name = name;
			Genre = genre;
			Rating = rating;
			ImageUrl = imageUrl;
			Synopsis = synopsis;
		}
		IRatings CreateRatings2()
		{
			var ratings = new Ratings();
			ratings.Add(1, 5, 0.9f);
			ratings.Add(7, 9, 0.5f);
			ratings.InitScale();

			return ratings;
		}
 // Here we serialize our UserData object of myData
 public string SerializeObject(Ratings pObject)
 {
     string XmlizedString = null;
     MemoryStream memoryStream = new MemoryStream();
     XmlSerializer xs = new XmlSerializer(typeof(Ratings));
     XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
     xs.Serialize(xmlTextWriter, pObject);
     memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
     XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
     return XmlizedString;
 }
		IRatings CreateRatings()
		{
			var ratings = new Ratings();
			ratings.Add(1, 4, 0.3f);
			ratings.Add(1, 8, 0.2f);
			ratings.Add(2, 4, 0.2f);
			ratings.Add(2, 2, 0.6f);
			ratings.Add(2, 5, 0.4f);
			ratings.Add(3, 7, 0.2f);
			ratings.Add(6, 3, 0.3f);

			return ratings;
		}
        public void TestNewUserInTestSet()
        {
            var recommender = new BiPolarSlopeOne();

            var training_data = new Ratings();
            training_data.Add(0, 0, 1.0f);
            training_data.Add(1, 1, 5.0f);

            recommender.Ratings = training_data;
            recommender.Train();

            Assert.AreEqual( 3.0, recommender.Predict(2, 1) );
        }
Beispiel #46
0
        public void TestComputeCorrelation()
        {
            // create test objects
            var ratings = new Ratings();
            ratings.Add(0, 1, 0.3);
            ratings.Add(0, 4, 0.2);
            ratings.Add(1, 2, 0.6);
            ratings.Add(1, 3, 0.4);
            ratings.Add(1, 4, 0.2);

            // test
            Assert.AreEqual(0, Pearson.ComputeCorrelation(ratings, EntityType.USER, 0, 1, 0));
        }
Beispiel #47
0
		[Test()] public void TestMinRatingMaxRating()
		{
			var ratings = new Ratings();
			ratings.Add(1, 4, 0.3f);
			ratings.Add(1, 8, 0.2f);
			ratings.Add(2, 4, 0.2f);
			ratings.Add(2, 2, 0.6f);
			ratings.Add(2, 5, 0.4f);
			ratings.Add(3, 7, 0.2f);
			ratings.Add(6, 3, 0.3f);

			Assert.AreEqual(0.6f, ratings.Scale.Max);
			Assert.AreEqual(0.2f, ratings.Scale.Min);
		}
Beispiel #48
0
        public void TestByUserByItem()
        {
            var ratings = new Ratings();
            ratings.Add(1, 4, 0.3);
            ratings.Add(1, 8, 0.2);
            ratings.Add(2, 4, 0.2);
            ratings.Add(2, 2, 0.6);
            ratings.Add(2, 5, 0.4);
            ratings.Add(3, 7, 0.2);
            ratings.Add(6, 3, 0.3);

            Assert.IsTrue(new HashSet<int>( new int[] { 0, 1 } ).SetEquals(ratings.ByUser[1]));
            Assert.IsTrue(new HashSet<int>( new int[] { 0, 2 } ).SetEquals(ratings.ByItem[4]));
        }
Beispiel #49
0
		[Test()] public void TestMaxUserIDMaxItemID()
		{
			var ratings = new Ratings();
			ratings.Add(1, 4, 0.3f);
			ratings.Add(1, 8, 0.2f);
			ratings.Add(2, 4, 0.2f);
			ratings.Add(2, 2, 0.6f);
			ratings.Add(2, 5, 0.4f);
			ratings.Add(3, 7, 0.2f);
			ratings.Add(6, 3, 0.3f);

			Assert.AreEqual(6, ratings.MaxUserID);
			Assert.AreEqual(8, ratings.MaxItemID);
		}
Beispiel #50
0
        public static IRatings CreateRandomRatings(int num_users, int num_items, int num_ratings)
        {
            var random = MyMediaLite.Random.GetInstance();

            var ratings = new Ratings();
            for (int i = 0; i < num_ratings; i++)
            {
                int user_id = random.Next(num_users);
                int item_id = random.Next(num_items);
                int rating_value = 1 + random.Next(5);
                ratings.Add(user_id, item_id, rating_value);
            }
            return ratings;
        }
Beispiel #51
0
        public void TestNewItemInTestSet()
        {
            var recommender = new SlopeOne();

            var training_data = new Ratings();
            training_data.Add(0, 0, 1.0f);
            training_data.Add(1, 1, 5.0f);
            training_data.InitScale();

            recommender.Ratings = training_data;
            recommender.Train();

            Assert.AreEqual( 3.0f, recommender.Predict(0, 2) );
        }
Beispiel #52
0
		[Test()] public void TestComputeCorrelation()
		{
			// create test objects
			var ratings = new Ratings();
			ratings.Add(0, 1, 0.3f);
			ratings.Add(0, 4, 0.2f);
			ratings.Add(1, 2, 0.6f);
			ratings.Add(1, 3, 0.4f);
			ratings.Add(1, 4, 0.2f);

			// test
			var p = new Pearson(ratings.AllUsers.Count, 0f);
			Assert.AreEqual(0, p.ComputeCorrelation(ratings, EntityType.USER, 0, 1));
		}
        public void TestNewItemInTestSet()
        {
            var recommender = new BiPolarSlopeOne();
            recommender.MinRating = 1;
            recommender.MaxRating = 5;

            var training_data = new Ratings();
            training_data.Add(0, 0, 1.0);
            training_data.Add(1, 1, 5.0);

            recommender.Ratings = training_data;
            recommender.Train();

            Assert.AreEqual( 3.0, recommender.Predict(0, 2) );
        }
Beispiel #54
0
        public IList<Movie> Search(String keywords, Genres? genre, Ratings? rating)
        {
            var movies = _Movies.Where(m => m.Name.ToLower().Contains(keywords.ToLower()));

            if (genre.HasValue)
            {
                movies = movies.Where(m => m.Genre == genre.Value);
            }

            if (rating.HasValue)
            {
                movies = movies.Where(m => m.Rating == rating.Value);
            }

            return movies.ToList();
        }
Beispiel #55
0
        public void TestAddRating()
        {
            var ratings = new Ratings();
            ratings.Add(1, 4, 0.3);
            ratings.Add(1, 8, 0.2);
            ratings.Add(2, 4, 0.2);
            ratings.Add(2, 2, 0.6);
            ratings.Add(2, 5, 0.4);
            ratings.Add(3, 7, 0.2);
            ratings.Add(6, 3, 0.3);

            Assert.AreEqual(0.4, ratings.Get(2, 5));
            Assert.AreEqual(0.3, ratings.Get(1, 4));
            Assert.AreEqual(0.3, ratings.Get(6, 3));
            Assert.AreEqual(7, ratings.Count);
        }
		public void TestConstructor()
		{
			var ratings = new Ratings();
			ratings.Add(0, 0, 5.0f);
			ratings.Add(0, 1, 4.5f);
			ratings.Add(1, 0, 1.0f);
			ratings.Add(1, 1, 2.5f);

			var split1 = new RatingsSimpleSplit(ratings, 0.25);
			Assert.AreEqual(3, split1.Train[0].Count);
			Assert.AreEqual(1, split1.Test[0].Count);

			var split2 = new RatingsSimpleSplit(ratings, 0.5);
			Assert.AreEqual(2, split2.Train[0].Count);
			Assert.AreEqual(2, split2.Test[0].Count);
		}
Beispiel #57
0
		[Test()] public void TestAdd()
		{
			var ratings = new Ratings();
			ratings.Add(1, 4, 0.3f);
			ratings.Add(1, 8, 0.2f);
			ratings.Add(2, 4, 0.2f);
			ratings.Add(2, 2, 0.6f);
			ratings.Add(2, 5, 0.4f);
			ratings.Add(3, 7, 0.2f);
			ratings.Add(6, 3, 0.3f);

			Assert.AreEqual(0.4f, ratings[2, 5]);
			Assert.AreEqual(0.3f, ratings[1, 4]);
			Assert.AreEqual(0.3f, ratings[6, 3]);
			Assert.AreEqual(7, ratings.Count);
		}
Beispiel #58
0
		[Test()] public void TestCreate()
		{
			var ratings = new Ratings();
			ratings.Add(0, 1, 0.3f);
			ratings.Add(0, 2, 0.6f);
			ratings.Add(0, 4, 0.2f);
			ratings.Add(1, 3, 0.4f);
			ratings.Add(1, 4, 0.2f);
			ratings.Add(2, 0, 0.1f);
			ratings.Add(2, 1, 0.3f);

			var correlation_matrix = new Pearson(ratings.MaxUserID + 1, 0f);
			correlation_matrix.ComputeCorrelations(ratings, EntityType.USER);
			Assert.AreEqual(3, correlation_matrix.NumberOfRows);
			Assert.IsTrue(correlation_matrix.IsSymmetric);
			Assert.AreEqual(0, correlation_matrix[0, 1]);
		}
Beispiel #59
0
		[Test()] public void TestComputeCorrelations()
		{
			// create test objects
			var pearson = new Pearson(3, 0f);
			var rating_data = new Ratings();
			rating_data.Add(0, 1, 0.3f);
			rating_data.Add(0, 2, 0.6f);
			rating_data.Add(0, 4, 0.2f);
			rating_data.Add(1, 3, 0.4f);
			rating_data.Add(1, 4, 0.2f);
			rating_data.Add(2, 0, 0.1f);
			rating_data.Add(2, 1, 0.3f);
			// test
			pearson.Shrinkage = 0;
			pearson.ComputeCorrelations(rating_data, EntityType.USER);

			Assert.AreEqual(0, pearson[0, 2]);
		}
Beispiel #60
0
        public void TestRemoveUser()
        {
            var ratings = new Ratings();
            ratings.Add(1, 4, 0.3);
            ratings.Add(1, 8, 0.2);
            ratings.Add(2, 4, 0.2);
            ratings.Add(2, 2, 0.6);
            ratings.Add(2, 5, 0.4);
            ratings.Add(3, 7, 0.2);
            ratings.Add(3, 3, 0.3);

            Assert.AreEqual(7, ratings.Count);
            Assert.AreEqual(0.4, ratings.Get(2, 5));
            ratings.RemoveUser(2);
            Assert.AreEqual(5, ratings.Count);

            double rating;
            Assert.IsFalse(ratings.TryGet(2, 5, out rating));
        }