Better matching algo
This commit is contained in:
parent
6a31f650be
commit
8380f40638
2 changed files with 8 additions and 5 deletions
|
@ -14,11 +14,11 @@ class HitRepository extends EntityRepository
|
||||||
public function getBetterHit(Hit $hit) {
|
public function getBetterHit(Hit $hit) {
|
||||||
// we want only the slightly better hit...
|
// we want only the slightly better hit...
|
||||||
$query = $this->_em->createQuery(
|
$query = $this->_em->createQuery(
|
||||||
"SELECT h, SUM(h.score) as HIDDEN totalScore FROM ".Hit::class." h WHERE h.target IN (:targets) AND totalScore > :score GROUP BY h.game ORDER BY totalScore DESC"
|
"SELECT h, SUM(h.score) as HIDDEN totalScore FROM ".Hit::class." h WHERE h.target IN (:targets) GROUP BY h.game HAVING totalScore > :score ORDER BY totalScore DESC"
|
||||||
)
|
)
|
||||||
->setMaxResults(1)
|
->setMaxResults(1)
|
||||||
->setParameters([
|
->setParameters([
|
||||||
'score' => $hit->getScore(),
|
'score' => $this->getTotalScoreForHit($hit),
|
||||||
'targets' => $this->getTargetSetForTarget($hit->getTarget()),
|
'targets' => $this->getTargetSetForTarget($hit->getTarget()),
|
||||||
]);
|
]);
|
||||||
$betterHit = $query->getOneOrNullResult();
|
$betterHit = $query->getOneOrNullResult();
|
||||||
|
@ -70,11 +70,11 @@ class HitRepository extends EntityRepository
|
||||||
/**
|
/**
|
||||||
* Get the total score of the TargetSet to which this hit belongs
|
* Get the total score of the TargetSet to which this hit belongs
|
||||||
* @param \EmotionHero\Models\Hit $hit
|
* @param \EmotionHero\Models\Hit $hit
|
||||||
* @return float
|
* @return string (return float as string, so it can be fed back to mysql without floating point issues)
|
||||||
*/
|
*/
|
||||||
public function getTotalScoreForHit(Hit $hit) {
|
public function getTotalScoreForHit(Hit $hit) {
|
||||||
$targets = $this->getTargetSetForTarget($hit->getTarget());
|
$targets = $this->getTargetSetForTarget($hit->getTarget());
|
||||||
return (float) $this->_em->createQuery(
|
return $this->_em->createQuery(
|
||||||
"SELECT SUM(h.score) FROM ".Hit::class." h WHERE h.game = :game AND h.target IN (:targets)"
|
"SELECT SUM(h.score) FROM ".Hit::class." h WHERE h.game = :game AND h.target IN (:targets)"
|
||||||
)
|
)
|
||||||
->setParameters([
|
->setParameters([
|
||||||
|
|
|
@ -333,9 +333,12 @@ echo "<h3><span class='last'>last</span><span class='vs'>vs</span><span class='p
|
||||||
// echo "<p>".\PrettyDateTime\PrettyDateTime::parse($currentHit->getGame()->getOriginalGameAt())."</p>";
|
// echo "<p>".\PrettyDateTime\PrettyDateTime::parse($currentHit->getGame()->getOriginalGameAt())."</p>";
|
||||||
echo "<p>aim:";
|
echo "<p>aim:";
|
||||||
foreach($targetSet as $target) {
|
foreach($targetSet as $target) {
|
||||||
" {$target->getScore()}% {$target->getEmotion()->getName()}";
|
echo " {$target->getScore()}% {$target->getEmotion()->getName()}";
|
||||||
}
|
}
|
||||||
echo "</p>";
|
echo "</p>";
|
||||||
|
if(empty($betterHit)) {
|
||||||
|
echo "<p>Best attempt so far</p>";
|
||||||
|
}
|
||||||
//echo "<p>aim: {$currentHit->getTarget()->getScore()}% ".$currentHit->getTarget()->getEmotion()->getName()."</p>";
|
//echo "<p>aim: {$currentHit->getTarget()->getScore()}% ".$currentHit->getTarget()->getEmotion()->getName()."</p>";
|
||||||
echo "<ul>";
|
echo "<ul>";
|
||||||
$expressions = array_keys($currentHit->getExpressions()::$EXPRESSIONS_2ND_PERSON);
|
$expressions = array_keys($currentHit->getExpressions()::$EXPRESSIONS_2ND_PERSON);
|
||||||
|
|
Loading…
Reference in a new issue