Skip to content

Commit

Permalink
enhance faketime option to allow subsecond steps. (GPSBabel#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteven4 authored Nov 7, 2022
1 parent ad62873 commit a7332a3
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 5 deletions.
96 changes: 96 additions & 0 deletions reference/track/simint1000m.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
No,Latitude,Longitude,Date,Time
1,66.000103,-179.979040,2022/01/01,00:00:00
2,66.000146,-179.979035,2022/01/01,00:00:01
3,66.000188,-179.979030,2022/01/01,00:00:02
4,66.000106,-179.979250,2022/01/01,00:00:03
5,66.000023,-179.979470,2022/01/01,00:00:04
6,66.000034,-179.979775,2022/01/01,00:00:05
7,66.000045,-179.980080,2022/01/01,00:00:06
8,66.000111,-179.980280,2022/01/01,00:00:07
9,66.000177,-179.980480,2022/01/01,00:00:08
10,66.000143,-179.980575,2022/01/01,00:00:09
11,66.000109,-179.980670,2022/01/01,00:00:10
12,66.000138,-179.981320,2022/01/01,00:00:11
13,66.000167,-179.981970,2022/01/01,00:00:12
14,66.000121,-179.982585,2022/01/01,00:00:13
15,66.000075,-179.983200,2022/01/01,00:00:14
16,66.000105,-179.983745,2022/01/01,00:00:15
17,66.000134,-179.984290,2022/01/01,00:00:16
18,66.000128,-179.984740,2022/01/01,00:00:17
19,66.000121,-179.985190,2022/01/01,00:00:18
20,66.000159,-179.985385,2022/01/01,00:00:19
21,66.000197,-179.985580,2022/01/01,00:00:20
22,66.000177,-179.986145,2022/01/01,00:00:21
23,66.000158,-179.986710,2022/01/01,00:00:22
24,66.000148,-179.987380,2022/01/01,00:00:23
25,66.000138,-179.988050,2022/01/01,00:00:24
26,66.000154,-179.988555,2022/01/01,00:00:25
27,66.000171,-179.989060,2022/01/01,00:00:26
28,66.000111,-179.989380,2022/01/01,00:00:27
29,66.000050,-179.989700,2022/01/01,00:00:28
30,66.000058,-179.990500,2022/01/01,00:00:29
31,66.000066,-179.991300,2022/01/01,00:00:30
32,66.000056,-179.991565,2022/01/01,00:00:31
33,66.000046,-179.991830,2022/01/01,00:00:32
34,66.000089,-179.992615,2022/01/01,00:00:33
35,66.000131,-179.993400,2022/01/01,00:00:34
36,66.000110,-179.993620,2022/01/01,00:00:35
37,66.000088,-179.993840,2022/01/01,00:00:36
38,66.000127,-179.994440,2022/01/01,00:00:37
39,66.000165,-179.995040,2022/01/01,00:00:38
40,66.000180,-179.995500,2022/01/01,00:00:39
41,66.000196,-179.995960,2022/01/01,00:00:40
42,66.000177,-179.996665,2022/01/01,00:00:41
43,66.000158,-179.997370,2022/01/01,00:00:42
44,66.000130,-179.997675,2022/01/01,00:00:43
45,66.000103,-179.997980,2022/01/01,00:00:44
46,66.000104,-179.998505,2022/01/01,00:00:45
47,66.000106,-179.999030,2022/01/01,00:00:46
48,66.000082,-179.999295,2022/01/01,00:00:47
49,66.000057,-179.999560,2022/01/01,00:00:48
50,66.000050,179.999795,2022/01/01,00:00:49
51,66.000042,179.999150,2022/01/01,00:00:50
52,66.000096,179.998730,2022/01/01,00:00:51
53,66.000150,179.998310,2022/01/01,00:00:52
54,66.000172,179.997530,2022/01/01,00:00:53
55,66.000193,179.996750,2022/01/01,00:00:54
56,66.000160,179.996480,2022/01/01,00:00:55
57,66.000128,179.996210,2022/01/01,00:00:56
58,66.000110,179.995570,2022/01/01,00:00:57
59,66.000091,179.994930,2022/01/01,00:00:58
60,66.000141,179.994275,2022/01/01,00:00:59
61,66.000191,179.993620,2022/01/01,00:01:00
62,66.000124,179.993275,2022/01/01,00:01:01
63,66.000057,179.992930,2022/01/01,00:01:02
64,66.000077,179.992520,2022/01/01,00:01:03
65,66.000098,179.992110,2022/01/01,00:01:04
66,66.000069,179.991745,2022/01/01,00:01:05
67,66.000040,179.991380,2022/01/01,00:01:06
68,66.000077,179.990915,2022/01/01,00:01:07
69,66.000114,179.990450,2022/01/01,00:01:08
70,66.000096,179.989495,2022/01/01,00:01:09
71,66.000077,179.988540,2022/01/01,00:01:10
72,66.000045,179.988185,2022/01/01,00:01:11
73,66.000013,179.987830,2022/01/01,00:01:12
74,66.000095,179.987410,2022/01/01,00:01:13
75,66.000176,179.986990,2022/01/01,00:01:14
76,66.000098,179.986525,2022/01/01,00:01:15
77,66.000021,179.986060,2022/01/01,00:01:16
78,66.000057,179.985720,2022/01/01,00:01:17
79,66.000093,179.985380,2022/01/01,00:01:18
80,66.000146,179.984835,2022/01/01,00:01:19
81,66.000199,179.984290,2022/01/01,00:01:20
82,66.000192,179.983700,2022/01/01,00:01:21
83,66.000184,179.983110,2022/01/01,00:01:22
84,66.000153,179.982810,2022/01/01,00:01:23
85,66.000122,179.982510,2022/01/01,00:01:24
86,66.000112,179.982165,2022/01/01,00:01:25
87,66.000102,179.981820,2022/01/01,00:01:26
88,66.000124,179.981825,2022/01/01,00:01:27
89,66.000147,179.981830,2022/01/01,00:01:28
90,66.000109,179.981790,2022/01/01,00:01:29
91,66.000071,179.981750,2022/01/01,00:01:30
92,66.000072,179.981765,2022/01/01,00:01:31
93,66.000073,179.981780,2022/01/01,00:01:32
94,66.000120,179.981700,2022/01/01,00:01:33
95,66.000167,179.981620,2022/01/01,00:01:34
96 changes: 96 additions & 0 deletions reference/track/simint250m.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
No,Latitude,Longitude,Date,Time
1,66.000103,-179.979040,2022/01/01,00:00:00
2,66.000146,-179.979035,2022/01/01,00:00:00.250
3,66.000188,-179.979030,2022/01/01,00:00:00.500
4,66.000106,-179.979250,2022/01/01,00:00:00.750
5,66.000023,-179.979470,2022/01/01,00:00:01
6,66.000034,-179.979775,2022/01/01,00:00:01.250
7,66.000045,-179.980080,2022/01/01,00:00:01.500
8,66.000111,-179.980280,2022/01/01,00:00:01.750
9,66.000177,-179.980480,2022/01/01,00:00:02
10,66.000143,-179.980575,2022/01/01,00:00:02.250
11,66.000109,-179.980670,2022/01/01,00:00:02.500
12,66.000138,-179.981320,2022/01/01,00:00:02.750
13,66.000167,-179.981970,2022/01/01,00:00:03
14,66.000121,-179.982585,2022/01/01,00:00:03.250
15,66.000075,-179.983200,2022/01/01,00:00:03.500
16,66.000105,-179.983745,2022/01/01,00:00:03.750
17,66.000134,-179.984290,2022/01/01,00:00:04
18,66.000128,-179.984740,2022/01/01,00:00:04.250
19,66.000121,-179.985190,2022/01/01,00:00:04.500
20,66.000159,-179.985385,2022/01/01,00:00:04.750
21,66.000197,-179.985580,2022/01/01,00:00:05
22,66.000177,-179.986145,2022/01/01,00:00:05.250
23,66.000158,-179.986710,2022/01/01,00:00:05.500
24,66.000148,-179.987380,2022/01/01,00:00:05.750
25,66.000138,-179.988050,2022/01/01,00:00:06
26,66.000154,-179.988555,2022/01/01,00:00:06.250
27,66.000171,-179.989060,2022/01/01,00:00:06.500
28,66.000111,-179.989380,2022/01/01,00:00:06.750
29,66.000050,-179.989700,2022/01/01,00:00:07
30,66.000058,-179.990500,2022/01/01,00:00:07.250
31,66.000066,-179.991300,2022/01/01,00:00:07.500
32,66.000056,-179.991565,2022/01/01,00:00:07.750
33,66.000046,-179.991830,2022/01/01,00:00:08
34,66.000089,-179.992615,2022/01/01,00:00:08.250
35,66.000131,-179.993400,2022/01/01,00:00:08.500
36,66.000110,-179.993620,2022/01/01,00:00:08.750
37,66.000088,-179.993840,2022/01/01,00:00:09
38,66.000127,-179.994440,2022/01/01,00:00:09.250
39,66.000165,-179.995040,2022/01/01,00:00:09.500
40,66.000180,-179.995500,2022/01/01,00:00:09.750
41,66.000196,-179.995960,2022/01/01,00:00:10
42,66.000177,-179.996665,2022/01/01,00:00:10.250
43,66.000158,-179.997370,2022/01/01,00:00:10.500
44,66.000130,-179.997675,2022/01/01,00:00:10.750
45,66.000103,-179.997980,2022/01/01,00:00:11
46,66.000104,-179.998505,2022/01/01,00:00:11.250
47,66.000106,-179.999030,2022/01/01,00:00:11.500
48,66.000082,-179.999295,2022/01/01,00:00:11.750
49,66.000057,-179.999560,2022/01/01,00:00:12
50,66.000050,179.999795,2022/01/01,00:00:12.250
51,66.000042,179.999150,2022/01/01,00:00:12.500
52,66.000096,179.998730,2022/01/01,00:00:12.750
53,66.000150,179.998310,2022/01/01,00:00:13
54,66.000172,179.997530,2022/01/01,00:00:13.250
55,66.000193,179.996750,2022/01/01,00:00:13.500
56,66.000160,179.996480,2022/01/01,00:00:13.750
57,66.000128,179.996210,2022/01/01,00:00:14
58,66.000110,179.995570,2022/01/01,00:00:14.250
59,66.000091,179.994930,2022/01/01,00:00:14.500
60,66.000141,179.994275,2022/01/01,00:00:14.750
61,66.000191,179.993620,2022/01/01,00:00:15
62,66.000124,179.993275,2022/01/01,00:00:15.250
63,66.000057,179.992930,2022/01/01,00:00:15.500
64,66.000077,179.992520,2022/01/01,00:00:15.750
65,66.000098,179.992110,2022/01/01,00:00:16
66,66.000069,179.991745,2022/01/01,00:00:16.250
67,66.000040,179.991380,2022/01/01,00:00:16.500
68,66.000077,179.990915,2022/01/01,00:00:16.750
69,66.000114,179.990450,2022/01/01,00:00:17
70,66.000096,179.989495,2022/01/01,00:00:17.250
71,66.000077,179.988540,2022/01/01,00:00:17.500
72,66.000045,179.988185,2022/01/01,00:00:17.750
73,66.000013,179.987830,2022/01/01,00:00:18
74,66.000095,179.987410,2022/01/01,00:00:18.250
75,66.000176,179.986990,2022/01/01,00:00:18.500
76,66.000098,179.986525,2022/01/01,00:00:18.750
77,66.000021,179.986060,2022/01/01,00:00:19
78,66.000057,179.985720,2022/01/01,00:00:19.250
79,66.000093,179.985380,2022/01/01,00:00:19.500
80,66.000146,179.984835,2022/01/01,00:00:19.750
81,66.000199,179.984290,2022/01/01,00:00:20
82,66.000192,179.983700,2022/01/01,00:00:20.250
83,66.000184,179.983110,2022/01/01,00:00:20.500
84,66.000153,179.982810,2022/01/01,00:00:20.750
85,66.000122,179.982510,2022/01/01,00:00:21
86,66.000112,179.982165,2022/01/01,00:00:21.250
87,66.000102,179.981820,2022/01/01,00:00:21.500
88,66.000124,179.981825,2022/01/01,00:00:21.750
89,66.000147,179.981830,2022/01/01,00:00:22
90,66.000109,179.981790,2022/01/01,00:00:22.250
91,66.000071,179.981750,2022/01/01,00:00:22.500
92,66.000072,179.981765,2022/01/01,00:00:22.750
93,66.000073,179.981780,2022/01/01,00:00:23
94,66.000120,179.981700,2022/01/01,00:00:23.250
95,66.000167,179.981620,2022/01/01,00:00:23.500
10 changes: 10 additions & 0 deletions testo.d/track.test
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ compare ${REFERENCE}/track/trackfilter_trk2seg~gpx.gpx ${TMPDIR}/trackfilter_trk
# speed with msec
gpsbabel -t -i unicsv -f ${REFERENCE}/track/utm_subsecond_track.csv -x track,speed -o unicsv,utc -F ${TMPDIR}/utm_subsecond_track~csv.csv
compare ${REFERENCE}/track/utm_subsecond_track~csv.csv ${TMPDIR}/utm_subsecond_track~csv.csv

# faketime, with and witout partial second steps
gpsbabel -t -i unicsv -f ${REFERENCE}/track/simint.csv -x track,faketime=f2022+0.25 -o unicsv,utc -F ${TMPDIR}/simint250m.csv
compare ${REFERENCE}/track/simint250m.csv ${TMPDIR}/simint250m.csv
gpsbabel -t -i unicsv -f ${REFERENCE}/track/simint.csv -x track,faketime=f2022+.25 -o unicsv,utc -F ${TMPDIR}/simint250m_2.csv
compare ${REFERENCE}/track/simint250m.csv ${TMPDIR}/simint250m_2.csv
gpsbabel -t -i unicsv -f ${REFERENCE}/track/simint.csv -x track,faketime=f2022+1 -o unicsv,utc -F ${TMPDIR}/simint1000m.csv
compare ${REFERENCE}/track/simint1000m.csv ${TMPDIR}/simint1000m.csv


8 changes: 4 additions & 4 deletions trackfilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ TrackFilter::faketime_t TrackFilter::trackfilter_faketime_check(const char* time
{
faketime_t result;

static const QRegularExpression re(R"(^(f?)(\d{0,14})(?:\+(\d{1,10}))?$)");
static const QRegularExpression re(R"(^(f?)(\d{0,14})(?:\+(\d+(?:\.\d*)?|\.\d+))?$)");
assert(re.isValid());
QRegularExpressionMatch match = re.match(timestr);
if (match.hasMatch()) {
Expand All @@ -843,7 +843,7 @@ TrackFilter::faketime_t TrackFilter::trackfilter_faketime_check(const char* time

if (match.capturedLength(3) > 0) {
bool ok;
result.step = match.captured(3).toInt(&ok);
result.step = llround(1000.0 * match.captured(3).toDouble(&ok));
if (!ok) {
fatal(MYNAME "-faketime-check: Invalid step \"%s\"!\n", qPrintable(match.captured(3)));
}
Expand All @@ -852,7 +852,7 @@ TrackFilter::faketime_t TrackFilter::trackfilter_faketime_check(const char* time
}

#ifdef TRACKF_DBG
qDebug() << MYNAME "-faketime option: force =" << result.force << ", timestamp =" << result.start << ", step =" << result.step;
qDebug() << MYNAME "-faketime option: force =" << result.force << ", timestamp =" << result.start << ", step =" << result.step << "milliseconds";
#endif
} else {
fatal(MYNAME "-faketime-check: Invalid value for faketime option \"%s\"!\n", timestr);
Expand All @@ -871,7 +871,7 @@ void TrackFilter::trackfilter_faketime()

if (!wpt->creation_time.isValid() || faketime.force) {
wpt->creation_time = faketime.start;
faketime.start = faketime.start.addSecs(faketime.step);
faketime.start = faketime.start.addMSecs(faketime.step);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion trackfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class TrackFilter:public Filter

struct faketime_t {
QDateTime start;
int step{0};
long long step{0};
bool force{false};
};

Expand Down

0 comments on commit a7332a3

Please sign in to comment.