window transform: difference, ratio, first and last drop the trailing outputs of each series

Đang mở Phù hợp với người mới
#2,472 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, node.js

Hướng nghiên cứu

Đọc src/transforms/window.js và kiểm tra reduceDifference, reduceRatio, reduceFirst và reduceLast, so sánh giới hạn vòng lặp ở chế độ strict và non-strict với hành vi được mô tả trong các ví dụ. Thêm hoặc cập nhật kiểm thử cho các đầu ra cuối ở cả hai chế độ, sau đó chạy các kiểm thử window transform liên quan. Hoàn thành khi các reducer này tạo ra đầu ra có độ dài đầy đủ như mong đợi, bao gồm cả các cửa sổ cuối bị cắt cụt khi strict là false.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

The difference, ratio, first and last window reducers stop their loops early: with strict: true the last full window is missing, and with strict: false the last k - 1 - s truncated windows are missing. Other reducers such as mean fill these positions.

import * as Plot from "@observablehq/plot";

const run = (w, data) => {
  const o = Plot.windowY(w, {x: "i", y: "v"});
  o.transform(data, [Uint32Array.from(data, (_, i) => i)]);
  return Array.from(o.y.transform());
};
const d = [2, 4, 8, 16].map((v, i) => ({i, v}));

console.log(run({k: 2, reduce: "difference", strict: true, anchor: "end"}, d));
console.log(run({k: 2, reduce: "ratio",      strict: true, anchor: "end"}, d));
console.log(run({k: 1, reduce: "last",       strict: true}, d));
console.log(run({k: 3, reduce: "first",      anchor: "start"}, d));
console.log(run({k: 3, reduce: "difference", anchor: "start"}, d));
console.log(run({k: 3, reduce: "mean",       anchor: "start"}, d));

node t.mjs

Actual:

[ undefined, 2, 4, undefined ]
[ undefined, 2, 2, undefined ]
[ 2, 4, 8, undefined ]
[ 2, 4, undefined, undefined ]
[ 6, 12, undefined, undefined ]
[ 4.666666666666667, 9.333333333333334, 12, 16 ]

Expected:

[ undefined, 2, 4, 8 ]
[ undefined, 2, 2, 2 ]
[ 2, 4, 8, 16 ]
[ 2, 4, 8, 16 ]
[ 6, 12, 8, 0 ]
[ 4.666666666666667, 9.333333333333334, 12, 16 ]

In a chart, Plot.lineY(data, Plot.windowY({k: 7, reduce: "difference"}, ...)) stops short of the right edge.

Tested with @observablehq/plot 0.6.19 and main 2245188, Node.js v26.13.0.

In src/transforms/window.js, reduceDifference, reduceRatio, reduceFirst and reduceLast use n = I.length - k in the strict branch (should be I.length - k + 1) and n = I.length - k + s + 1 in the non-strict branch (should be I.length - s, with the window clipped to I.length).

Credit: https://ucsbplse.github.io/

Ngôn ngữ chính
HTML
Star
5.4k
Fork
251
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của observablehq/plot

Tất cả issue của observablehq/plot

Issue tương tự

Thêm issue về Data Visualization

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.