Skip to content
Permalink
Browse files

optimized and fixes recommendation count calculations

  • Loading branch information...
following5 committed Oct 6, 2017
1 parent 6074553 commit aa1a1fa4762657bfca824a01d4239c20616e8397
@@ -87,9 +87,9 @@
// fill_gaps = false: continue with the last waypoint
$opt['logic']['waypoint_pool']['fill_gaps'] = false;
/* geocache recommendation settings
/* number of finds needed to give one recommendation
*/
$opt['logic']['rating']['percentageOfFounds'] = 10;
$opt['logic']['rating']['findsPerRating'] = 10;
/* admin functions
*/
@@ -367,11 +367,12 @@
$tpl->assign('showstatfounds', $user->showStatFounds());
// recommendation-related data
$tpl->assign('ratingallowed', $user->allowRatings());
$tpl->assign('givenratings', $user->getGivenRatings());
$tpl->assign('maxratings', $user->getMaxRatings());
$ratingParams = $user->getRatingParameters();
$tpl->assign('ratingallowed', $ratingParams['givenRatings'] < $ratingParams['maxRatings']);
$tpl->assign('givenratings', $ratingParams['givenRatings']);
$tpl->assign('maxratings', $ratingParams['maxRatings']);
$tpl->assign('israted', $cache->isRecommendedByUser($user->getUserId()) || isset($_REQUEST['rating']));
$tpl->assign('foundsuntilnextrating', $user->foundsUntilNextRating());
$tpl->assign('findsuntilnextrating', $ratingParams['findsUntilNextRating']);
$tpl->assign('isowner', $user->getUserId() == $cache->getUserId());
// password
@@ -1586,26 +1586,25 @@ public function getGivenRatings()
);
}
public function getMaxRatings()
public function getRatingParameters()
{
global $opt;
// get number of possible rates
return (int) floor($this->getStatFound() * $opt['logic']['rating']['percentageOfFounds'] / 100);
}
$findsPerRating = $opt['logic']['rating']['findsPerRating'];
$finds = $this->getStatFound();
$ratings = $this->getGivenRatings();
public function allowRatings()
{
// new ratings allowed, if "given ratings" < "max ratings"
return ($this->getGivenRatings() < $this->getMaxRatings());
return [
'maxRatings' => floor($finds / $findsPerRating),
'givenRatings' => $ratings,
'findsUntilNextRating' => ($ratings + 1) * $findsPerRating - $finds,
];
}
public function foundsUntilNextRating()
public function allowRatings()
{
global $opt;
$rating = $opt['logic']['rating'];
return (int) ($rating['percentageOfFounds'] - ($this->getStatFound() % $rating['percentageOfFounds']));
$ratingParams = $this->getRatingParameters();
return $ratingParams['givenRatings'] < $ratingParams['maxRatings'];
}
public function showStatFounds()
@@ -70,11 +70,12 @@
$isOwner = ($user->getUserId() == $cache->getUserId());
// assing ratings to template
$tpl->assign('ratingallowed', $user->allowRatings());
$tpl->assign('givenratings', $user->getGivenRatings());
$tpl->assign('maxratings', $user->getMaxRatings());
$ratingParams = $user->getRatingParameters();
$tpl->assign('ratingallowed', $ratingParams['givenRatings'] < $ratingParams['maxRatings']);
$tpl->assign('givenratings', $ratingParams['givenRatings']);
$tpl->assign('maxratings', $ratingParams['maxRatings']);
$tpl->assign('israted', $cache->isRecommendedByUser($user->getUserId()) || isset($_REQUEST['rating']));
$tpl->assign('foundsuntilnextrating', $user->foundsUntilNextRating());
$tpl->assign('findsuntilnextrating', $ratingParams['findsUntilNextRating']);
$tpl->assign('isowner', $isOwner);
// check and prepare form values
@@ -307,7 +307,7 @@ function show_tip(text)
{if ($ratingallowed==true || $israted==true)}<input type="hidden" name="ratingoption" value="1"><input type="checkbox" id="rating" name="rating" value="1" class="checkbox" {if $israted==true}checked{/if}/>&nbsp;<label for="rating" id="ratinglabel" >{t}This cache is one of my recommendations.{/t}</label><br />
{t 1=$givenratings 2=$maxratings}You have given %1 of %2 possible recommendations.{/t}
{else}
{t 1=$foundsuntilnextrating}You need additional %1 finds, to make another recommendation.{/t}
{t 1=$findsuntilnextrating}You need additional %1 finds, to make another recommendation.{/t}
{if ($givenratings > 0 && $givenratings==$maxratings && $israted==false)}<br />{t}Alternatively, you can withdraw a <a href="mytop5.php">existing recommendation</a>.{/t}{/if}
{/if}
<noscript><br />{t}A recommendation can only be made with a "found" or "attended" log!{/t}</noscript>
@@ -359,6 +359,8 @@
$tpl->title = $menu->GetMenuTitle() . ' ' . $record['username'];
$user = new user($userid);
$ratingParams = $user->getRatingParameters();
$tpl->assign('username', $record['username']);
$tpl->assign('userid', $userid);
@@ -369,17 +371,15 @@
$tpl->assign('maintenance', $record['maintenance'] <= 0 ? '0' : $record['maintenance']);
$tpl->assign('hidden', $record['hidden'] <= 0 ? '0' : $record['hidden']);
$tpl->assign('active', $active);
$tpl->assign('recommended', sql_value("SELECT COUNT(*) FROM `cache_rating` WHERE `user_id`='&1'", 0, $userid));
$tpl->assign('maxrecommended', (int) floor($record['found'] * $opt['logic']['rating']['percentageOfFounds'] / 100));
$tpl->assign('recommended', $ratingParams['givenRatings']);
$tpl->assign('maxrecommended', $ratingParams['maxRatings']);
$tpl->assign('show_statistics', $show_statistics);
$tpl->assign('show_oconly81', $show_oconly81);
$tpl->assign('oconly_hidden', $oconly_hidden);
$tpl->assign('oconly_hidden_active', $oconly_hidden_active);
$tpl->assign('oconly_recommended', $oconly_recommended);
$user = new user($userid);
$picstat = ($useropt->getOptValue(USR_OPT_PICSTAT) == 1) && !$user->getLicenseDeclined();
$tpl->assign('show_picstat', $picstat);
if ($picstat) {

0 comments on commit aa1a1fa

Please sign in to comment.
You can’t perform that action at this time.