renamed the random int generator function
All checks were successful
default-pipeline default-pipeline #170
All checks were successful
default-pipeline default-pipeline #170
This commit is contained in:
parent
8136273b33
commit
fb7c0e7a5c
@ -60,11 +60,11 @@ class PlaceRepository
|
|||||||
return $places;
|
return $places;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRandomForMapWithValidPano($numberOfPlaces, $select, array &$exclude, $randomSelection = null): ?Place
|
private function getRandomForMapWithValidPano($numberOfPlaces, $select, array &$exclude, $pickRandomInt = null): ?Place
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
$numberOfPlacesLeft = $numberOfPlaces - count($exclude);
|
$numberOfPlacesLeft = $numberOfPlaces - count($exclude);
|
||||||
$place = $this->selectRandomFromDbForMap($numberOfPlacesLeft, $select, $exclude, $randomSelection);
|
$place = $this->selectRandomFromDbForMap($numberOfPlacesLeft, $select, $exclude, $pickRandomInt);
|
||||||
if($place === null) {
|
if($place === null) {
|
||||||
// there is no more never visited place left
|
// there is no more never visited place left
|
||||||
return null;
|
return null;
|
||||||
@ -79,15 +79,15 @@ class PlaceRepository
|
|||||||
return $place;
|
return $place;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function selectRandomFromDbForMap($numberOfPlacesLeft, $select, array $exclude, $randomSelection): ?Place
|
private function selectRandomFromDbForMap($numberOfPlacesLeft, $select, array $exclude, $pickRandomInt): ?Place
|
||||||
{
|
{
|
||||||
if($numberOfPlacesLeft <= 0)
|
if($numberOfPlacesLeft <= 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if(!isset($randomSelection)) {
|
if(!isset($pickRandomInt)) {
|
||||||
$randomOffset = random_int(0, $numberOfPlacesLeft - 1);
|
$randomOffset = random_int(0, $numberOfPlacesLeft - 1);
|
||||||
} else {
|
} else {
|
||||||
$randomOffset = $randomSelection($numberOfPlacesLeft);
|
$randomOffset = $pickRandomInt($numberOfPlacesLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $select_unvisited->orderBy('last_time');
|
// $select_unvisited->orderBy('last_time');
|
||||||
@ -150,7 +150,7 @@ class PlaceRepository
|
|||||||
$selectOldPlaces->orderBy('last_time');
|
$selectOldPlaces->orderBy('last_time');
|
||||||
|
|
||||||
// selection algorithm with preference (weighting) for older places
|
// selection algorithm with preference (weighting) for older places
|
||||||
$gaussianRandomSelection = function($numberOfPlaces) {
|
$pickGaussianRandomInt = function($numberOfPlaces) {
|
||||||
$stdev = 0.2;
|
$stdev = 0.2;
|
||||||
$avg = 0.0;
|
$avg = 0.0;
|
||||||
$x = mt_rand() / mt_getrandmax();
|
$x = mt_rand() / mt_getrandmax();
|
||||||
@ -162,7 +162,7 @@ class PlaceRepository
|
|||||||
// look for n - numberOfUnvisitedPlaces places
|
// look for n - numberOfUnvisitedPlaces places
|
||||||
while(count($places) < $n)
|
while(count($places) < $n)
|
||||||
{
|
{
|
||||||
$place = $this->getRandomForMapWithValidPano($numberOfOldPlaces, $selectOldPlaces, $exclude, $gaussianRandomSelection);
|
$place = $this->getRandomForMapWithValidPano($numberOfOldPlaces, $selectOldPlaces, $exclude, $pickGaussianRandomInt);
|
||||||
if(isset($place))
|
if(isset($place))
|
||||||
{
|
{
|
||||||
$places[] = $place;
|
$places[] = $place;
|
||||||
@ -173,5 +173,4 @@ class PlaceRepository
|
|||||||
return $places;
|
return $places;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user