2023-03-04 12:19:01 +00:00
|
|
|
package nu.marginalia.dating;
|
2022-05-19 15:45:26 +00:00
|
|
|
|
2023-03-04 12:19:01 +00:00
|
|
|
import nu.marginalia.browse.DbBrowseDomainsRandom;
|
|
|
|
import nu.marginalia.browse.DbBrowseDomainsSimilarCosine;
|
|
|
|
import nu.marginalia.browse.model.BrowseResult;
|
2023-03-25 14:26:17 +00:00
|
|
|
import nu.marginalia.db.DomainBlacklist;
|
2022-05-19 15:45:26 +00:00
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
|
|
public class DatingSessionObject {
|
|
|
|
public final LinkedList<BrowseResult> queue = new LinkedList<>();
|
|
|
|
public final LinkedList<BrowseResult> recentlyViewed = new LinkedList<>();
|
|
|
|
private BrowseResult current;
|
|
|
|
|
|
|
|
private static final int MAX_HISTORY_SIZE = 100;
|
|
|
|
private static final int MAX_QUEUE_SIZE = 100;
|
|
|
|
|
|
|
|
public BrowseResult setCurrent(BrowseResult result) {
|
|
|
|
current = result;
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
2023-03-11 12:48:40 +00:00
|
|
|
public BrowseResult next(DbBrowseDomainsRandom random, DomainBlacklist blacklist) {
|
2022-05-19 15:45:26 +00:00
|
|
|
if (queue.isEmpty()) {
|
2023-03-04 12:19:01 +00:00
|
|
|
random.getRandomDomains(25, blacklist, 0).forEach(queue::addLast);
|
2022-05-19 15:45:26 +00:00
|
|
|
}
|
|
|
|
return queue.pollFirst();
|
|
|
|
}
|
|
|
|
|
2023-08-24 15:46:02 +00:00
|
|
|
public BrowseResult nextSimilar(int domainId, DbBrowseDomainsSimilarCosine adjacent, DomainBlacklist blacklist) {
|
2023-12-04 21:10:24 +00:00
|
|
|
adjacent.getDomainNeighborsAdjacentCosineRequireScreenshot(domainId, blacklist, 25).forEach(queue::addFirst);
|
2022-05-19 15:45:26 +00:00
|
|
|
|
|
|
|
while (queue.size() > MAX_QUEUE_SIZE) {
|
|
|
|
queue.removeLast();
|
|
|
|
}
|
|
|
|
|
|
|
|
return queue.pollFirst();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void browseForward(BrowseResult res) {
|
|
|
|
if (current != null) {
|
|
|
|
addToHistory(current);
|
|
|
|
}
|
|
|
|
setCurrent(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void browseBackward(BrowseResult res) {
|
|
|
|
if (current != null) {
|
|
|
|
addToQueue(current);
|
|
|
|
}
|
|
|
|
setCurrent(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BrowseResult addToHistory(BrowseResult res) {
|
|
|
|
recentlyViewed.addFirst(res);
|
|
|
|
while (recentlyViewed.size() > MAX_HISTORY_SIZE) {
|
|
|
|
recentlyViewed.removeLast();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BrowseResult addToQueue(BrowseResult res) {
|
|
|
|
queue.addFirst(res);
|
|
|
|
while (queue.size() > MAX_QUEUE_SIZE) {
|
|
|
|
queue.removeLast();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BrowseResult takeFromHistory() {
|
|
|
|
return recentlyViewed.pollFirst();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasHistory() {
|
|
|
|
return !recentlyViewed.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRecent(BrowseResult res) {
|
|
|
|
return recentlyViewed.contains(res) || res.equals(current);
|
|
|
|
}
|
|
|
|
public void resetQueue() {
|
|
|
|
queue.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public BrowseResult getCurrent() {
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
}
|