Esempio n. 1
0
        public override void CalculateRanking()
        {
            List <Ranking> ranking           = new List <Ranking>();
            var            PlantDetails      = _misc.CalculateRanking(PlantIds, "SunGrow");
            var            PlantCapacity     = _misc.GetPlantsCapacity("SunGrowPlantInformation", "DesignCapacity", "PowerStationId", PlantIds);
            var            RankingDetailView = from pd in PlantDetails
                                               join pc in PlantCapacity
                                               on pd.PlantId equals pc.PlantId
                                               select new RankingCalculationViewDTO
            {
                PlantId           = pd.PlantId,
                Energy            = pd.Energy,
                GridStationRate   = pd.GridStationRate,
                GroupId           = pd.GroupId,
                RateMonthDateTime = pd.RateMonthDateTime,
                SunHours          = pd.SunHours,
                UserId            = pd.UserId,
                VendorType        = pd.VendorType,
                PlantCapacity     = pc.PlantCapacity
            };

            if (RankingDetailView.Count() > 0)
            {
                foreach (var item in RankingDetailView)
                {
                    decimal TargetEnergy = item.SunHours * item.PlantCapacity;
                    decimal TargetAchieved;
                    if (TargetEnergy > 0)
                    {
                        TargetAchieved = item.Energy / TargetEnergy;
                    }
                    else
                    {
                        TargetAchieved = 0;
                    }
                    ranking.Add(new Ranking {
                        PlantId = item.PlantId, RankingPercentage = TargetAchieved
                    });
                }

                var finallist = ranking.OrderByDescending(x => x.RankingPercentage).ToList();
                int position  = 1;
                var date      = DateTime.Now;

                foreach (var item in finallist)
                {
                    item.Rank = position;
                    item.RankingPercentage = Convert.ToDecimal((1 - position / Convert.ToDouble(ranking.Count)) * 100);
                    item.CreatedOn         = date;
                    item.UpdatedOn         = date;
                    position++;
                }
                _misc.FinalRanking(finallist);
            }
        }