public Result CalculateTyreDegradation(Tyre tyreData) { Result retval = new Result(); TrackDegrCoef trackData = TrackCoefPoints[SelectedTrackIndex]; List <int> trackPoints = trackData.Values; if (trackPoints.Count < 0) { return(null); } double average = trackPoints.Average(); double range = trackPoints.Max() - trackPoints.Min(); double mode = trackPoints .GroupBy(x => x) .OrderByDescending(x => x.Count()).ThenBy(x => x.Key) .Select(x => x.Key) .FirstOrDefault(); double degPercentage; switch (tyreData.Type) { case "SuperSoft": degPercentage = 0.8; break; case "Soft": degPercentage = 0.8; break; case "Medium": degPercentage = 0.9; break; case "Hard": degPercentage = 0.75; break; default: degPercentage = 1; break; } double tyreCoef = degPercentage * tyreData.DegradationCoefficient; int trackTemperature = Int32.Parse(Temperature); retval.Average = (int)Math.Ceiling((average * trackTemperature) / tyreCoef); retval.Mode = (int)Math.Ceiling((mode * trackTemperature) / tyreCoef); retval.Range = (int)Math.Ceiling((range * trackTemperature) / tyreCoef); return(retval); }
public List <TrackDegrCoef> DeserializeTxt(string filename) { List <TrackDegrCoef> tdCoefs = new List <TrackDegrCoef>(); string[] coefs = File.ReadAllLines(filename); for (int i = 0; i < coefs.Length; i++) { TrackDegrCoef coef = new TrackDegrCoef(); char[] delimiter = { '|' }; int count = 3; string[] coefFields = coefs[i].Split(delimiter, count); coef.TrackName = coefFields[0]; coef.TrackLocation = coefFields[1]; char[] valDelimiter = { ',' }; string[] coefValues = coefFields[2].Split(valDelimiter); int[] coefIntVals = Array.ConvertAll(coefValues, int.Parse); coef.Values = coefIntVals.ToList(); tdCoefs.Add(coef); } return(tdCoefs); }