웹
data pivot 데이터 피벗만들기. feat rxjs
아카이sun
2023. 12. 18. 16:26
기록을 위해 작성.
기존 데이터를 pivot형태로 만들기.
1. 데이터 준비 (시간별 랜덤값)
const data = new Array(24).fill(0).map((n,i)=> ({
h:i+1,
val1: Math.ceil(Math.random(1, 10)*10),
val2: Math.ceil(Math.random(1, 10)*10)
}))
2. 데이터 피벗 (rxjs and reduce)
const subs = rxjs.from(data).pipe(
rxjs.reduce((acc, item) => {
acc[0][item.h] = item.h;
acc[1][item.h] = item.val1;
acc[2][item.h] = item.val2;
return acc;
}, [{}, {}, {}])
);
3. 데이터 확인
subs.subscribe(res=>console.log(res))
확인
랜덤값을 만들고 피벗 적용이 잘 되었음을 확인.