private void FinalizeList <T>(ListHeaderModel model, IEnumerable <T> results, Func <T, bool> selectorWithResult, Comparison <T> sortingComparison, Func <T, long> resultSelector, Func <T, bool> isDSQ, Func <T, bool> isDNS, bool isLeadQualy, bool forceQf, Func <T, int> leadTimeSelector ) where T : ListLineModel { var dt = SortingClass.CreateStructure(); var posCol = dt.Columns.Add("pos0", typeof(int)); DataColumn rNumCol; long curRes = -1; int curPos = 1; int i = 0; HashSet <long> climbersWithResult = new HashSet <long>(); var resultList = results.Where(r => selectorWithResult(r)).ToList(); resultList.Sort(sortingComparison); foreach (var res in resultList) { i++; long rowRes = resultSelector(res); if (curRes < 0 || rowRes != curRes) { curRes = rowRes; curPos = i; } int sp; if (isDSQ(res)) { sp = 1; } else if (isDNS(res)) { sp = 2; } else { sp = 0; } dt.Rows.Add(res.Climber.Vk, 0, String.Empty, res.Climber.SecretaryId.Value, String.Empty, 0.0, String.Empty, sp, curPos); climbersWithResult.Add(res.Climber.SecretaryId.Value); } if (dt.Rows.Count > 0) { var currentList = model; i = 0; while (currentList.PreviousRoundId != null) { currentList = currentList.PreviousRound; rNumCol = dt.Columns.Add(String.Format("rNum{0}", ++i), typeof(int)); posCol = dt.Columns.Add(String.Format("pos{0}", i), typeof(int)); var roundRes = GetResultsByRound(currentList); foreach (DataRow row in dt.Rows) { int iid = (int)row["iid"]; if (roundRes == null || !roundRes.ContainsKey(iid)) { row[rNumCol] = 0; row[posCol] = 1; } else { var r = roundRes[iid]; row[rNumCol] = r.RouteNum; row[posCol] = r.Pos; } } } SortingClass.SortResults(dt, model.Quota, i == 0, isLeadQualy, model.CompetitionRules, forceQf); if (leadTimeSelector != null) { var dtWithTime = SortingClass.CreateStructure(); posCol = dtWithTime.Columns.Add("pos0"); rNumCol = dtWithTime.Columns.Add("rNum1"); var timeCol = dtWithTime.Columns.Add("pos1"); foreach (DataRow dr in dt.Rows) { var clmResult = resultList.FirstOrDefault(r => r.Climber.SecretaryId == (int)dr[3]); int time = clmResult == null ? -1 : leadTimeSelector(clmResult); dtWithTime.Rows.Add(dr[0], 0, String.Empty, dr[3], String.Empty, 0.0, String.Empty, dr[7], dr[1], time < 0 ? 0 : 1, time < 0 ? 1 : time); } SortingClass.SortResults(dtWithTime, model.Quota, i == 0, isLeadQualy, model.CompetitionRules, forceQf); dt = dtWithTime; } foreach (DataRow row in dt.Rows) { var climberRes = model.Results.First(r => r.Climber.SecretaryId == (int)row["iid"]); climberRes.Position = (int)row["pos"]; climberRes.PosText = (string)row["posText"]; climberRes.Qf = (string)row["qf"]; climberRes.Points = (double)row["pts"]; climberRes.PointsText = (string)row["ptsText"]; } } foreach (var clmRes in model.Results.ToArray().Where(r => !climbersWithResult.Contains(r.Climber.SecretaryId.Value))) { clmRes.Position = null; clmRes.PosText = String.Empty; clmRes.Qf = String.Empty; clmRes.Points = null; clmRes.PointsText = String.Empty; } }
private ActionResult RenderResultListFlash(ListHeaderModel header) { var results = ResultsController.GetFlashResult(header); var dataTable = SortingClass.CreateStructure(); dataTable.Columns.Add("pos0", typeof(int)); //dt.Rows.Add(res.Climber.Vk, 0, String.Empty, res.Climber.SecretaryId.Value, String.Empty, // 0.0, String.Empty, sp, curPos); //climbersWithResult.Add(res.Climber.SecretaryId.Value); foreach (var r in results.Values.OfType <ResultsController.FlashRoundResult>().Where(r => r.RouteNum == 1)) { var climber = header.Competition.Climbers.FirstOrDefault(c => c.SecretaryId == r.ClimberId); if (climber == null) { continue; } int sp; bool allDSQ = true, allDNS = true; foreach (var route in r.Routes) { if (allDNS && !route.ResText.ToLowerInvariant().Contains("н/я")) { allDNS = false; } if (allDSQ && !route.ResText.ToLowerInvariant().Contains("дискв")) { allDSQ = false; } if (!allDNS || allDSQ) { break; } } if (allDNS && allDSQ) { continue; } if (allDNS) { sp = 2; } else if (allDSQ) { sp = 1; } else { sp = 0; } dataTable.Rows.Add(climber.Vk, 0, String.Empty, r.ClimberId, String.Empty, 0.0, String.Empty, sp, r.Pos); } if (dataTable.Rows.Count > 0) { SortingClass.SortResults(dataTable, header.Quota, true, false, header.CompetitionRules, false); } List <FlashResult> model = new List <FlashResult>(); foreach (DataRow row in dataTable.Rows) { FlashResult flshRes = new FlashResult(); flshRes.Climber = header.Competition.Climbers.First(r => r.SecretaryId == (int)row[3]); flshRes.PointsText = (string)row["ptsText"]; flshRes.PosText = (string)row["posText"]; flshRes.PreQf = false; flshRes.Qf = (string)row["qf"]; flshRes.ResText = results[flshRes.Climber.SecretaryId.Value].Pts.ToString("0.00"); foreach (var list in header.Children.OrderBy(r => r.LocalIid)) { var listRes = list.ResultsLead.FirstOrDefault(r => r.ClimberId == flshRes.Climber.Iid); if (listRes == null) { flshRes.Routes.Add(new LeadResultLine { ResText = String.Empty, PointsText = String.Empty, PosText = String.Empty }); } else { flshRes.Routes.Add(listRes); } } model.Add(flshRes); } return(PartialView("RenderResultListFlash", model)); }