api.emotionhero.com/www/faces3.php

446 lines
10 KiB
PHP
Raw Normal View History

2016-09-19 01:50:50 +02:00
<?php
require __DIR__ . '/../bootstrap.php';
error_reporting(E_ALL);ini_set('display_errors', true);
$em = \EmotionHero\Application::getInstance()->getEm();
/* @var $hitRepo EmotionHero\Models\HitRepository */
$hitRepo = $em->getRepository(\EmotionHero\Models\Hit::class);
/* @var $currentHit \EmotionHero\Models\Hit */
$currentHit = $hitRepo->findOneBy(['hasImage'=>true], ['id'=>'DESC']);
2016-09-22 00:17:26 +02:00
$targetSet = $hitRepo->getTargetSetForTarget($currentHit->getTarget());
2016-09-19 01:50:50 +02:00
$betterHit = $hitRepo->getBetterHit($currentHit);
$printEmoBlocks = function($emotion, $feature, $steps = 6) use($em) {
foreach(range(0, 100, 100/($steps-1)) as $i) {
/* @var $hitRepo EmotionHero\Models\HitRepository */
$hitRepo = $em->getRepository(EmotionHero\Models\Hit::class);
2016-09-19 18:25:59 +02:00
// if($feature == 'nose'){
// $items = [992, 1035, 701, 888, 671, 906, 693, 725, 762, 666, 751,992,728];
// $hit = $hitRepo->find($items[array_rand($items)]);
// } elseif($feature == 'mouth_left') {
// $items = [992, 1035, 1034, 888];
// $hit = $hitRepo->find($items[array_rand($items)]);
// } else{
2016-09-19 01:50:50 +02:00
$hit = $hitRepo->getClosestHitWithImage($emotion, $i);
2016-09-19 18:25:59 +02:00
// }
2016-09-19 01:50:50 +02:00
$img = $hit->getFeatureImgAsString($feature);
$score = $hit->getEmotions()->getEmotionScore($emotion);
$percentage = sprintf("%.0f %%",$score);
echo <<< EOSNIPPET
<div class="block">
<img src="data:image/x-icon;base64,$img" title="{$hit->getId()}">
<span class="perc">$percentage</span>
</div>
EOSNIPPET;
}
};
?>
<html>
<head>
<title>Emotion Hero</title>
</head>
<style type="text/css">
2016-09-20 13:00:40 +02:00
html{
height:100%;
overflow:hidden;
}
body{
background:blue;
font-family:"Unifont";
font-weight:bold;
font-size:1vw;
margin:0.5em;
2016-09-20 13:00:40 +02:00
font-family: sans-serif;
}
body.presentation{
background:black;
}
2016-09-19 01:50:50 +02:00
h3{
margin:0.5%;
text-align:center;
2016-09-20 13:00:40 +02:00
/*! background: white; */
/*! color: black; */
2016-09-19 01:50:50 +02:00
}
h3 span{
2016-09-20 13:00:40 +02:00
background:none;
color:white;
padding:0.2%;
2016-09-20 13:00:40 +02:00
/*! border-bottom: solid 0.2em white; */
2016-09-19 01:50:50 +02:00
}
.block{
width:100%;
font-size:80%;
}
2016-09-19 01:50:50 +02:00
.mouth .emo-block{
width:50%;
float:left;
height:5em;
2016-09-19 01:50:50 +02:00
}
.mouth .emotitle{
display:block;
width:14%;
margin-right:0.14%;
margin-left:0.14%;
2016-09-19 01:50:50 +02:00
float:left;
font-size:80%;
2016-09-20 13:00:40 +02:00
padding-top:2.5%;
2016-09-19 01:50:50 +02:00
}
.mouth .block {
width:14%;
margin-right:0.14%;
margin-left:0.14%;
float:left;
2016-09-19 01:50:50 +02:00
}
/*.emotitle span:before{content:"";}
.emotitle span:after{content:"";}*/
2016-09-20 13:00:40 +02:00
.emotitle{/*! font-style:italic; *//*! display: none; */}
2016-09-20 13:01:12 +02:00
.emotitle:before{content:"«";}
2016-09-19 01:50:50 +02:00
.emotitle:after{content:"»";}
img{
width:100%;
2016-09-20 13:00:40 +02:00
/*! filter:saturate(0%); */
/*! mix-blend-mode: multiply; */
/*mix-blend-mode: exclusion;*/
}
2016-09-19 01:50:50 +02:00
.perc{
display:block;
width:100%;
text-align:center;
}
2016-09-19 01:50:50 +02:00
.emo-block{
2016-09-19 01:50:50 +02:00
float:left;
text-align:center;
}
.brows .emo-block {
width:23%;
margin-left:1%;
margin-right:1%;
2016-09-21 15:56:24 +02:00
height: 22em;
2016-09-19 01:50:50 +02:00
}
.nose .emo-block {
width:12%;
margin-left:1.14%;
margin-right:1.14%;
2016-09-19 01:50:50 +02:00
}
.nose .emotitle{
font-size:80%;
2016-09-19 01:50:50 +02:00
}
.emo-block-emos{
position:relative;
2016-09-19 01:50:50 +02:00
}
.emo{
2016-09-19 01:50:50 +02:00
text-align:center;
float:left;
2016-09-20 13:00:40 +02:00
background:black;
color: white;
}
.brows{
width:40%;
margin-right:1%;
}
.nose{
width:40%;
margin-right:1%;
2016-09-19 01:50:50 +02:00
}
.mouth{
width:81%;
margin-top:1%;
}
img.curImg{
2016-09-19 01:50:50 +02:00
position:absolute;
left:0;
mix-blend-mode:difference;
}
.currentHit svg{
border-top: 1em solid blue;
margin: 0px -0.5em;
width: 100%;
padding: 0.5em;
width:100%;
}
.presentation .currentHit svg {
border-top: solid 0.1em white;
}
2016-09-19 01:50:50 +02:00
.nose .block{position:relative;margin-bottom:2%;}
.nose .block span{position:absolute;top:0;right:0;color:white;text-align:right;padding:0.5%;}
2016-09-19 11:36:04 +02:00
2016-09-19 14:58:58 +02:00
.brows .emo-block.brow_explainer {
margin-top:3%;font-size:85%;
border-left: 0.3em solid blue;
width: 22%;
padding-left: 0.4em;
margin-left: -0.1em;
2016-09-19 01:50:50 +02:00
}
2016-09-20 11:31:59 +02:00
.presentation .brows .emo-block.brow_explainer{
border-left-color: black;
}
2016-09-19 01:50:50 +02:00
.brow_explainer img{filter:unset;margin-bottom:5%;}
.brow_explainer ol{
margin:0;padding:0;
counter-reset:li 4;
2016-09-19 01:50:50 +02:00
}
.brow_explainer li{
text-align:left;
margin-bottom:5%;
list-style:none;
2016-09-19 01:50:50 +02:00
}
.brow_explainer li:before{
content:counter(li) ". "; /* Use the counter as content */
counter-increment:li; /* Increment the counter by 1 */
color:red;
2016-09-19 01:50:50 +02:00
}
.currentHit{
width:17%;
position:absolute;
right:0.5em;
top:0.5em;
background:yellow;
padding:0.5%;
}
2016-09-20 11:29:33 +02:00
.presentation .currentHit {
background:none;
2016-09-20 11:29:56 +02:00
color:white;
2016-09-20 11:29:33 +02:00
}
.presentation .currentHit h3 span{
color:white;
background: none;
2016-09-19 01:50:50 +02:00
}
.currentHit h3 span{
color:yellow;
}
.presentation .currentHit h3 span{
color:white;
2016-09-19 01:50:50 +02:00
}
2016-09-19 02:08:28 +02:00
.currentHit h3 .last{color:red;}
.currentHit h3 .vs{background:none;color:black;padding-left:0.5em;padding-right:0.5em;}
.currentHit h3 .perfect{}
2016-09-19 01:50:50 +02:00
ul{
font-size:80%;
list-style:none;
margin:0;
padding:0;
}
.presentation ul{
2016-09-20 11:31:22 +02:00
font-size:1.1em;
2016-09-19 01:50:50 +02:00
}
.currentHit li{
clear:both;
2016-09-19 01:50:50 +02:00
}
.currentHit li .value{
float:right;
}
.currentHit li .diff{
float:right;
clear:both;
font-size:72%;
color:gray;
2016-09-19 01:50:50 +02:00
}
.currentHit li .diff.negative{
color:red;
2016-09-19 01:50:50 +02:00
}
.currentHit li .diff.positive{
color:green;
2016-09-19 02:08:28 +02:00
}
2016-09-20 11:33:01 +02:00
.presentation .currentHit li .diff.positive{
color:yellow;
}
2016-09-19 02:08:28 +02:00
.currentHit p {
margin: 0 -0.5em 1% -0.5em;
border-bottom: solid 1em blue;
padding: 0.5em;
text-align: center;
}
.presentation .currentHit p {
border-bottom: solid 0.1em white;
2016-09-19 01:50:50 +02:00
}
2016-09-20 13:01:12 +02:00
2016-09-19 01:50:50 +02:00
</style>
2016-09-22 00:17:26 +02:00
<body class='presentation'>
2016-09-19 01:50:50 +02:00
<?php
echo "<div class='brows emo'><h3><span>eye brows</span></h3>";
foreach(EmotionHero\Models\Emotions::$EMOTIONS as $emotion) {
echo "<div class='emo-block'><span class='emotitle'>$emotion</span><div class='emo-block-emos'>";
$printEmoBlocks($emotion, 'brows');
//echo "<img class='curImg' src=\"data:image/x-icon;base64,{$currentHit->getFeatureImgAsString("brows")}\" title=\"{$currentHit->getId()}\" style=\"top:{$currentHit->getEmotions()->getEmotionScore($emotion)}%\">";
echo "</div></div>";
}
?>
<div class="emo-block brow_explainer">
2016-09-21 15:56:24 +02:00
<img src="brow_explain_color.png">
2016-09-19 01:50:50 +02:00
<ol start="5">
<li>Outer Right Brow Corner</li>
<li>Right Brow Center</li>
<li>Inner Right Brow Corner</li>
<li>Inner Left Brow Corner</li>
<li>Left Brow Center</li>
<li>Outer Left Brow Corner</li>
</ol>
</div>
<?php
echo "</div>"; // .brows
echo "<div class='nose emo'><h3><span>nose</span></h3>";
foreach(EmotionHero\Models\Emotions::$EMOTIONS as $emotion) {
echo "<div class='emo-block'><span class='emotitle'>$emotion</span><div class='emo-block-emos'>";
$printEmoBlocks($emotion, 'nose');
//echo "<img class='curImg' src=\"data:image/x-icon;base64,{$currentHit->getFeatureImgAsString("nose")}\" title=\"{$currentHit->getId()}\" style=\"top:{$currentHit->getEmotions()->getEmotionScore($emotion)}%\">";
echo "</div></div>";
}
echo "</div>"; // .nose
echo "<div class='mouth emo'><h3><span>mouth</span></h3>";
foreach(EmotionHero\Models\Emotions::$EMOTIONS as $emotion) {
echo "<div class='emo-block'><span class='emotitle'>$emotion</span><div class='emo-block-emos'>";
$printEmoBlocks($emotion, 'mouth_left');
echo "</div></div>";
}
echo "</div>"; // .mouth
echo "<div class='currentHit'>";
2016-09-19 02:08:28 +02:00
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>";
2016-09-22 00:17:26 +02:00
echo "<p>aim:";
foreach($targetSet as $target) {
2016-09-22 00:43:20 +02:00
echo " {$target->getScore()}% {$target->getEmotion()->getName()}";
2016-09-22 00:17:26 +02:00
}
echo "</p>";
2016-09-22 00:43:20 +02:00
if(empty($betterHit)) {
echo "<p>Best attempt so far</p>";
}
2016-09-22 00:17:26 +02:00
//echo "<p>aim: {$currentHit->getTarget()->getScore()}% ".$currentHit->getTarget()->getEmotion()->getName()."</p>";
2016-09-19 01:50:50 +02:00
echo "<ul>";
$expressions = array_keys($currentHit->getExpressions()::$EXPRESSIONS_2ND_PERSON);
sort($expressions);
2016-09-22 00:17:26 +02:00
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>";
2016-09-19 01:50:50 +02:00
}
echo "</ul>";
$circles = "";
2016-09-22 00:17:26 +02:00
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>';
}
2016-09-19 01:50:50 +02:00
}
foreach($currentHit->getPoints()->getNormalisedPoints() as $i => $point) {
$circles .= '<text
style="fill:red;font-size:4"
id="point'.$i.'"
x="'.$point->getX().'"
y="'.$point->getY().'"
r="0.7">'.$i.'</text>';
}
echo <<< EOSVG
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="-4 -4 108 108"
id="svg2"
version="1.1">
<g id="layer1">
$circles
</g>
</svg>
EOSVG;
echo "</div>"; // .currentHit
?>
2016-11-01 22:35:27 +01:00
<script type="text/javascript">
var socket = new WebSocket("ws://<?php echo $_SERVER['SERVER_NAME']; ?>:8181");
2016-11-01 22:36:23 +01:00
socket.onopen = function(){
2016-11-01 22:35:27 +01:00
/*Send a small message to the console once the connection is established */
console.log('Connection open!');
};
2016-11-01 22:36:23 +01:00
socket.onclose = function(){
2016-11-01 22:35:27 +01:00
console.log('Connection closed');
2016-11-01 22:36:23 +01:00
location.reload();
// socket.connect()
2016-11-01 22:35:27 +01:00
}
2016-11-01 22:36:23 +01:00
socket.onerror = function(error){
2016-11-01 22:35:27 +01:00
// reload page
console.log('Error detected: ' + error);
location.reload();
}
2016-11-01 22:36:23 +01:00
socket.onmessage = function(e){
2016-11-01 22:38:52 +01:00
console.log(e.data);
2016-11-01 22:35:27 +01:00
var message = JSON.parse(e.data);
// var server_message = e.data;
console.log(message);
if(message['action'] == 'update') {
if(message['method'] == 'image' || message['method'] == 'game') {
// reload page
location.reload();
}
}
}
</script>
2016-09-19 01:50:50 +02:00
</body>
</html>