如何以微小的精度绘制BigQuery的时间序列?

问题描述 投票:1回答:2

我在BigQuery中有一个数据集,我将其用作创建Data Studio报表的源代码。

我可以使用Timestamp作为维度和我作为指标的其他数字字段将数据绘制为时间序列/组合/折线图。

我遇到的问题是,我能得到的最多精确度是一小时,而我需要一分钟精确度。 BigQuery中的数据集具有毫秒的精度,但我似乎无法在Data Studio中获取它。

我已经阅读了关于使用日期创建字符串并将其用作度量标准,或者提取并组合分钟字段的简短建议,但我似乎无法使其工作。

samp

google-cloud-platform google-bigquery google-data-studio
2个回答
1
投票

在BigQuery中,由TRUNCATEMINUTE组成的GROUP BY。然后在Data Studio中将此时间戳设置为STRING值而不是DATE。使用此时间戳STRING创建一个折线图作为X维度,并且瞧。

enter image description here enter image description here

查询此vis:

WITH data AS (
  SELECT bus, ST_GeogPoint(longitude, latitude) point
    , PARSE_TIMESTAMP('%Y%m%d %H%M%S',FORMAT('%i %06d', day, time)) ts
  FROM `fh-bigquery.mta_nyc_si.201410_bustime`
  WHERE day=20141014
  AND bus IN (7043, 7086, 7076, 2421, 7052, 7071)
)

SELECT bus, TIMESTAMP_TRUNC(ts, MINUTE) ts, AVG(distance/time) speed
FROM (
  SELECT bus, ts
    , ST_DISTANCE(point, LAG(point, 3) OVER(PARTITION BY bus ORDER BY ts)) distance
    , TIMESTAMP_DIFF(ts, LAG(ts, 3) OVER(PARTITION BY bus ORDER BY ts), SECOND) time
  FROM data
)
WHERE time IS NOT null 
GROUP BY bus, ts
HAVING speed < 500

0
投票

您可以使用此查询创建表的视图:

SELECT
  t.*,
  FORMAT_TIMESTAMP("%Y-%m-%d %H:%M", t.timestamp) as date_time
FROM
  `project-id.dataset-id.table-id` AS t

创建此类视图后,您可以将此视图添加为数据源,并使用字段date_time作为时间序列

© www.soinside.com 2019 - 2024. All rights reserved.