Пример #1
0
        /// <summary>
        /// Gets the stats for specific range.
        /// </summary>
        /// <param name="min">The minimum.</param>
        /// <param name="max">The maximum.</param>
        /// <returns>StatResponse</returns>
        private StatResponse GetStatsForSpecificRange(float min, float max)
        {
            StatResponse response = new StatResponse();

            response.Max = float.MinValue;
            response.Min = float.MaxValue;

            if (this.nodeData == null)
            {
                response.Min = 0;
                response.Max = 0;
                return(response);
            }

            for (int i = 0; i < this.nodeData.Count && this.nodeData[i] <= max; i++)
            {
                if (this.nodeData[i] >= min)
                {
                    response.Size++;
                }

                if (response.Max <= this.nodeData[i])
                {
                    response.Max = this.nodeData[i];
                }

                if (response.Min > this.nodeData[i])
                {
                    response.Min = this.nodeData[i];
                }
            }

            return(response);
        }
Пример #2
0
        public TeamDetail GetTeamDetailByTeamResponse(IStat stat, TeamResponse team, IList <StatResponse> matchStats)
        {
            var teamDetail = new TeamDetail {
                TeamInfo = team
            };
            var teamTotalAge = 0;
            var teamStats    = new StatResponse();

            var players = matchStats.Where(p => p.TeamId == team.Id).Select(p => p.Player).ToList();

            foreach (var player in players)
            {
                var playerStat = stat.GetPlayerStatByMatchIdAndTeamId(player.Id, team.Id, matchStats);
                if (playerStat == null)
                {
                    continue;
                }

                teamStats = stat.AddPlayerStatToTeamStats(teamStats, playerStat);

                teamDetail.PlayerStats.Add(new PlayerMatchStat {
                    Player = player, Stat = playerStat
                });
                teamTotalAge = teamTotalAge + player.BirthDate.GetAge();
            }

            teamDetail.AgeRatio = ConvertFunctions.GetTeamAgeRatio(players.Count, teamTotalAge);

            teamDetail.TeamStats = teamStats;
            return(teamDetail);
        }
