public void createStlCsv(string fileName) { if (exerciseDataList == null) { return; } string[] csvColumnNames = new string[] { "id", "category", "event", "location", "tags", "year", "month", "week of year", "start", "finish", "distance", "duration", "duration(s)", "calories", "ave speed", "ave pace", "ave pace(s)", "ave moving speed", "ave moving pace", "ave moving pace(s)", "max speed", "ave heart rate", "elevation gain", "elevation loss", "max elevation" }; // From https://docs.microsoft.com/en-us/dotnet/api/system.globalization.calendar.getweekofyear?view=netframework-4.8 CultureInfo ci = new CultureInfo("en-US"); Calendar cal = ci.Calendar; CalendarWeekRule cwr = ci.DateTimeFormat.CalendarWeekRule; DayOfWeek dow = ci.DateTimeFormat.FirstDayOfWeek; try { using (StreamWriter sw = new StreamWriter(fileName)) { foreach (string col in csvColumnNames) { sw.Write(col + CSV_SEP); } sw.Write(NL); foreach (GpsData data in exerciseDataList) { sw.Write(CSV_SEP); // id sw.Write(data.Category + CSV_SEP); // category sw.Write(CSV_SEP); //event sw.Write(data.Location + CSV_SEP); // location sw.Write(CSV_SEP); // tags sw.Write(data.StartTime.Year + CSV_SEP); // year // STL uses 0-based month number sw.Write(GpsData.formatMonthStl(data.StartTime) + CSV_SEP); // month sw.Write(cal.GetWeekOfYear(data.StartTime, cwr, dow) + CSV_SEP); // week of year sw.Write(GpsData.formatTimeStl(data.StartTime) + CSV_SEP); // start sw.Write(GpsData.formatTimeStl(data.EndTime) + CSV_SEP); // end sw.Write($"{GpsData.M2MI * data.Distance:f2}" + CSV_SEP); // distance sw.Write(GpsData.formatDuration(data.Duration) + CSV_SEP); // duration sw.Write(data.Duration.TotalSeconds + CSV_SEP); // duration(s) sw.Write(CSV_SEP); // calories sw.Write(GpsData.formatSpeed(data.SpeedAvg) + CSV_SEP); // ave speed sw.Write(GpsData.formatPace(data.SpeedAvg) + CSV_SEP); // ave pace sw.Write(GpsData.formatPaceSec(data.SpeedAvg) + CSV_SEP); // ave pace (s) sw.Write(GpsData.formatSpeed(data.SpeedAvgMoving) + CSV_SEP); // ave moving speed sw.Write(GpsData.formatPace(data.SpeedAvgMoving) + CSV_SEP); // ave moving pace sw.Write(GpsData.formatPaceSec(data.SpeedAvgMoving) + CSV_SEP); // ave moving pace(s) sw.Write(GpsData.formatSpeed(data.SpeedMax) + CSV_SEP); // max speed sw.Write(GpsData.formatHeartRateStlAvg(data.HrAvg) + CSV_SEP); // ave heart rate sw.Write(GpsData.formatElevation(data.EleGain) + CSV_SEP); // elevation gain sw.Write(GpsData.formatElevation(data.EleLoss) + CSV_SEP); // elevation loss sw.Write(GpsData.formatElevation(data.EleMax) + CSV_SEP); // elevation max sw.Write(NL); } writeInfo(NL + "Wrote STL CSV " + fileName); } } catch (Exception ex) { Utils.excMsg("Error writing STL CSV file " + fileName, ex); return; } }