-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suggest recipes based on cook history
- Loading branch information
Showing
8 changed files
with
109 additions
and
8 deletions.
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/brennaswitzer/cookbook/graphql/model/SuggestionRequest.java
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.brennaswitzer.cookbook.graphql.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class SuggestionRequest { | ||
|
||
int first; | ||
|
||
OffsetConnectionCursor after; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/brennaswitzer/cookbook/repositories/PlannedRecipeHistoryRepository.java
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 |
---|---|---|
@@ -1,6 +1,35 @@ | ||
package com.brennaswitzer.cookbook.repositories; | ||
|
||
import com.brennaswitzer.cookbook.domain.PlannedRecipeHistory; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.List; | ||
|
||
public interface PlannedRecipeHistoryRepository extends BaseEntityRepository<PlannedRecipeHistory> { | ||
|
||
/** | ||
* I return a list of recipe ids based on how likely the user is to want to | ||
* cook them, most likely first. The specific algorithm (and its parameters) | ||
* are subject to change. | ||
* | ||
* <p>Currently, recipes are ranked based on the user's (not other users') | ||
* ratings, decayed over time. If a recipe was cooked but not rated, a | ||
* 3-star rating is assumed. If a recipe was cooked two months ago, it will | ||
* contribute half the weight it would if it were cooked today. Four months | ||
* ago will contribute a quarter as much as today. | ||
*/ | ||
@Query(value = """ | ||
SELECT recipe_id | ||
FROM planned_recipe_history | ||
WHERE owner_id = :userId | ||
AND status_id = 100 -- completed | ||
GROUP BY recipe_id | ||
ORDER BY SUM(EXP(LN(0.5) / 60 * (CURRENT_DATE - CAST(done_at AS DATE))) * COALESCE(rating, 3)) DESC | ||
, 1 | ||
LIMIT :limit | ||
OFFSET :offset | ||
""", | ||
nativeQuery = true) | ||
List<Long> getRecipeSuggestions(Long userId, int offset, int limit); | ||
|
||
} |
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
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