From 8380f40638603d96cc38882dc3d23a73b4ab9f6e Mon Sep 17 00:00:00 2001 From: Ruben Date: Wed, 21 Sep 2016 23:43:20 +0100 Subject: [PATCH] Better matching algo --- src/Models/HitRepository.php | 8 ++++---- www/faces3.php | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Models/HitRepository.php b/src/Models/HitRepository.php index afbf925..96b9188 100644 --- a/src/Models/HitRepository.php +++ b/src/Models/HitRepository.php @@ -14,11 +14,11 @@ class HitRepository extends EntityRepository public function getBetterHit(Hit $hit) { // we want only the slightly better hit... $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) ->setParameters([ - 'score' => $hit->getScore(), + 'score' => $this->getTotalScoreForHit($hit), 'targets' => $this->getTargetSetForTarget($hit->getTarget()), ]); $betterHit = $query->getOneOrNullResult(); @@ -70,11 +70,11 @@ class HitRepository extends EntityRepository /** * Get the total score of the TargetSet to which this hit belongs * @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) { $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)" ) ->setParameters([ diff --git a/www/faces3.php b/www/faces3.php index b8b8363..27950fd 100644 --- a/www/faces3.php +++ b/www/faces3.php @@ -333,9 +333,12 @@ echo "

lastvs