예제 #1
0
        /// <summary>
        /// <para>Gets the gt sport statistics.</para>
        /// <para>
        /// The total line is only the total cars in game, total cars owned, and the unique total
        /// cars owned.
        /// </para>
        /// </summary>
        /// <param name="ownerKey">The owner key.</param>
        /// <returns>A list of gt sport statistics for each category and the total line.</returns>
        public List <GTSportStatistic> GetGTSportStatistics(string ownerKey)
        {
            List <GTSportStatistic> statistics = new List <GTSportStatistic>();

            foreach (CarCategory.Category category in CarCategory.categories)
            {
                if (category != CarCategory.Empty)
                {
                    GTSportStatistic statistic = new GTSportStatistic();
                    statistic.Category = category;

                    statistics.Add(statistic);
                }
            }

            AddCarStatistics(ref statistics);
            AddOwnedStatistics(ref statistics, ownerKey);
            AddUniqueOwnedStatistics(ref statistics, ownerKey);
            AddTotalLine(ref statistics);

            return(statistics);
        }
예제 #2
0
        private void AddTotalLine(ref List <GTSportStatistic> statistics)
        {
            GTSportStatistic statistic = new GTSportStatistic();

            statistic.Category = CarCategory.Total;

            foreach (GTSportStatistic sportStatistic in statistics)
            {
                statistic.NumberOfCars    = statistic.NumberOfCars + sportStatistic.NumberOfCars;
                statistic.CarsOwned       = statistic.CarsOwned + sportStatistic.CarsOwned;
                statistic.UniqueCarsOwned = statistic.UniqueCarsOwned + sportStatistic.UniqueCarsOwned;

                if (sportStatistic.NumberOfCars > 0)
                {
                    sportStatistic.PercentOwned = (double)sportStatistic.UniqueCarsOwned / sportStatistic.NumberOfCars;
                }
            }

            if (statistic.NumberOfCars > 0)
            {
                statistic.PercentOwned = (double)statistic.UniqueCarsOwned / statistic.NumberOfCars;
            }
            statistics.Insert(0, statistic);
        }