Skip to content

Estimate time series periodicity

The ts_period_detect function estimates the periodicity of time series data distributed in different time intervals. Syntax: select ts_period_detect(x,y,minPeriod,maxPeriod) The x parameter specifies the time sequence. Points in time are sorted in ascending order. Each point in time is a UNIX timestamp. Unit: seconds. The y parameter specifies the sequence of numeric data at a specific point in time. The minPeriod parameter specifies the ratio of the minimum length of the estimated period to the total length of the sequence. The value must be a decimal number. Valid values: (0,1]. The maxPeriod parameter specifies the ratio of the maximum length of the estimated period to the total length of the sequence. Note: The value of the maxPeriod parameter must be greater than that of the minPeriod parameter. The value must be a decimal number. Valid values: (0,1].

SQL
*
and metric - type: demonetwork |
select
  ts_period_detect(stamp, value, 0.005, 0.2, 1, 'avg')
from
  (
    select
      key [1] as stamp,
      key [3] as value
    from
      (
        select
          ts_smooth_fir(stamp, value, 'rectangle', 4, 1, 'avg') as res
        from
          (
            select
              stamp - stamp % 10 as stamp,
              avg(value) as value
            from
              log
            GROUP by
              stamp
            order by
              stamp
          )
        limit
          1000
      ), unnest(res) as t(key)
  )

SQLSample query result:

样例图片