当我继续我的问题(删除),我可以确认我要计算的采样率的描述。采样与每次行程的gps点有关。我的表如下所示(实际上我应该调用最后一列采样间隔而不是速率):
SELECT * FROM trajectories_splitted LIMIT 10;
user_id | session_id | timestamp | lat | lon | alt | sampling_rate | rate_diff
---------+----------------+------------------------+-----------+------------+-----+---------------+-----------
1 | 20081023025304 | 2008-10-23 02:53:04+01 | 39.984702 | 116.318417 | 492 | |
1 | 20081023025304 | 2008-10-23 02:53:10+01 | 39.984683 | 116.31845 | 492 | 00:00:06 | 6
1 | 20081023025304 | 2008-10-23 02:53:15+01 | 39.984686 | 116.318417 | 492 | 00:00:05 | 5
1 | 20081023025304 | 2008-10-23 02:53:20+01 | 39.984688 | 116.318385 | 492 | 00:00:05 | 5
1 | 20081023025304 | 2008-10-23 02:53:25+01 | 39.984655 | 116.318263 | 492 | 00:00:05 | 5
1 | 20081023025304 | 2008-10-23 02:53:30+01 | 39.984611 | 116.318026 | 493 | 00:00:05 | 5
1 | 20081023025305 | 2008-10-23 04:08:07+01 | 39.995777 | 116.286798 | 716 | |
1 | 20081023025305 | 2008-10-23 04:08:12+01 | 39.996832 | 116.285446 | 276 | 00:00:05 | 5
1 | 20081023025305 | 2008-10-23 04:08:42+01 | 39.984397 | 116.299292 | 931 | 00:00:30 | 30
1 | 20081023025305 | 2008-10-23 04:08:47+01 | 39.984426 | 116.299329 | 959 | 00:00:05 | 5
1 | 20081023025305 | 2008-10-23 04:08:52+01 | 39.984499 | 116.299413 | 983 | 00:00:05 | 5
1 | 20081023025305 | 2008-10-23 04:08:57+01 | 39.984424 | 116.299467 | 990 | 00:00:05 | 5
1 | 20081023025305 | 2008-10-23 04:09:02+01 | 39.98441 | 116.299477 | 940 | 00:00:05 | 5
1 | 20081023025305 | 2008-10-23 04:09:07+01 | 39.984421 | 116.299569 | 928 | 00:00:05 | 5
1 | 20081023025305 | 2008-10-23 04:09:12+01 | 39.984518 | 116.29953 | 902 | 00:00:05 | 5
1 | 20081023025305 | 2008-10-23 04:09:17+01 | 39.984488 | 116.299645 | 897 | 00:00:05 | 5
这显示了两次行程的gps轨迹: 20081023025304
以及 20081023025305
.
为了计算旅行的采样率,我应该:
对于那次旅行,重复这个得到每次旅行的值(然后我可以绘制)。
为此,我需要访问第一个和最后一个 timestamp
每次行程(其中 session_id
表示唯一行程)。比如说trip 20081023025305
如上所述,采样率为:
i、 e.点数-1/持续时间。我不确定 LEAD/LAG
在这种情况下,可以使用函数获取first last/first timestamp
每次旅行。
编辑
我想得到这样的东西:
+----------------+---------------+
| session_id | sampling_rate |
+----------------+---------------+
| 20081023025304 | 0.1923 |
| 20081023025305 | 0.1286 |
+----------------+---------------+
为了 20081023025304
是 6points -1 /26 secs
以及 20081023025305
是 10points - 1 / 70 secs
.
也许最好说 rate = totalPoints -1 / sum(rate_diff)
为了那次旅行。
1条答案
按热度按时间jmp7cifd1#
这很简单: