public IEnumerable <GoalInfo> Get(int rangeID, int numItems, bool isIncludeBetweenLimitGoals) { DTC.RangeEnum range = (DTC.RangeEnum)rangeID; OwnerInfo owner = DB.Owner.GetOwner(range, DateTime.Today); List <GoalInfo> goalsAll = DB.Goals.GetGoals(owner, true); List <GoalGroupInfo> goalGroups = DB.Goals.GetGoalGroups(); List <GoalInfo> goalsPicked = new List <GoalInfo>(); DayInfo today = DB.Days.GetDay(DateTime.Today, true); GoalsEngine goalEngine = new GoalsEngine(goalsAll, goalGroups, today); if (!isIncludeBetweenLimitGoals) { goalsAll = goalsAll.FindAll(i => i.Nature == GoalInfo.NatureEnum.Standart); } foreach (GoalInfo goal in goalsAll) { goal.Contribution = goalEngine.GetGoalContributionWeighted(goal, false, GoalsEngine.PerformanceNatureEnum.Worst); goal.ContributionMax = goalEngine.GetGoalContributionWeighted(goal, true, GoalsEngine.PerformanceNatureEnum.Worst); } int nCount = 0; foreach (GoalInfo gOut in goalsAll) { float maxValue = 0; long maxID = 0; foreach (GoalInfo gIn in goalsAll) { float contrDifference = gIn.ContributionMax - gIn.Contribution; if (contrDifference > maxValue && !goalsPicked.Exists(i => i.ID == gIn.ID) && gIn.Status == DTC.StatusEnum.Running) { maxValue = contrDifference; maxID = gIn.ID; } } if (maxID > 0 && !goalsPicked.Exists(i => i.ID == maxID)) { goalsPicked.Add(goalsAll.Find(i => i.ID == maxID)); } nCount++; if (nCount >= numItems) { break; } } return(goalsPicked); }
public IEnumerable <GoalInfo> Get(int rangeID, bool getPresentValues, int standartOrProjected) { List <GoalInfo> goals = new List <GoalInfo>(); DTC.RangeEnum range = (DTC.RangeEnum)rangeID; OwnerInfo owner = DB.Owner.GetOwner(range, DateTime.Today); goals = DB.Goals.GetGoals(owner, true); DayInfo today = DB.Days.GetDay(DateTime.Today, true); foreach (GoalInfo goal in goals) { if (standartOrProjected == 1) { goal.PresentPercentage = goal.GetPresentPercentage(); goal.DesiredValue = goal.GoalValue; } if (standartOrProjected == 2) { goal.PresentPercentage = goal.GetPerformance(false, today); // What does it mean? isFull goal.DesiredValue = goal.GetDesiredValue(today); } } goals = goals.OrderByDescending(i => i.Status).OrderByDescending(i => i.PresentPercentage).ToList(); if (getPresentValues) { List <GoalGroupInfo> goalGroups = DB.Goals.GetGoalGroups(); GoalsEngine goalEngine = new GoalsEngine(goals, goalGroups, today); GoalsEngine.PerformanceNatureEnum nature = GoalsEngine.PerformanceNatureEnum.Normal; if (standartOrProjected == 1) { nature = GoalsEngine.PerformanceNatureEnum.Worst; } else if (standartOrProjected == 1) { nature = GoalsEngine.PerformanceNatureEnum.Normal; } foreach (GoalInfo goal in goals) { goal.Contribution = goalEngine.GetGoalContributionWeighted(goal, false, nature); goal.ContributionMax = goalEngine.GetGoalContributionWeighted(goal, true, nature); } } return(goals); }