Example #1
0
        public void pointCalculation()
        {
            //Arange
            MatchRepository matchRepository = new MatchRepository(null);

            List <Forecast> forecast1 = DataStorage.forecasts1;
            PointsAnalysis  rules1    = new PointsAnalysis()
            {
                Full = 60, GoalDif = 30, JustWinner = 20
            };
            double expSum1 = 24;

            List <Forecast> forecast2 = DataStorage.forecasts2;
            PointsAnalysis  rules2    = new PointsAnalysis()
            {
                Full = 80, GoalDif = 20, JustWinner = 10
            };
            double expSum2 = 20;

            //Act
            double sum1 = matchRepository.calculateUserPoints(forecast1, DataStorage.fixtures, rules1);
            double sum2 = matchRepository.calculateUserPoints(forecast2, DataStorage.fixtures, rules2);

            //Assert
            Assert.AreEqual(expSum1, sum1);
            Assert.AreEqual(expSum2, sum2);
        }
Example #2
0
        public int AddTotalizator(int organaizerId, int stage, string tTitle, PointsAnalysisView tPoints, string tAccess)
        {
            bool     isPublic  = true;
            DateTime ValidDate = DateService.getValidDate(stage, context);

            if (tAccess == "Private")
            {
                isPublic = false;
            }
            int totalizatorId = GetNextIndex();
            var pA            = new PointsAnalysis()
            {
                Full          = tPoints.Full,
                GoalDif       = tPoints.GoalDif,
                JustWinner    = tPoints.JustWinner,
                TotalizatorId = totalizatorId
            };

            context.PointsAnalysis.Add(pA);
            var totalizator = new Totalizator()
            {
                Name          = tTitle,
                TotalizatorId = totalizatorId,
                OrganaizerId  = organaizerId,
                StageId       = stage,
                Validity      = ValidDate,
                isPublic      = isPublic
            };

            context.Totalizators.Add(totalizator);
            context.SaveChanges();
            return(totalizatorId);
        }
Example #3
0
        public void testException()
        {
            MatchRepository matchRepository = new MatchRepository(null);

            List <Forecast> forecast1 = DataStorage.forecasts1;
            PointsAnalysis  rules1    = new PointsAnalysis()
            {
                Full = -60, GoalDif = 30, JustWinner = 20
            };
            double expSum1 = 0;

            //Act
            double sum1 = matchRepository.calculateUserPoints(forecast1, DataStorage.fixtures, rules1);

            //Assert
            Assert.AreEqual(expSum1, sum1);
        }
        public double  calculateUserPoints(List <Forecast> forecasts, List <FixtureView> matchRes, PointsAnalysis pointsRules)
        {
            if (!EntityHelper.isValidRules(pointsRules))
            {
                throw new ArgumentException("Incorrect values. Please, enter some positive numbers");
            }
            double sum = 0;

            foreach (var forecast in forecasts)
            {
                var currRes = matchRes.Single(m => m.awayTeamName == forecast.Match.GuestTeam.Name && m.homeTeamName == forecast.Match.HomeTeam.Name);
                if (forecast.GuestTeamGoals == currRes.result.goalsAwayTeam && forecast.HomeTeamGoals == currRes.result.goalsHomeTeam)
                {
                    sum += pointsRules.Full;
                }
                else
                {
                    string winnerResName = getWinnerName(currRes.homeTeamName, currRes.result.goalsHomeTeam,
                                                         currRes.awayTeamName, currRes.result.goalsAwayTeam);

                    string winnerUserName = getWinnerName(forecast.Match.HomeTeam.Name, forecast.HomeTeamGoals,
                                                          forecast.Match.GuestTeam.Name, forecast.GuestTeamGoals);

                    if (winnerResName == winnerUserName)
                    {
                        if (forecast.GuestTeamGoals - forecast.HomeTeamGoals == currRes.result.goalsAwayTeam - currRes.result.goalsHomeTeam)
                        {
                            sum += pointsRules.GoalDif;
                        }
                        else
                        {
                            sum += pointsRules.JustWinner;
                        }
                    }
                }
            }
            return(sum / (double)matchRes.Count);
        }
Example #5
0
 public static bool isValidRules(PointsAnalysis rules)
 {
     return(rules.Full >= 0 && rules.GoalDif >= 0 && rules.JustWinner >= 0);
 }