Пример #3
0
        public HttpResponseMessage Stat(int days)
        {
            if (!CookFormManager.Instance.IsAuthorized)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Use Index page for authorization ;)"));
            }

            StatResponse response = new StatResponse();

            var dishItems = _dbService.GetDishes();
            Dictionary <int, int> counts = new Dictionary <int, int>();

            foreach (var dish in dishItems)
            {
                counts.Add(int.Parse(dish.Id), 0);
            }

            response.Stat = new List <DishItemStat>();

            for (int i = days; i > 0; i--)
            {
                foreach (var menu in _dbService.GetMenus(DefaultCookerId, DateTime.Now.Date.AddDays(2 - i)))
                {
                    var formAnswers           = CookFormManager.Instance.GetFormResult(menu.FormId);
                    var dishesRelationsByMenu = _dbService.GetDishesRelationsByMenu(menu.Id);
                    foreach (var formAnswer in formAnswers)
                    {
                        foreach (var value in formAnswer.FormValues)
                        {
                            if (dishesRelationsByMenu.ContainsKey(value.FormId))
                            {
                                counts[dishesRelationsByMenu[value.FormId]]++;
                            }
                        }
                    }
                }

                foreach (var dishCount in counts)
                {
                    if (dishCount.Value > 0)
                    {
                        response.Stat.Add(new DishItemStat
                        {
                            Date  = DateTime.Now.Date.AddDays(2 - i),
                            Count = dishCount.Value,
                            Item  = dishItems.Single(d => d.Id == dishCount.Key.ToString())
                        });
                    }
                }

                counts = new Dictionary <int, int>();
                foreach (var dish in dishItems)
                {
                    counts.Add(int.Parse(dish.Id), 0);
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Пример #4
0
        public StatResponse AddPlayerStatToTeamStats(StatResponse teamStats, StatResponse playerStat)
        {
            teamStats.Assist        += playerStat.Assist;
            teamStats.Goal          += playerStat.Goal;
            teamStats.MissedPenalty += playerStat.MissedPenalty;
            teamStats.OwnGoal       += playerStat.OwnGoal;
            teamStats.PenaltyScore  += playerStat.PenaltyScore;

            return(teamStats);
        }
Пример #5
0
        public StatResponse GetPerMatchStats(StatResponse totalStats, List <StatResponse> playerStats)
        {
            var matchCount = GetMatchCount(playerStats);

            return(new StatResponse
            {
                Goal = (totalStats.Goal / matchCount).RoundValue(),
                OwnGoal = (totalStats.OwnGoal / matchCount).RoundValue(),
                Assist = (totalStats.Assist / matchCount).RoundValue(),
                MissedPenalty = (totalStats.MissedPenalty / matchCount).RoundValue(),
                PenaltyScore = (totalStats.PenaltyScore / matchCount).RoundValue(),
            });
        }
Пример #6
0
        private int CalculateTotalDeaths(StatResponse characterStats)
        {
            var deathSum = 0.0;

            if (characterStats.Response.allPvP.allTime != null)
            {
                deathSum = deathSum + characterStats.Response.allPvP.allTime.deaths.basic.value;
            }

            if (characterStats.Response.allArena.allTime != null)
            {
                deathSum = deathSum + characterStats.Response.allArena.allTime.deaths.basic.value;
            }

            if (characterStats.Response.allStrikes.allTime != null)
            {
                deathSum = deathSum + characterStats.Response.allStrikes.allTime.deaths.basic.value;
            }

            if (characterStats.Response.patrol.allTime != null)
            {
                deathSum = deathSum + characterStats.Response.patrol.allTime.deaths.basic.value;
            }

            if (characterStats.Response.raid.allTime != null)
            {
                deathSum = deathSum + characterStats.Response.raid.allTime.deaths.basic.value;
            }

            if (characterStats.Response.story.allTime != null)
            {
                deathSum = deathSum + characterStats.Response.story.allTime.deaths.basic.value;
            }

            return(Convert.ToInt32(deathSum));
        }
Пример #7
0
        /// <summary>
        /// Starts the thread.
        /// </summary>
        private void StartThread()
        {
            this.logger.Info($"Node_{this.id} Starting");

            if (!this.LoadNodeData())
            {
                this.Dispose();
            }

            while (!this.token.IsCancellationRequested)
            {
                try
                {
                    ICommand command = null;
                    if (this.commandQueue.TryDequeue(out command))
                    {
                        switch (command.CommandType)
                        {
                        case Enums.CommandType.Sort_Elements:
                            this.logger.Debug("Sort Elements Request");
                            this.nodeData?.Sort();     // TODO space complexity
                            break;

                        case Enums.CommandType.Display_Elements:
                            this.logger.Debug("Sort Elements Request");
                            this.logger.Debug(this.nodeData);
                            break;

                        case Enums.CommandType.Initial_Stat_Req:
                            this.logger.Debug("Publish Initial Stats Request");
                            command.Sender.QueueCommand(new StatResponse()
                            {
                                Sender      = this,
                                CommandType = Enums.CommandType.Initial_Stat_Response,
                                Size        = this.nodeData?.Count ?? 0,
                                Min         = this.nodeData?[0] ?? 0,
                                Max         = this.nodeData?[this.nodeData.Count - 1] ?? 0,
                            });
                            break;

                        case Enums.CommandType.Publish_Stats:
                            StatRequest  sr    = (StatRequest)command;
                            StatResponse sresp = this.GetStatsForSpecificRange(sr.Min, sr.Max);
                            command.Sender.QueueCommand(sresp);
                            break;

                        case Enums.CommandType.Publish_NextValue:
                            NextValueRequest  nvr        = (NextValueRequest)command;
                            NextValueResponse nxtValResp = this.GetNextValueInQueue(nvr.CurrentValue);
                            command.Sender.QueueCommand(nxtValResp);
                            break;

                        default:
                            this.logger.Debug("Unhandled Command. Ignoring");
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.logger.Fatal("Exception Occured");
                    this.logger.Fatal($"Exception Data - {ex.Message}");
                    this.logger.Fatal($"Inner Exception Data - {ex.InnerException?.Message}");
                    this.logger.Fatal($"Stack Trace - {ex.StackTrace}");
                }
            }
        }