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) {
|
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 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)
|
->setMaxResults(1)
|
||||||
->setParameters([
|
->setParameters([
|
||||||
'score' => $hit->getScore(),
|
'score' => $hit->getScore(),
|
||||||
'target' => $hit->getTarget(),
|
'targets' => $this->getTargetSetForTarget($hit->getTarget()),
|
||||||
]);
|
]);
|
||||||
$betterHit = $query->getOneOrNullResult();
|
$betterHit = $query->getOneOrNullResult();
|
||||||
|
|
||||||
|
@ -34,8 +34,9 @@ class HitRepository extends EntityRepository
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function getClosestHitWithImage(string $emotionField, float $score) {
|
public function getClosestHitWithImage(string $emotionField, float $score) {
|
||||||
if(!in_array($emotionField, Emotions::$EMOTIONS))
|
if (!in_array($emotionField, Emotions::$EMOTIONS)) {
|
||||||
throw new \Exception("Invalid emotion!");
|
throw new \Exception("Invalid emotion!");
|
||||||
|
}
|
||||||
|
|
||||||
$query = $this->_em->createQuery(
|
$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 "
|
"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);
|
->setMaxResults(1);
|
||||||
return $query->getSingleResult();
|
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 */
|
/* @var $currentHit \EmotionHero\Models\Hit */
|
||||||
$currentHit = $hitRepo->findOneBy(['hasImage'=>true], ['id'=>'DESC']);
|
$currentHit = $hitRepo->findOneBy(['hasImage'=>true], ['id'=>'DESC']);
|
||||||
|
$targetSet = $hitRepo->getTargetSetForTarget($currentHit->getTarget());
|
||||||
$betterHit = $hitRepo->getBetterHit($currentHit);
|
$betterHit = $hitRepo->getBetterHit($currentHit);
|
||||||
|
|
||||||
$printEmoBlocks = function($emotion, $feature, $steps = 6) use($em) {
|
$printEmoBlocks = function($emotion, $feature, $steps = 6) use($em) {
|
||||||
|
@ -274,7 +275,7 @@ ul{
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<body <?php if(isSet($_GET['presentation'])){echo "class='presentation'";}?>>
|
<body class='presentation'>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "<div class='brows emo'><h3><span>eye brows</span></h3>";
|
echo "<div class='brows emo'><h3><span>eye brows</span></h3>";
|
||||||
|
@ -330,12 +331,23 @@ echo "</div>"; // .mouth
|
||||||
echo "<div class='currentHit'>";
|
echo "<div class='currentHit'>";
|
||||||
echo "<h3><span class='last'>last</span><span class='vs'>vs</span><span class='perfect'>perfect</span></h3>";
|
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>".\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>";
|
echo "<ul>";
|
||||||
$expressions = array_keys($currentHit->getExpressions()::$EXPRESSIONS_2ND_PERSON);
|
$expressions = array_keys($currentHit->getExpressions()::$EXPRESSIONS_2ND_PERSON);
|
||||||
sort($expressions);
|
sort($expressions);
|
||||||
foreach ($expressions as $expression) {
|
foreach ($expressions as $expression) {
|
||||||
$currentScore = $currentHit->getExpressions()->getExpressionScore($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);
|
$betterScore = $betterHit->getExpressions()->getExpressionScore($expression);
|
||||||
$diff = $betterScore - $currentScore;
|
$diff = $betterScore - $currentScore;
|
||||||
if ($diff > 0) {
|
if ($diff > 0) {
|
||||||
|
@ -343,15 +355,16 @@ if($diff > 0) {
|
||||||
} elseif ($diff < 0) {
|
} elseif ($diff < 0) {
|
||||||
$diffclass = "negative";
|
$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 "<span class='diff $diffclass'>". sprintf("%+.5f", $diff)." %</span>";
|
||||||
|
}
|
||||||
|
|
||||||
echo "</li>";
|
echo "</li>";
|
||||||
}
|
}
|
||||||
echo "</ul>";
|
echo "</ul>";
|
||||||
|
|
||||||
$circles = "";
|
$circles = "";
|
||||||
|
|
||||||
|
if(!empty($betterHit)) {
|
||||||
foreach($betterHit->getPoints()->getNormalisedPoints() as $i => $point) {
|
foreach($betterHit->getPoints()->getNormalisedPoints() as $i => $point) {
|
||||||
/* $circles .= '<circle
|
/* $circles .= '<circle
|
||||||
style="fill:gray;"
|
style="fill:gray;"
|
||||||
|
@ -366,6 +379,7 @@ foreach($betterHit->getPoints()->getNormalisedPoints() as $i => $point) {
|
||||||
y="'.$point->getY().'"
|
y="'.$point->getY().'"
|
||||||
r="0.7">'.$i.'</text>';
|
r="0.7">'.$i.'</text>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach($currentHit->getPoints()->getNormalisedPoints() as $i => $point) {
|
foreach($currentHit->getPoints()->getNormalisedPoints() as $i => $point) {
|
||||||
$circles .= '<text
|
$circles .= '<text
|
||||||
|
|
Loading…
Reference in a new issue