[mob][photos] Get unique random numbers + write method to get mathcing fileIDs from promptData
This commit is contained in:
parent
d132353291
commit
6bd34014fb
1 changed files with 21 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'dart:math';
|
||||
|
||||
import "package:logging/logging.dart";
|
||||
import "package:photos/services/machine_learning/semantic_search/semantic_search_service.dart";
|
||||
import "package:shared_preferences/shared_preferences.dart";
|
||||
|
||||
const _promptsJson = {
|
||||
|
@ -48,7 +49,8 @@ class MagicCacheService {
|
|||
List<Map<String, Object>> getRandomPrompts() {
|
||||
final promptsJson = _promptsJson["prompts"];
|
||||
final randomPrompts = <Map<String, Object>>[];
|
||||
final randomNumbers = _generateRandomNumbers(promptsJson!.length - 1, 4);
|
||||
final randomNumbers =
|
||||
_generateUniqueRandomNumbers(promptsJson!.length - 1, 4);
|
||||
for (int i = 0; i < randomNumbers.length; i++) {
|
||||
randomPrompts.add(promptsJson[randomNumbers[i]]);
|
||||
}
|
||||
|
@ -56,10 +58,25 @@ class MagicCacheService {
|
|||
return randomPrompts;
|
||||
}
|
||||
|
||||
List<int> _generateRandomNumbers(int max, int count) {
|
||||
Future<List<int>> getMatchingFileIDsForPromptData(
|
||||
Map<String, Object> promptData,
|
||||
) {
|
||||
return SemanticSearchService.instance.getMatchingFileIDs(
|
||||
promptData["prompt"] as String,
|
||||
promptData["minimumScore"] as double,
|
||||
);
|
||||
}
|
||||
|
||||
///Generates from 0 to max unique random numbers
|
||||
List<int> _generateUniqueRandomNumbers(int max, int count) {
|
||||
final numbers = <int>[];
|
||||
for (int i = 1; i <= count; i++) {
|
||||
numbers.add(Random().nextInt(max + 1));
|
||||
for (int i = 1; i <= count;) {
|
||||
final randomNumber = Random().nextInt(max + 1);
|
||||
if (numbers.contains(randomNumber)) {
|
||||
continue;
|
||||
}
|
||||
numbers.add(randomNumber);
|
||||
i++;
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue