Skip to content

Commit

Permalink
get rid of datetime filter
Browse files Browse the repository at this point in the history
  • Loading branch information
k2xl committed Oct 1, 2023
1 parent fbc29b7 commit 4198d4e
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pages/api/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ async function getRecentAverageDifficulty(reqUser: User, numResults = 1) {

async function getRecommendedLevel(reqUser: User) {
const avgDifficulty = await getRecentAverageDifficulty(reqUser, 10);
const levelsPlayedHour = await getPlayAttempts(reqUser, {
// query where datetime is greater than 1 hour ago so we don't recommend levels they have recently tried
datetime: new Date(Date.now() - 1 * 60 * 60 * 1000)
});
const recentPlayAttempts = await getPlayAttempts(reqUser, {}, 10);

const uniqueLevelIdsFromPastHour = new Set(levelsPlayedHour.map(playAttempt => playAttempt.levelId._id.toString()));
const uniqueLevelIdsFromRecentAttempts = new Set(recentPlayAttempts.map(playAttempt => playAttempt.levelId._id.toString()));

const query = {
disableCount: 'true',
excludeLevelIds: [...uniqueLevelIdsFromPastHour].join(','),
excludeLevelIds: [...uniqueLevelIdsFromRecentAttempts].join(','),
minSteps: '7',
maxSteps: '2500',
minDifficulty: String(avgDifficulty * 0.9), // 10% below average of last 10
Expand All @@ -90,7 +87,7 @@ async function getRecommendedLevel(reqUser: User) {
// try a broader query without min and max difficulty for those rare users that have beaten so many levels to not have any recommended one
const query = {
disableCount: 'true',
excludeLevelIds: [...uniqueLevelIdsFromPastHour].join(','),
excludeLevelIds: [...uniqueLevelIdsFromRecentAttempts].join(','),
minSteps: '7',
maxSteps: '2500',
minRating: '0.55',
Expand Down

0 comments on commit 4198d4e

Please sign in to comment.