コード例 #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;
            }
        }
コード例 #2
0
        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;
            }
        }