Exemplo n.º 1
0
 public static void FiimDbUpdate(ObservableCollection <FiimPlayerEntry> players, bool redWin, bool blackWin)
 {
     using (var context = new SaluteDbContext())
     {
         foreach (var player in players)
         {
             var         currentNick  = player.Nick;
             IFiimRating fiimInSeason =
                 context.SeasonRatingFiimDbSet.FirstOrDefault(t => t.Nick == currentNick);
             IFiimRating fiimInSeries =
                 context.SeriesRatingFiimDbSet.FirstOrDefault(t => t.Nick == currentNick);
             IFiimRating fiimInWeek = context.WeekRatingFiimDbSet.FirstOrDefault(t => t.Nick == currentNick);
             IFiimRating fiimInAl   = context.AllTimeRatingFiimDbSet.FirstOrDefault(t => t.Nick == currentNick);
             if (fiimInSeason != null)
             {
                 GeneralFiimDbUpdate(player, fiimInSeason, redWin, blackWin);
             }
             else
             {
                 var newPlayer = new SeasonRatingFiim(player, redWin, blackWin);
                 context.SeasonRatingFiimDbSet.Add(newPlayer);
             }
             if (fiimInSeries != null)
             {
                 GeneralFiimDbUpdate(player, fiimInSeries, redWin, blackWin);
             }
             else
             {
                 var newPlayer = new SeriesRatingFiim(player, redWin, blackWin);
                 context.SeriesRatingFiimDbSet.Add(newPlayer);
             }
             if (fiimInWeek != null)
             {
                 GeneralFiimDbUpdate(player, fiimInWeek, redWin, blackWin);
             }
             else
             {
                 var newPlayer = new WeekRatingFiim(player, redWin, blackWin);
                 context.WeekRatingFiimDbSet.Add(newPlayer);
             }
             if (fiimInAl != null)
             {
                 GeneralFiimDbUpdate(player, fiimInAl, redWin, blackWin);
             }
             else
             {
                 var newPlayer = new AllTimeRatingFiim(player, redWin, blackWin);
                 context.AllTimeRatingFiimDbSet.Add(newPlayer);
             }
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public static void SetPosition(ObservableCollection <PlayerEntry> players)
 {
     using (var context = new SaluteDbContext())
     {
         var inSeasonSorted  = context.SeasonRatingDbSet.Where(x => x.Rating != 0 && x.Rating != null).OrderByDescending(x => x.Rating).ToList();
         var inSeriesSorted  = context.SeriesRatingDbSet.Where(x => x.Rating != 0 && x.Rating != null).OrderByDescending(x => x.Rating).ToList();
         var inAllTimeSorted =
             context.AllTimeRatingDbSet.Where(x => x.Rating != 0 && x.Rating != null)
             .OrderByDescending(x => x.Rating)
             .ToList();
         foreach (var sr in context.SeasonRatingDbSet)
         {
             if (!string.IsNullOrEmpty(sr.Position) && sr.Position != "0")
             {
                 sr.Position = sr.Position + "," + (inSeasonSorted.FindIndex(x => x.Nick == sr.Nick) + 1);
             }
             else
             {
                 sr.Position = (inSeasonSorted.FindIndex(x => x.Nick == sr.Nick) + 1).ToString();
             }
         }
         foreach (var sr in context.SeriesRatingDbSet)
         {
             if (!string.IsNullOrEmpty(sr.Position) && sr.Position != "0")
             {
                 sr.Position = sr.Position + "," + (inSeriesSorted.FindIndex(x => x.Nick == sr.Nick) + 1);
             }
             else
             {
                 sr.Position = (inSeriesSorted.FindIndex(x => x.Nick == sr.Nick) + 1).ToString();
             }
         }
         foreach (var alr in context.AllTimeRatingDbSet)
         {
             if (!string.IsNullOrEmpty(alr.Position) && alr.Position != "0")
             {
                 alr.Position = alr.Position + "," + (inAllTimeSorted.FindIndex(x => x.Nick == alr.Nick) + 1);
             }
             else
             {
                 alr.Position = (inAllTimeSorted.FindIndex(x => x.Nick == alr.Nick) + 1).ToString();
             }
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public static void ApplyRatio()
 {
     using (var context = new SaluteDbContext())
     {
         var seasonRedSum   = context.SeasonRatingFiimDbSet.Sum(t => t.RedWin) / 7;
         var seasonBlackSum = context.SeasonRatingFiimDbSet.Sum(t => t.BlackWin) / 3;
         var seasonRatio    = CountRatio(seasonRedSum ?? 0, seasonBlackSum ?? 0);
         foreach (var player in context.SeasonRatingFiimDbSet)
         {
             var pureRedResult    = (player.RedWin ?? 0) * 2;
             var pureBlackResult  = (player.BlackWin ?? 0) * 2;
             var additionalResult = player.ScoreAdditional;
             if (seasonRedSum > seasonBlackSum)
             {
                 player.Rating = Math.Round((pureRedResult + additionalResult + pureBlackResult * seasonRatio) / player.Games, 2) * 100;
             }
             else if (seasonBlackSum > seasonRedSum)
             {
                 player.Rating = Math.Round((pureBlackResult + additionalResult + pureRedResult * seasonRatio) / player.Games, 2) * 100;
             }
             else
             {
                 player.Rating = Math.Round((pureBlackResult + additionalResult + pureRedResult) / player.Games, 2) * 100;
             }
         }
         var seriesRedSum   = context.SeriesRatingFiimDbSet.Sum(t => t.RedWin) / 7;
         var seriesBlackSum = context.SeriesRatingFiimDbSet.Sum(t => t.BlackWin) / 3;
         var seriesRatio    = CountRatio(seriesRedSum ?? 0, seriesBlackSum ?? 0);
         foreach (var player in context.SeriesRatingFiimDbSet)
         {
             var pureRedResult    = (player.RedWin ?? 0) * 2;
             var pureBlackResult  = (player.BlackWin ?? 0) * 2;
             var additionalResult = player.ScoreAdditional;
             if (seriesRedSum > seriesBlackSum)
             {
                 player.Rating = Math.Round((pureRedResult + additionalResult + pureBlackResult * seriesRatio) / player.Games, 2) * 100;
             }
             else if (seriesBlackSum > seriesRedSum)
             {
                 player.Rating = Math.Round((pureBlackResult + additionalResult + pureRedResult * seriesRatio) / player.Games, 2) * 100;
             }
             else
             {
                 player.Rating = Math.Round((pureBlackResult + additionalResult + pureRedResult) / player.Games, 2) * 100;
             }
         }
         var weekRedSum   = context.WeekRatingFiimDbSet.Sum(t => t.RedWin) / 7;
         var weekBlackSum = context.WeekRatingFiimDbSet.Sum(t => t.BlackWin) / 3;
         var weekRatio    = CountRatio(weekRedSum ?? 0, weekBlackSum ?? 0);
         foreach (var player in context.WeekRatingFiimDbSet)
         {
             var pureRedResult    = (player.RedWin ?? 0) * 2;
             var pureBlackResult  = (player.BlackWin ?? 0) * 2;
             var additionalResult = player.ScoreAdditional;
             if (weekRedSum > weekBlackSum)
             {
                 player.Rating = Math.Round((pureRedResult + additionalResult + pureBlackResult * weekRatio) / player.Games, 2) * 100;
             }
             else if (weekBlackSum > weekRedSum)
             {
                 player.Rating = Math.Round((pureBlackResult + additionalResult + pureRedResult * weekRatio) / player.Games, 2) * 100;
             }
             else
             {
                 player.Rating = Math.Round((pureBlackResult + additionalResult + pureRedResult) / player.Games, 2) * 100;
             }
         }
         var allRedSum   = context.AllTimeRatingFiimDbSet.Sum(t => t.RedWin) / 7;
         var allBlackSum = context.AllTimeRatingFiimDbSet.Sum(t => t.BlackWin) / 3;
         var allRatio    = CountRatio(allRedSum ?? 0, allBlackSum ?? 0);
         foreach (var player in context.AllTimeRatingFiimDbSet)
         {
             var pureRedResult    = (player.RedWin ?? 0) * 2;
             var pureBlackResult  = (player.BlackWin ?? 0) * 2;
             var additionalResult = player.ScoreAdditional;
             if (allRedSum > allBlackSum)
             {
                 player.Rating = Math.Round((pureRedResult + additionalResult + pureBlackResult * allRatio) / player.Games, 2) * 100;
             }
             else if (allBlackSum > allRedSum)
             {
                 player.Rating = Math.Round((pureBlackResult + additionalResult + pureRedResult * allRatio) / player.Games, 2) * 100;
             }
             else
             {
                 player.Rating = Math.Round((pureBlackResult + additionalResult + pureRedResult) / player.Games, 2) * 100;
             }
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public static void DbUpdate(ObservableCollection <PlayerEntry> players, bool isBestWay,
                                    bool redWin, bool blackWin, bool techRedWin, bool techBlackWin,
                                    ObservableCollection <int?> ugadaykaContainer, bool ugadaykaOn, bool threeZv, int prohBal, int?falseCom)
        {
            var gap = GetGap();

            using (var context = new SaluteDbContext())
            {
                foreach (var player in players)
                {
                    var     fc          = falseCom != null && falseCom == players.IndexOf(player) + 1;
                    var     currentNick = player.Nick;
                    IRating inSeason    = context.SeasonRatingDbSet.FirstOrDefault(t => t.Nick == currentNick);
                    IRating inSeries    = context.SeriesRatingDbSet.FirstOrDefault(t => t.Nick == currentNick);
                    IRating inWeek      = context.WeekRatingDbSet.FirstOrDefault(t => t.Nick == currentNick);
                    IRating inAll       = context.AllTimeRatingDbSet.FirstOrDefault(t => t.Nick == currentNick);
                    if (inSeason != null)
                    {
                        GeneralDbUpdate(player, inSeason, players, isBestWay,
                                        redWin, blackWin, techRedWin, techBlackWin, ugadaykaContainer, ugadaykaOn, threeZv, gap.SeasonMinGames,
                                        true, fc);
                    }
                    else
                    {
                        var newPlayer = new SeasonRating(player, players, isBestWay,
                                                         redWin, blackWin, techRedWin, techBlackWin, ugadaykaContainer, ugadaykaOn, threeZv, fc);
                        context.SeasonRatingDbSet.Add(newPlayer);
                    }
                    if (inSeries != null)
                    {
                        GeneralDbUpdate(player, inSeries, players, isBestWay,
                                        redWin, blackWin, techRedWin, techBlackWin, ugadaykaContainer, ugadaykaOn, threeZv, gap.SeriesMinGames,
                                        false, fc);
                    }
                    else
                    {
                        var newPlayer = new SeriesRating(player, players, isBestWay,
                                                         redWin, blackWin, techRedWin, techBlackWin, ugadaykaContainer, ugadaykaOn, threeZv, fc);
                        context.SeriesRatingDbSet.Add(newPlayer);
                    }
                    if (inWeek != null)
                    {
                        GeneralDbUpdate(player, inWeek, players, isBestWay,
                                        redWin, blackWin, techRedWin, techBlackWin, ugadaykaContainer, ugadaykaOn, threeZv, 1,
                                        false, fc);
                    }
                    else
                    {
                        var newPlayer = new WeekRating(player, players, isBestWay,
                                                       redWin, blackWin, techRedWin, techBlackWin, ugadaykaContainer, ugadaykaOn, threeZv, fc);
                        context.WeekRatingDbSet.Add(newPlayer);
                    }
                    if (inAll != null)
                    {
                        GeneralDbUpdate(player, inAll, players, isBestWay,
                                        redWin, blackWin, techRedWin, techBlackWin, ugadaykaContainer, ugadaykaOn, threeZv, gap.AllTimeMinGames,
                                        false, fc);
                    }
                    else
                    {
                        var newPlayer = new AllTimeRating(player, players, isBestWay,
                                                          redWin, blackWin, techRedWin, techBlackWin, ugadaykaContainer, ugadaykaOn, threeZv, fc);
                        context.AllTimeRatingDbSet.Add(newPlayer);
                    }
                }
                context.SaveChanges();
            }
        }