private TimeStampList leaders; // Список времён лидеров // на каждой отсечке /// <summary> /// Инициализирует новый экземпляр класса Race с заданными параметрами трассы, /// вида и даты, а также генерирует вектор силы ветра /// </summary> /// <param name="_course">Трасса</param> /// <param name="_type">Тип</param> /// <param name="_date">Дата</param> public Race(Course _course, RaceType _type, DateTime _date) { course = _course; type = _type; date = _date; weather = new Weather(); athletes = new List <Athlete>(); isCompleted = false; }
//private void prepare_Click(object sender, RoutedEventArgs e) private void Start() { Dictionary <int, Athlete> athletes = new Dictionary <int, Athlete>(); using (StreamReader sr = new StreamReader(@"athletes.txt")) { string line; line = sr.ReadLine(); int id = 0; while (!sr.EndOfStream) { line = sr.ReadLine(); if (line != "") { string[] attr = line.Split('|'); Athlete newAt = new Athlete(id, attr[0].Trim(), attr[1].Trim(), attr[2], new Attributes(double.Parse(attr[3], CultureInfo.InvariantCulture), double.Parse(attr[4], CultureInfo.InvariantCulture), double.Parse(attr[5], CultureInfo.InvariantCulture), double.Parse(attr[6], CultureInfo.InvariantCulture), double.Parse(attr[7], CultureInfo.InvariantCulture), int.Parse(attr[8], CultureInfo.InvariantCulture), double.Parse(attr[9], CultureInfo.InvariantCulture), double.Parse(attr[10], CultureInfo.InvariantCulture), double.Parse(attr[11], CultureInfo.InvariantCulture), double.Parse(attr[12], CultureInfo.InvariantCulture), double.Parse(attr[13], CultureInfo.InvariantCulture)), attr[14]); if (!athletes.ContainsValue(newAt)) { athletes.Add(id, newAt); id++; } } } } Dictionary <string, Course[]> map = ReadMaps(); List <Race> race = new List <Race>(); RaceType type = new RaceType(RaceTypes.Individual); DateTime t = new DateTime(2017, 10, 1); double[,] range = new double[athletes.Count, 4]; double[] behind = new double[athletes.Count]; int[] points = { 40, 35, 32, 30, 28, 26, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; Dictionary <int, int[]> season = new Dictionary <int, int[]>(); for (int i = 0; i < athletes.Count; i++) { season.Add(athletes.Keys.ElementAt(i), new int[map.Count * 4]); } using (StreamWriter sw = File.CreateText(@"test.csv")) { for (int k = 0; k < map.Count * 4; k++) { if (k % 4 == 0) { type = new RaceType(RaceTypes.Sprint); t += new TimeSpan(14, 0, 0, 0); } else if (k % 4 == 1) { type = new RaceType(RaceTypes.Pursuit); t += new TimeSpan(1, 0, 0, 0); } else if (k % 4 == 2) { type = new RaceType(RaceTypes.Individual); t += new TimeSpan(3, 0, 0, 0); } else { type = new RaceType(RaceTypes.Mass_Start); t += new TimeSpan(2, 0, 0, 0); } race.Add(new Race(map.ElementAt(k / 4).Value[k % 4 % 3], type, t)); sw.WriteLine(RaceInfo(race[k])); if (race[k].Type == RaceTypes.Pursuit) { race[k].Draw(race[k - 1].Athletes, race[k - 1].Results); } else if (race[k].Type == RaceTypes.Mass_Start) { List <int> idlist = new List <int>(); List <Athlete> masslist = new List <Athlete>(); var currentTable = season.OrderByDescending(x => x.Value.Sum()).ToList(); for (int i = 0; i < 20; i++) { idlist.Add(currentTable[i].Key); } var topFiveThisEvent = season.OrderByDescending(x => x.Value.Skip(k - 3).Sum()).ToList(); for (int i = 0; i < 5; i++) { idlist.Add(topFiveThisEvent.First(x => !idlist.Contains(x.Key)).Key); } foreach (var id in idlist) { masslist.Add(athletes[id]); } race[k].Draw(masslist); } else { race[k].Draw(athletes.Values.ToList()); } race[k].Start(); var h = race[k].Results.OrderBy(x => x.Finish, new TimeSpanCompare()).ToList(); List <double> CourseTime = h.Select(x => x.CourseTime.Value.TotalSeconds).ToList(); for (int curA = 0; curA < h.Count; curA++) { for (int lap = 0; lap < race[k].Laps - 1; lap++) { if (race[k].RangeDistr[lap] == 's') { range[race[k].Athletes[h[curA].Bib].ID, 3] += 5; } else { range[race[k].Athletes[h[curA].Bib].ID, 1] += 5; } foreach (var l in h[curA].Range[lap]) { if (l) { if (race[k].RangeDistr[lap] == 's') { range[race[k].Athletes[h[curA].Bib].ID, 2]++; } else { range[race[k].Athletes[h[curA].Bib].ID, 0]++; } } } } if (k % 4 == 0) { behind[race[k].Athletes[h[curA].Bib].ID] += (CourseTime[curA] / CourseTime.OrderBy(x => x).Take(5).Average() - 1) * 100; } TimeSpan?m = TimeSpan.FromSeconds(CourseTime[curA]) - TimeSpan.FromSeconds(CourseTime.Min()); if (CourseTime[curA] == CourseTime.Min()) { m = TimeSpan.FromSeconds(CourseTime.Min()); } //TimeSpan? m = h[j].Finish - h[j].Start; //for (int i = 1; i < race[k].Type.Laps; i++) //{ // m += h[j].TimeStamps[i - 1].Last() - h[j].TimeStamps[i].First(); //} sw.WriteLine(AthleteRaceResults(race[k], h[curA], m, curA)); } for (int i = 0; i < Math.Min(points.Length, h.Count); i++) { season[race[k].Athletes[h[i].Bib].ID][k] = points[i]; } Extensions.updateStamina(ref athletes, race[k].Athletes); foreach (var id in athletes.Keys) { if (race[k].Type == RaceTypes.Sprint) { athletes[id].Attributes.RestoreStamina(1); } else { athletes[id].Attributes.RestoreStamina(4); } } sw.WriteLine("\r\n"); } sw.WriteLine(); var cup = season.OrderByDescending(x => x.Value.Sum() - x.Value.Min()) .CreateOrderedEnumerable(x => x.Value.Max(), Comparer <int> .Default, true) .CreateOrderedEnumerable(x => x.Value.Count(val => val == x.Value.Max()), Comparer <int> .Default, true) .CreateOrderedEnumerable(x => x.Value.Where(val => val < Math.Max(x.Value.Max(), 1)).Max(), Comparer <int> .Default, true) .CreateOrderedEnumerable(x => x.Value.Count(val => val < x.Value.Max() && val == x.Value.Where(inval => inval < Math.Max(x.Value.Max(), 1)).Max()), Comparer <int> .Default, true) .ToList(); sw.WriteLine(";№;Name;Points;;Total;Prone;Standing;% Behind"); for (int i = 0; i < athletes.Count; i++) { sw.WriteLine(";{0};{1}. {2};{3};;{4:f2}%;{5:f2}%;{6:f2}%;{7:f2}%", i + 1, athletes[cup[i].Key].Name.First(), athletes[cup[i].Key].Surname, cup[i].Value.Sum() - cup[i].Value.Min(), (range[cup[i].Key, 0] + range[cup[i].Key, 2]) / (range[cup[i].Key, 1] + range[cup[i].Key, 3]) * 100, range[cup[i].Key, 0] / range[cup[i].Key, 1] * 100, range[cup[i].Key, 2] / range[cup[i].Key, 3] * 100, behind[cup[i].Key] / (map.Count)); } using (StreamWriter sw2 = File.CreateText(@"test2.csv")) { sw2.WriteLine(); for (int i = 0; i < athletes.Count; i++) { sw2.Write("{0};{1};", i + 1, athletes[cup[i].Key].FullName); for (int j = 0; j < map.Count * 4; j++) { sw2.Write("{0};", cup[i].Value[j]); } sw2.Write(cup[i].Value.Sum() - cup[i].Value.Min()); sw2.Write("\r\n"); } for (int k = 0; k < 2; k++) { if (k == 0) { sw2.Write("\r\n\r\n;Sprint Cup;;;;;;;;;;;;;;;;Individual Cup;\r\n"); } else { sw2.Write("\r\n\r\n;Pursuit Cup;;;;;;;;;;;;;;;;Mass Start Cup;\r\n"); } Dictionary <int, int[]> season1 = new Dictionary <int, int[]>(); Dictionary <int, int[]> season2 = new Dictionary <int, int[]>(); foreach (int id in season.Keys) { season1.Add(id, season[id].GetNth(k, 4).ToArray()); } var cup1 = season1.OrderByDescending(x => x.Value.Sum()) .ThenByDescending(x => x.Value.Max()) .ThenByDescending(x => x.Value.Count(val => val == x.Value.Max())) .ThenByDescending(x => x.Value.Where(val => val < Math.Max(x.Value.Max(), 1)).Max()) .ThenByDescending(x => x.Value.Count(val => val < x.Value.Max() && val == x.Value.Where(inval => inval < Math.Max(x.Value.Max(), 1)).Max())) .ToList(); foreach (int id in season.Keys) { season2.Add(id, season[id].GetNth(k + 2, 4).ToArray()); } var cup2 = season2.OrderByDescending(x => x.Value.Sum()) .ThenByDescending(x => x.Value.Max()) .ThenByDescending(x => x.Value.Count(val => val == x.Value.Max())) .ThenByDescending(x => x.Value.Where(val => val < Math.Max(x.Value.Max(), 1)).Max()) .ThenByDescending(x => x.Value.Count(val => val < x.Value.Max() && val == x.Value.Where(inval => inval < Math.Max(x.Value.Max(), 1)).Max())) .ToList(); for (int i = 0; i < athletes.Count; i++) { sw2.Write("{0};{1};", i + 1, athletes[cup1[i].Key].FullName); for (int j = 0; j < map.Count; j++) { sw2.Write("{0};", cup1[i].Value[j]); } sw2.Write("{0};;;;;;;{1};{2}. {3};;;;;;", cup1[i].Value.Sum(), i + 1, athletes[cup2[i].Key].Name.First(), athletes[cup2[i].Key].Surname); for (int j = 0; j < map.Count; j++) { sw2.Write("{0};", cup2[i].Value[j]); } sw2.Write(cup2[i].Value.Sum()); sw2.Write("\r\n"); } } /*sw.WriteLine(); * for (int i = 0; i < 11; i++) * sw.Write(i.ToString().PadLeft(4)); * sw.WriteLine(); * double sum = 0.0; * for (int i = 0; i < 11; i++) * { * sum += i * an[i]; * sw.Write(an[i].ToString().PadLeft(4)); * } * sw.Write(" " + (int)(100 * (1 - sum / (20 * 500))) + "%" + " " + (int)(100 * (1 - sumwind/(20*r))));*/ } } //Refresh(ref race); }