Пример #1
0
        public void createCsv(string fileName)
        {
            if (exerciseDataList == null)
            {
                return;
            }
            string[] csvColumnNames = new string[] { "Category", "Location",
                                                     "Start", "Finish", "Time Zone", "Distance", "Duration", "Duration(s)",
                                                     "Avg Speed", "Min HR", "Avg HR", "Max HR" };

            // 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(data.Category + CSV_SEP);                                     // category
                        sw.Write(data.Location + CSV_SEP);                                     // location
                        sw.Write(GpsData.formatTime(data.StartTime) + CSV_SEP);                // start
                        sw.Write(GpsData.formatTime(data.EndTime) + CSV_SEP);                  // end
                        sw.Write(GpsData.formatTimeZone(data.StartTime, data.TZId) + 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(GpsData.formatSpeed(data.SpeedAvg) + CSV_SEP);                // avg speed
                        sw.Write(GpsData.formatHeartRate(data.HrMin) + CSV_SEP);               // min heart rate
                        sw.Write(GpsData.formatHeartRateAvg(data.HrAvg) + CSV_SEP);            // avg heart rate
                        sw.Write(GpsData.formatHeartRate(data.HrMax) + CSV_SEP);               // max heart rate
                        sw.Write(NL);
                    }
                    writeInfo(NL + "Wrote STL CSV " + fileName);
                }
            } catch (Exception ex) {
                Utils.excMsg("Error writing STL CSV file " + fileName, ex);
                return;
            }
        }