Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sample func 采样目标必须大于2 #2004

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/f2-algorithm/src/lttbDownSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export default function lttbDownSample(data, options?: OptionsProps) {
const len = data.length;
const targetCount = len / rate;

if (rate >= len || targetCount === 0) {
if (rate >= len || targetCount < 2) {
return data;
}

const sampled = [];
let sampledIndex = 0;
// Bucket size
// Bucket size targetCount需大于2
const bucketSize = Math.floor((len - 2) / (targetCount - 2));

// A is the first point in the triangle
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion packages/f2-algorithm/test/sample.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('sample', () => {
expect(context).toMatchImageSnapshot();
});

it('rate 小于 data个数', async () => {
it('rate 小于可抽个数', async () => {
const res = await fetch(url);
const result = [
{ value: { value: '0.516' }, updateTime: '2023-10-26T16:00:00.000Z', extInfo: null },
Expand All @@ -70,6 +70,9 @@ describe('sample', () => {
{ value: { value: '0.516' }, updateTime: '2023-10-29T16:00:00.000Z', extInfo: null },
{ value: { value: '0.472' }, updateTime: '2023-10-30T16:00:00.000Z', extInfo: null },
{ value: { value: '0.448' }, updateTime: '2023-10-31T16:00:00.000Z', extInfo: null },
{ value: { value: '0.478' }, updateTime: '2023-10-32T16:00:00.000Z', extInfo: null },
{ value: { value: '0.458' }, updateTime: '2023-10-33T16:00:00.000Z', extInfo: null },
{ value: { value: '0.455' }, updateTime: '2023-10-34T16:00:00.000Z', extInfo: null },
];
const data = result.map((d) => {
return {
Expand Down
Loading