Share via


series_downsample_fl()

함수 series_downsample_fl() 는 정수 인수로 시계열을 다운샘플링하는 UDF(사용자 정의 함수)입니다. 이 함수는 여러 시계열(동적 숫자 배열)이 포함된 테이블을 가져와서 각 계열을 다운샘플링합니다. 출력에는 거친 계열과 해당 시간 배열이 모두 포함됩니다. 별칭 지정을 방지하기 위해 함수는 하위 샘플링 전에 각 계열에 간단한 로우 패스 필터를 적용합니다.

Syntax

T | invoke series_downsample_fl(, t_col, y_col, ds_t_col, ds_y_colsampling_factor)

구문 규칙에 대해 자세히 알아봅니다.

매개 변수

이름 형식 필수 Description
t_col string ✔️ 다운샘플할 계열의 시간 축을 포함하는 열의 이름입니다.
y_col string ✔️ 다운샘플할 계열이 포함된 열의 이름입니다.
ds_t_col string ✔️ 각 계열의 다운 샘플링된 시간 축을 저장할 열의 이름입니다.
ds_y_col string ✔️ 다운 샘플링된 계열을 저장할 열의 이름입니다.
sampling_factor int ✔️ 필요한 다운 샘플링을 지정하는 정수입니다.

함수 정의

코드를 쿼리 정의 함수로 포함하거나 다음과 같이 데이터베이스에 저장된 함수로 만들어 함수를 정의할 수 있습니다.

다음 let 문을 사용하여 함수를 정의합니다. 사용 권한이 필요 없습니다.

중요

let 문은 자체적으로 실행할 수 없습니다. 테이블 형식 식 문 뒤에 이어서야 합니다. 의 작업 예제를 실행하려면 예제 series_downsample_fl()를 참조 하세요.

let series_downsample_fl=(tbl:(*), t_col:string, y_col:string, ds_t_col:string, ds_y_col:string, sampling_factor:int)
{
    tbl
    | extend _t_ = column_ifexists(t_col, dynamic(0)), _y_ = column_ifexists(y_col, dynamic(0))
    | extend _y_ = series_fir(_y_, repeat(1, sampling_factor), true, true)    //  apply a simple low pass filter before sub-sampling
    | mv-apply _t_ to typeof(DateTime), _y_ to typeof(double) on
    (extend rid=row_number()-1
    | where rid % sampling_factor == ceiling(sampling_factor/2.0)-1                    //  sub-sampling
    | summarize _t_ = make_list(_t_), _y_ = make_list(_y_))
    | extend cols = bag_pack(ds_t_col, _t_, ds_y_col, _y_)
    | project-away _t_, _y_
    | evaluate bag_unpack(cols)
};
// Write your query to use the function here.

예제

다음 예제에서는 invoke 연산자를 사용하여 함수를 실행합니다.

쿼리 정의 함수를 사용하려면 포함된 함수 정의 다음에 호출합니다.

let series_downsample_fl=(tbl:(*), t_col:string, y_col:string, ds_t_col:string, ds_y_col:string, sampling_factor:int)
{
    tbl
    | extend _t_ = column_ifexists(t_col, dynamic(0)), _y_ = column_ifexists(y_col, dynamic(0))
    | extend _y_ = series_fir(_y_, repeat(1, sampling_factor), true, true)    //  apply a simple low pass filter before sub-sampling
    | mv-apply _t_ to typeof(DateTime), _y_ to typeof(double) on
    (extend rid=row_number()-1
    | where rid % sampling_factor == ceiling(sampling_factor/2.0)-1                    //  sub-sampling
    | summarize _t_ = make_list(_t_), _y_ = make_list(_y_))
    | extend cols = bag_pack(ds_t_col, _t_, ds_y_col, _y_)
    | project-away _t_, _y_
    | evaluate bag_unpack(cols)
};
demo_make_series1
| make-series num=count() on TimeStamp step 1h by OsVer
| invoke series_downsample_fl('TimeStamp', 'num', 'coarse_TimeStamp', 'coarse_num', 4)
| render timechart with(xcolumn=coarse_TimeStamp, ycolumns=coarse_num)

출력

시계열 다운샘플링 4: 시계열의 다운샘플링을 보여 주는 그래프입니다.

참고로 원래 시계열(다운샘플링 전)은 다음과 같습니다.

demo_make_series1
| make-series num=count() on TimeStamp step 1h by OsVer
| render timechart with(xcolumn=TimeStamp, ycolumns=num)

다운샘플링 전의 원래 시계열을 보여 주는 그래프