public List <Activity> LoadFiles(List <string> fileNames) { //string[] fileNames = Directory.GetFiles(".\\activity\\"); double totalDistance = 0; double totalElevationGain = 0; List <Activity> activities = new List <Activity>(); foreach (string name in fileNames) { Console.WriteLine(name); Activity activity = LoadFile(name); totalDistance += Measurements.CalculateDistance(activity.Points); totalElevationGain += CalculateElevationGain(activity.Points); activities.Add(activity); } activities = activities.OrderBy(x => x.StartTime).ToList(); double discrepancy = 0.0; double elevationGainDiscrepancy = 0.0; for (int i = 0; i < activities.Count - 1; i++) { //check current activity with next activity last point - first point, for discrepances TrackPoint current = activities[i].Points.Last(); TrackPoint next = activities[i + 1].Points.First(); var pointPair = new List <TrackPoint> { current, next }; double d = Measurements.CalculateDistance(pointPair); double e = CalculateElevationGain(pointPair); //skip the bus trip if (d > 100) { continue; } if (d < 1) { continue; } discrepancy += d; elevationGainDiscrepancy += e; // add extra points at 1km intervals int extraPoints = (int)Math.Round(discrepancy); double latInc = (next.Lat - current.Lat) / (extraPoints + 1); double lonInc = (next.Lon - current.Lon) / (extraPoints + 1); //consider an average of 6 minutes per km double minInc = 6.0; for (int j = 0; j < extraPoints + 1; j++) { //add the new activity TrackPoint n = new TrackPoint { Lat = current.Lat + latInc * j, Lon = current.Lon + lonInc * j, Elevation = next.Elevation, Time = next.Time > current.Time.AddMinutes(minInc * j) ? current.Time.AddMinutes(minInc * j) : next.Time }; activities[i].Points.Add(n); } } Console.WriteLine($"Untracked distance: {discrepancy}"); Console.WriteLine($"Untracked elevation gain: {elevationGainDiscrepancy}"); totalDistance += discrepancy; Console.WriteLine($"Total distance: {totalDistance}"); Console.WriteLine($"Total elevation gain: {totalElevationGain}"); return(activities); }