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

512 Added max-recency boundries #526

Merged
merged 11 commits into from
Oct 5, 2024
Merged

512 Added max-recency boundries #526

merged 11 commits into from
Oct 5, 2024

Conversation

aaryansinha16
Copy link
Contributor

Added the data limit for maximum recency allowed by each tier

Copy link
Collaborator

@trixobird trixobird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should work, let's fix the comments. You also have some eslint errors. You probably need to configure vscode to show them. Mine for example are
image

packages/channel-utils/src/date-utils.ts Outdated Show resolved Hide resolved
packages/mappings/src/tier-mapping.ts Outdated Show resolved Hide resolved
packages/channel-utils/src/date-utils.ts Outdated Show resolved Hide resolved
@aaryansinha16 aaryansinha16 force-pushed the 512-align-data-recency branch 3 times, most recently from 3e764b7 to 1dfbc65 Compare September 19, 2024 18:29
Copy link
Collaborator

@trixobird trixobird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's create some tests for the timeRanges. In order not o mess with db calls let's create another function that start after the db call.

Let me know if you want to talk about it.

packages/channel-utils/src/date-utils.ts Show resolved Hide resolved
packages/channel-utils/src/date-utils.ts Outdated Show resolved Hide resolved
@aaryansinha16 aaryansinha16 force-pushed the 512-align-data-recency branch 2 times, most recently from 54864ff to 486645c Compare September 23, 2024 06:19
Comment on lines 21 to 42
const organizations = latestInsight?.adAccount?.organizations ?? [];

const organizationWithHighestTier =
organizations.length > 0
? organizations.sort((a, b) => tierConstraints[b.tier].order - tierConstraints[a.tier].order)[0].tier
: undefined;

const maxRecency = tierConstraints[organizationWithHighestTier ?? Tier.Launch].maxRecency;

if (initial) {
const range = getLastXMonths();

if (!organizationWithHighestTier) {
return splitTimeRange(tierConstraints[Tier.Launch].maxRecency, range.since, range.until);
}

return splitTimeRange(maxRecency, range.since, range.until);
}
const furthestDate = addInterval(new Date(), 'day', -maxRecency);
const insightDateWithinLimit = latestInsight && latestInsight.date > furthestDate ? latestInsight.date : furthestDate;
const range = getDayPriorTillTomorrow(insightDateWithinLimit);
return splitTimeRange(maxRecency, range.since, range.until);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const organizations = latestInsight?.adAccount?.organizations ?? [];
const organizationWithHighestTier =
organizations.length > 0
? organizations.sort((a, b) => tierConstraints[b.tier].order - tierConstraints[a.tier].order)[0].tier
: undefined;
const maxRecency = tierConstraints[organizationWithHighestTier ?? Tier.Launch].maxRecency;
if (initial) {
const range = getLastXMonths();
if (!organizationWithHighestTier) {
return splitTimeRange(tierConstraints[Tier.Launch].maxRecency, range.since, range.until);
}
return splitTimeRange(maxRecency, range.since, range.until);
}
const furthestDate = addInterval(new Date(), 'day', -maxRecency);
const insightDateWithinLimit = latestInsight && latestInsight.date > furthestDate ? latestInsight.date : furthestDate;
const range = getDayPriorTillTomorrow(insightDateWithinLimit);
return splitTimeRange(maxRecency, range.since, range.until);
return testTimeRange(initial, latestInsight);

I am a bit confused. You have created a testTimeRange (probably a name that we need to change) function that you test, but the product code does not use it.

packages/channel-utils/test/date-util.test.ts Outdated Show resolved Hide resolved
};

const ranges = testTimeRange(false, dummyInsight);
assert.strictEqual(ranges.length, 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that these tests will fail as time passes. This should help you.

@@ -57,4 +94,31 @@ void describe('splitTimeRange tests', () => {
assert.strictEqual(ranges[2].since.toISOString(), '2021-06-30T00:00:00.000Z');
assert.strictEqual(ranges[2].until.toISOString(), '2021-09-25T00:00:00.000Z');
});

void it('returns split time range when passed with false initial', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a test where the last insight was 3 months back and the tier is Launch?

@aaryansinha16 aaryansinha16 force-pushed the 512-align-data-recency branch 6 times, most recently from fd09815 to 57df657 Compare October 4, 2024 08:28
packages/channel-utils/test/date-util.test.ts Show resolved Hide resolved
assert.strictEqual(ranges.length, 26);
assert.strictEqual(ranges[0].since.toISOString(), '2024-01-01T00:00:00.000Z');
assert.strictEqual(ranges[0].until.toISOString(), '2024-01-07T00:00:00.000Z');
assert.strictEqual(ranges[1].since.toISOString(), '2024-01-08T00:00:00.000Z');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is find not to check all 26 ranges, but please check the first and the last at least.

packages/channel-utils/test/date-util.test.ts Show resolved Hide resolved
assert.strictEqual(ranges[0].until.toISOString(), '2024-06-25T18:30:00.000Z');
});

void it('returns correct time range when last insight was 3 months ago and tier is Launch', (context) => {
Copy link
Collaborator

@trixobird trixobird Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these last two test should produce the same result. I would expect one range from midnight 18 till 26 midnight. This means that the existing code has a bug.

@aaryansinha16 aaryansinha16 merged commit 13a5b91 into main Oct 5, 2024
4 checks passed
@aaryansinha16 aaryansinha16 deleted the 512-align-data-recency branch October 5, 2024 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants