-
Notifications
You must be signed in to change notification settings - Fork 7
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
P95 #1008
Draft
k2xl
wants to merge
9
commits into
main
Choose a base branch
from
p95
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
P95 #1008
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
072ba20
wip
k2xl 5b305b8
speed up calcPlayAttempts and also calc p95s
k2xl 661ebee
forgot to commit
k2xl 0424893
Merge branch 'main' into p95
sspenst dc0a98c
merge
sspenst f9b7938
Merge branch 'main' into p95
k2xl 8049a19
should group by user first then do the p95
k2xl 5a34345
tests
k2xl f1e9604
merge
sspenst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -816,9 +816,10 @@ describe('Testing stats api', () => { | |
}); | ||
test('calcDifficultyEstimate', async () => { | ||
const level = await initLevel(TestId.USER, 'calcDifficultyEstimate', {}, false); | ||
const toInsert = []; | ||
|
||
for (let i = 0; i < 9; i++) { | ||
await PlayAttemptModel.create({ | ||
toInsert.push({ | ||
_id: new Types.ObjectId(), | ||
// half beaten | ||
attemptContext: i % 2 === 0 ? AttemptContext.JUST_BEATEN : AttemptContext.UNBEATEN, | ||
|
@@ -830,6 +831,8 @@ describe('Testing stats api', () => { | |
}); | ||
} | ||
|
||
await PlayAttemptModel.insertMany(toInsert); | ||
|
||
await queueCalcPlayAttempts(level._id); | ||
await processQueueMessages(); | ||
|
||
|
@@ -844,6 +847,7 @@ describe('Testing stats api', () => { | |
const unbeatenUserId = new Types.ObjectId(); | ||
|
||
// create a playattempt for the 10th unique user | ||
|
||
await PlayAttemptModel.create({ | ||
_id: new Types.ObjectId(), | ||
attemptContext: AttemptContext.UNBEATEN, | ||
|
@@ -864,17 +868,63 @@ describe('Testing stats api', () => { | |
ts: 0, | ||
}); | ||
|
||
const unbeatenUserId2 = new Types.ObjectId(); | ||
|
||
// create a playattempt for the 11th unique user But make it have 0 play time so it shouldn't affect calculations | ||
await PlayAttemptModel.create({ | ||
_id: new Types.ObjectId(), | ||
attemptContext: AttemptContext.UNBEATEN, | ||
endTime: 0, | ||
levelId: level._id, | ||
startTime: 0, | ||
updateCount: 0, | ||
userId: unbeatenUserId, | ||
}); | ||
await UserModel.create({ | ||
_id: unbeatenUserId2, | ||
calc_records: 0, | ||
email: '[email protected]', | ||
last_visited_at: 0, | ||
name: 'unbeaten2', | ||
password: 'unbeaten', | ||
score: 0, | ||
ts: 0, | ||
}); | ||
|
||
await queueCalcPlayAttempts(level._id); | ||
await processQueueMessages(); | ||
|
||
const levelUpdated2 = await LevelModel.findById(level._id); | ||
|
||
expect(levelUpdated2).toBeDefined(); | ||
expect(levelUpdated2?.calc_difficulty_estimate).toBeCloseTo(29.2 * 1.47629); | ||
|
||
/** | ||
* User 1 has 10 | ||
* User 2 has 11 | ||
* User 3 has 12 | ||
* User 4 has 13 | ||
* User 5 has 14 | ||
* User 6 has 15 | ||
* User 7 has 16 | ||
* User 8 has 17 | ||
* User 9 has 18 | ||
* User 10 (created above manually): 20 | ||
* Sum = 146 | ||
*/ | ||
expect(levelUpdated2?.calc_playattempts_duration_sum).toBe(146); | ||
expect(levelUpdated2?.calc_playattempts_just_beaten_count).toBe(5); | ||
|
||
expect(levelUpdated2?.calc_playattempts_unique_users?.length).toBe(10); | ||
|
||
/** Take away top 2.5% and bottom 2.5% for p95 | ||
* User 1 and User 10 are the outliers (10 and 20) | ||
* 146 - 10 - 20 = 116 | ||
*/ | ||
|
||
expect(levelUpdated2?.calc_playattempts_just_beaten_count_p95).toBe(8); // removing user 1 and 10 | ||
expect(levelUpdated2?.calc_playattempts_duration_sum_p95).toBe(116); | ||
|
||
jest.spyOn(TimerUtil, 'getTs').mockReturnValue(30); | ||
await testApiHandler({ | ||
handler: async (_, res) => { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine
sumDuration
andsumDurationP95
? Should have all the data forsumDuration
at this pointThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually i realized when trying to do this that this is risky and not actually as straightforward since i do a bunch of groups. probably safer for now to keep it separate