Skip to content

Commit b9c9caf

Browse files
committed
Matchup with closest rank, not a random pick.
- This reduces the time to reach confidence also. - Fixes #52
1 parent 555cb9d commit b9c9caf

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

app/src/main/java/com/dessalines/rankmyfavs/db/FavListItem.kt

+14-10
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,20 @@ interface FavListItemDao {
164164
)
165165
fun leastTrained(favListId: Int): FavListItem?
166166

167+
// Sort the second match by the closest neighbor, IE abs(difference)
167168
@Query(
168169
"""
169170
SELECT * FROM FavListItem
170171
WHERE fav_list_id = :favListId
171-
AND id <> :firstFavListItemId
172-
ORDER BY RANDOM()
172+
AND id <> :firstItemId
173+
ORDER BY ABS(glicko_rating - :firstGlickoRating), RANDOM()
173174
LIMIT 1
174175
""",
175176
)
176-
fun randomAndNot(
177+
fun closestMatch(
177178
favListId: Int,
178-
firstFavListItemId: Int,
179+
firstItemId: Int,
180+
firstGlickoRating: Float,
179181
): FavListItem?
180182

181183
@Insert(entity = FavListItem::class, onConflict = OnConflictStrategy.IGNORE)
@@ -218,10 +220,11 @@ class FavListItemRepository(
218220

219221
fun leastTrained(favListId: Int) = favListItemDao.leastTrained(favListId)
220222

221-
fun randomAndNot(
223+
fun closestMatch(
222224
favListId: Int,
223-
favListItemId: Int,
224-
) = favListItemDao.randomAndNot(favListId, favListItemId)
225+
firstItemId: Int,
226+
firstGlickoRating: Float,
227+
) = favListItemDao.closestMatch(favListId, firstItemId, firstGlickoRating)
225228

226229
fun insert(favListItem: FavListItemInsert) = favListItemDao.insert(favListItem)
227230

@@ -249,10 +252,11 @@ class FavListItemViewModel(
249252

250253
fun leastTrained(favListId: Int) = repository.leastTrained(favListId)
251254

252-
fun randomAndNot(
255+
fun closestMatch(
253256
favListId: Int,
254-
favListItemId: Int,
255-
) = repository.randomAndNot(favListId, favListItemId)
257+
firstItemId: Int,
258+
firstGlickoRating: Float,
259+
) = repository.closestMatch(favListId, firstItemId, firstGlickoRating)
256260

257261
fun insert(favListItem: FavListItemInsert) = repository.insert(favListItem)
258262

app/src/main/java/com/dessalines/rankmyfavs/ui/components/match/MatchScreen.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fun MatchScreen(
6060
val first = favListItemViewModel.leastTrained(favListId)
6161
val second =
6262
if (first !== null) {
63-
favListItemViewModel.randomAndNot(favListId, first.id)
63+
favListItemViewModel.closestMatch(favListId, first.id, first.glickoRating)
6464
} else {
6565
null
6666
}
@@ -236,6 +236,7 @@ fun MatchItem(
236236
MarkdownText(
237237
markdown = favListItem.description,
238238
linkColor = MaterialTheme.colorScheme.primary,
239+
disableLinkMovementMethod = true,
239240
)
240241
}
241242
}

0 commit comments

Comments
 (0)