public void OpenOldRace() { OpenFileDialog ofd = new OpenFileDialog(); ofd.FileName = "sample"; ofd.DefaultExt = ".csv"; ofd.Filter = "Comma Separated Values (.csv)|*.csv"; Nullable <bool> result = ofd.ShowDialog(); if (result == true) { string filename = ofd.FileName; RacingVisibility = Visibility.Collapsed; AnalyzingVisibility = Visibility.Visible; rm = ReadFile(filename); CollectionLaps.Clear(); CollectionLaps.Add("All Laps"); for (int i = 1; i < rm.CompletedLaps[rm.CompletedLaps.Count - 1] + 1; i++) { CollectionLaps.Add(i.ToString()); } int numberOfSections; rm.TurnSections = Utils.FindTurnsBasedOnLap(rm.CompletedLaps, rm.AccG, rm.CarCoordinates, 0, out numberOfSections); CollectionSections.Clear(); CollectionSections.Add("All Sections"); for (int i = 1; i <= numberOfSections; i++) { CollectionSections.Add(i.ToString()); } UpdateScreen(); } }
private RaceModel ReadFile(string filename) { RaceModel model = new RaceModel(); var fields = typeof(RaceModel).GetProperties(BindingFlags.Public | BindingFlags.Instance); System.IO.StreamReader filestream = new System.IO.StreamReader(filename); string line = filestream.ReadLine(); //string[] instancenames = line.Split(','); while ((line = filestream.ReadLine()) != null) { string[] values = line.Split(','); for (int i = 0; i < values.Count(); i++) { var oldvalue = fields[i].GetValue(model); if (oldvalue.GetType() == typeof(List <float>)) { var array = oldvalue as List <float>; array.Add(float.Parse(values[i])); fields[i].SetValue(model, array); } else if (oldvalue.GetType() == typeof(List <List <float> >)) { var array = oldvalue as List <List <float> >; string[] numbersString = values[i].Split(':'); if (array.Count == 0) { for (int j = 0; j < numbersString.Count() - 1; j++) { array.Add(new List <float>()); } } for (int j = 0; j < numbersString.Count() - 1; j++) //one less time, since the last one is blank { array[j].Add(float.Parse(numbersString[j])); } fields[i].SetValue(model, array); } else if (oldvalue.GetType() == typeof(List <string>)) { var array = oldvalue as List <string>; array.Add(values[i]); fields[i].SetValue(model, array); } else if (oldvalue.GetType() == typeof(List <int>)) { var array = oldvalue as List <int>; array.Add(int.Parse(values[i])); fields[i].SetValue(model, array); } } } return(model); }
private RaceModel ReadFile(string filename) { RaceModel model = new RaceModel(); var fields = typeof(RaceModel).GetProperties(BindingFlags.Public | BindingFlags.Instance); System.IO.StreamReader filestream = new System.IO.StreamReader(filename); string line = filestream.ReadLine(); //string[] instancenames = line.Split(','); while ((line = filestream.ReadLine()) != null) { string[] values = line.Split(','); for (int i = 0; i < values.Count(); i++) { var oldvalue = fields[i].GetValue(model); if (oldvalue.GetType() == typeof(List<float>)) { var array = oldvalue as List<float>; array.Add(float.Parse(values[i])); fields[i].SetValue(model, array); } else if (oldvalue.GetType() == typeof(List<List<float>>)) { var array = oldvalue as List<List<float>>; string[] numbersString = values[i].Split(':'); if (array.Count == 0) { for (int j = 0; j < numbersString.Count() - 1; j++) { array.Add(new List<float>()); } } for (int j = 0; j < numbersString.Count() - 1; j++) //one less time, since the last one is blank { array[j].Add(float.Parse(numbersString[j])); } fields[i].SetValue(model, array); } else if (oldvalue.GetType() == typeof(List<string>)) { var array = oldvalue as List<string>; array.Add(values[i]); fields[i].SetValue(model, array); } else if (oldvalue.GetType() == typeof(List<int>)) { var array = oldvalue as List<int>; array.Add(int.Parse(values[i])); fields[i].SetValue(model, array); } } } return model; }
public void OpenOldRace() { OpenFileDialog ofd = new OpenFileDialog(); ofd.FileName = "sample"; ofd.DefaultExt = ".csv"; ofd.Filter = "Comma Separated Values (.csv)|*.csv"; Nullable<bool> result = ofd.ShowDialog(); if (result == true) { string filename = ofd.FileName; RacingVisibility = Visibility.Collapsed; AnalyzingVisibility = Visibility.Visible; rm = ReadFile(filename); CollectionLaps.Clear(); CollectionLaps.Add("All Laps"); for (int i = 1; i < rm.CompletedLaps[rm.CompletedLaps.Count - 1] + 1; i++) { CollectionLaps.Add(i.ToString()); } int numberOfSections; rm.TurnSections = Utils.FindTurnsBasedOnLap(rm.CompletedLaps, rm.AccG, rm.CarCoordinates, 0, out numberOfSections); CollectionSections.Clear(); CollectionSections.Add("All Sections"); for (int i = 1; i <= numberOfSections; i++) { CollectionSections.Add(i.ToString()); } UpdateScreen(); } }