Better faces
This commit is contained in:
parent
9f040a4785
commit
6a31f650be
2 changed files with 83 additions and 33 deletions
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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{
|
|||
}
|
||||
|
||||
</style>
|
||||
<body <?php if(isSet($_GET['presentation'])){echo "class='presentation'";}?>>
|
||||
<body class='presentation'>
|
||||
<?php
|
||||
|
||||
echo "<div class='brows emo'><h3><span>eye brows</span></h3>";
|
||||
|
@ -330,41 +331,54 @@ echo "</div>"; // .mouth
|
|||
echo "<div class='currentHit'>";
|
||||
echo "<h3><span class='last'>last</span><span class='vs'>vs</span><span class='perfect'>perfect</span></h3>";
|
||||
// echo "<p>".\PrettyDateTime\PrettyDateTime::parse($currentHit->getGame()->getOriginalGameAt())."</p>";
|
||||
echo "<p>aim: {$currentHit->getTarget()->getScore()}% ".$currentHit->getTarget()->getEmotion()->getName()."</p>";
|
||||
echo "<p>aim:";
|
||||
foreach($targetSet as $target) {
|
||||
" {$target->getScore()}% {$target->getEmotion()->getName()}";
|
||||
}
|
||||
echo "</p>";
|
||||
//echo "<p>aim: {$currentHit->getTarget()->getScore()}% ".$currentHit->getTarget()->getEmotion()->getName()."</p>";
|
||||
echo "<ul>";
|
||||
$expressions = array_keys($currentHit->getExpressions()::$EXPRESSIONS_2ND_PERSON);
|
||||
sort($expressions);
|
||||
foreach($expressions as $expression) {
|
||||
$currentScore = $currentHit->getExpressions()->getExpressionScore($expression);
|
||||
$betterScore = $betterHit->getExpressions()->getExpressionScore($expression);
|
||||
$diff = $betterScore - $currentScore;
|
||||
if($diff > 0) {
|
||||
$diffclass = "positive";
|
||||
}elseif($diff < 0) {
|
||||
$diffclass = "negative";
|
||||
}
|
||||
echo "<li>";
|
||||
echo "<span class='name'>$expression</span>";
|
||||
echo "<span class='value'>". sprintf("%.5f", $currentScore)." %</span>";
|
||||
echo "<span class='diff $diffclass'>". sprintf("%+.5f", $diff)." %</span>";
|
||||
echo "</li>";
|
||||
foreach ($expressions as $expression) {
|
||||
$currentScore = $currentHit->getExpressions()->getExpressionScore($expression);
|
||||
echo "<li>";
|
||||
echo "<span class='name'>$expression</span>";
|
||||
echo "<span class='value'>". sprintf("%.5f", $currentScore)." %</span>";
|
||||
|
||||
|
||||
if(!empty($betterHit)) {
|
||||
$betterScore = $betterHit->getExpressions()->getExpressionScore($expression);
|
||||
$diff = $betterScore - $currentScore;
|
||||
if ($diff > 0) {
|
||||
$diffclass = "positive";
|
||||
} elseif ($diff < 0) {
|
||||
$diffclass = "negative";
|
||||
}
|
||||
echo "<span class='diff $diffclass'>". sprintf("%+.5f", $diff)." %</span>";
|
||||
}
|
||||
|
||||
echo "</li>";
|
||||
}
|
||||
echo "</ul>";
|
||||
|
||||
$circles = "";
|
||||
foreach($betterHit->getPoints()->getNormalisedPoints() as $i => $point) {
|
||||
/* $circles .= '<circle
|
||||
style="fill:gray;"
|
||||
id="point'.$i.'"
|
||||
cx="'.$point->getX().'"
|
||||
cy="'.$point->getY().'"
|
||||
r="0.7" />';*/
|
||||
$circles .= '<text
|
||||
style="fill:green;font-size:4"
|
||||
id="point'.$i.'"
|
||||
x="'.$point->getX().'"
|
||||
y="'.$point->getY().'"
|
||||
r="0.7">'.$i.'</text>';
|
||||
|
||||
if(!empty($betterHit)) {
|
||||
foreach($betterHit->getPoints()->getNormalisedPoints() as $i => $point) {
|
||||
/* $circles .= '<circle
|
||||
style="fill:gray;"
|
||||
id="point'.$i.'"
|
||||
cx="'.$point->getX().'"
|
||||
cy="'.$point->getY().'"
|
||||
r="0.7" />';*/
|
||||
$circles .= '<text
|
||||
style="fill:green;font-size:4"
|
||||
id="point'.$i.'"
|
||||
x="'.$point->getX().'"
|
||||
y="'.$point->getY().'"
|
||||
r="0.7">'.$i.'</text>';
|
||||
}
|
||||
}
|
||||
|
||||
foreach($currentHit->getPoints()->getNormalisedPoints() as $i => $point) {
|
||||
|
|
Loading…
Reference in a new issue