diff --git a/src/Models/HitRepository.php b/src/Models/HitRepository.php index 5196fc0..afbf925 100644 --- a/src/Models/HitRepository.php +++ b/src/Models/HitRepository.php @@ -14,12 +14,12 @@ class HitRepository extends EntityRepository public function getBetterHit(Hit $hit) { // we want only the slightly better hit... $query = $this->_em->createQuery( - "SELECT h FROM ".Hit::class." h WHERE h.target = :target AND h.score > :score ORDER BY h.score DESC" + "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" ) ->setMaxResults(1) ->setParameters([ 'score' => $hit->getScore(), - 'target' => $hit->getTarget(), + 'targets' => $this->getTargetSetForTarget($hit->getTarget()), ]); $betterHit = $query->getOneOrNullResult(); @@ -34,9 +34,10 @@ class HitRepository extends EntityRepository * @throws \Exception */ public function getClosestHitWithImage(string $emotionField, float $score) { - if(!in_array($emotionField, Emotions::$EMOTIONS)) + if (!in_array($emotionField, Emotions::$EMOTIONS)) { throw new \Exception("Invalid emotion!"); - + } + $query = $this->_em->createQuery( "SELECT h, ABS(:score - h.emotions.$emotionField) as HIDDEN distance FROM ".Hit::class." h WHERE h.hasImage = :has ORDER BY distance ASC " ) @@ -47,4 +48,39 @@ class HitRepository extends EntityRepository ->setMaxResults(1); return $query->getSingleResult(); } + + /** + * Get targets of the same level at the same time (targetset) + * TODO: move to TargetRepository + * @param Target $target [description] + * @return ArrayCollection|null The result or nul if no results + */ + public function getTargetSetForTarget(Target $target) { + return $this->_em->createQuery( + "SELECT t FROM ".Target::class." t WHERE t.level = :level AND t.time = :time" + ) + ->setParameters([ + 'level' => $target->getLevel(), + 'time' => $target->getTime() + ]) + ->getResult(); + + } + + /** + * Get the total score of the TargetSet to which this hit belongs + * @param \EmotionHero\Models\Hit $hit + * @return float + */ + public function getTotalScoreForHit(Hit $hit) { + $targets = $this->getTargetSetForTarget($hit->getTarget()); + return (float) $this->_em->createQuery( + "SELECT SUM(h.score) FROM ".Hit::class." h WHERE h.game = :game AND h.target IN (:targets)" + ) + ->setParameters([ + 'game' => $hit->getGame(), + 'targets' => $targets + ]) + ->getSingleScalarResult(); + } } \ No newline at end of file diff --git a/www/faces3.php b/www/faces3.php index 67a4428..b8b8363 100644 --- a/www/faces3.php +++ b/www/faces3.php @@ -8,6 +8,7 @@ $hitRepo = $em->getRepository(\EmotionHero\Models\Hit::class); /* @var $currentHit \EmotionHero\Models\Hit */ $currentHit = $hitRepo->findOneBy(['hasImage'=>true], ['id'=>'DESC']); +$targetSet = $hitRepo->getTargetSetForTarget($currentHit->getTarget()); $betterHit = $hitRepo->getBetterHit($currentHit); $printEmoBlocks = function($emotion, $feature, $steps = 6) use($em) { @@ -274,7 +275,7 @@ ul{ } - > +

eye brows

"; @@ -330,41 +331,54 @@ echo ""; // .mouth echo "
"; echo "

lastvsperfect

"; // echo "

".\PrettyDateTime\PrettyDateTime::parse($currentHit->getGame()->getOriginalGameAt())."

"; -echo "

aim: {$currentHit->getTarget()->getScore()}% ".$currentHit->getTarget()->getEmotion()->getName()."

"; +echo "

aim:"; +foreach($targetSet as $target) { + " {$target->getScore()}% {$target->getEmotion()->getName()}"; +} +echo "

"; +//echo "

aim: {$currentHit->getTarget()->getScore()}% ".$currentHit->getTarget()->getEmotion()->getName()."

"; echo ""; $circles = ""; -foreach($betterHit->getPoints()->getNormalisedPoints() as $i => $point) { -/* $circles .= '';*/ - $circles .= ''.$i.''; + +if(!empty($betterHit)) { + foreach($betterHit->getPoints()->getNormalisedPoints() as $i => $point) { + /* $circles .= '';*/ + $circles .= ''.$i.''; + } } foreach($currentHit->getPoints()->getNormalisedPoints() as $i => $point) {