Commit aa3fce9e authored by Arnaud Bey's avatar Arnaud Bey
Browse files

add bigrams to debug page

parent 93b2f9cc
......@@ -61,4 +61,15 @@ class LanguageManager
return;
}
public function getBigrams(Language $language)
{
$fileBigrams = $language->getDirectory().DIRECTORY_SEPARATOR."bigrams.txt";
$bigrams = file_exists($fileBigrams)
? file($fileBigrams)
: [];
return $bigrams;
}
}
......@@ -56,6 +56,8 @@ class AdministrationController extends Controller
$countWords = $this->getDoctrine()->getRepository(Word::class)->countAllByLanguage($language);
$countRoots = $this->getDoctrine()->getRepository(Root::class)->countAllByLanguage($language);
$countWordStarts = $this->getDoctrine()->getRepository(WordStart::class)->countAllByLanguage($language);
$bigrams = $this->get('lexicon_manager.language')->getBigrams($language);
$bigrams = array_slice($bigrams, 1, 6);
$letters = $this->getDoctrine()->getRepository(Letter::class)->findBy(["language" => $language], ["value" => "ASC"]);
return $this->render('MagicWordBundle:Administration:language-debug.html.twig', [
......@@ -66,7 +68,8 @@ class AdministrationController extends Controller
'countWords' => $countWords,
'countWordStarts' => $countWordStarts,
'countRoots' => $countRoots,
'letters' => $letters
'letters' => $letters,
'bigrams' => $bigrams
]);
}
......
......@@ -16,6 +16,7 @@ class GridManager
{
protected $em;
protected $squareManager;
protected $languageManager;
protected $foundableFormManager;
protected $tokenStorage;
......@@ -24,14 +25,16 @@ class GridManager
* "entityManager" = @DI\Inject("doctrine.orm.entity_manager"),
* "foundableFormManager" = @DI\Inject("mw_manager.foundableform"),
* "squareManager" = @DI\Inject("mw_manager.square"),
* "languageManager" = @DI\Inject("lexicon_manager.language"),
* "tokenStorage" = @DI\Inject("security.token_storage"),
* })
*/
public function __construct($entityManager, $foundableFormManager, $squareManager, $tokenStorage)
public function __construct($entityManager, $foundableFormManager, $squareManager, $languageManager, $tokenStorage)
{
$this->em = $entityManager;
$this->foundableFormManager = $foundableFormManager;
$this->squareManager = $squareManager;
$this->languageManager = $languageManager;
$this->tokenStorage = $tokenStorage;
}
......@@ -356,12 +359,10 @@ class GridManager
public function lottery(Language $language, $side, $debug = false, $minBigram = null)
{
$minBigram = ($minBigram == null) ? $language->getMinBigram() : $minBigram;
$fileBigrams = $language->getDirectory().DIRECTORY_SEPARATOR."bigrams.txt";
// On crée un tableau de bigrammes
// où chaque bigramme apparait autant de fois que son poids
$bigrams = [];
$lines = file($fileBigrams);
$lines = $this->languageManager->getBigrams($language);
$lettersFromBigrams=[];
array_shift($lines);
foreach ($lines as $line) {
......
......@@ -15,42 +15,61 @@
<div class="card">
<div class="card-body">
<ul class="list-group mb-2">
<li class="list-group-item list-group-item-secondary">Stats</li>
<li class="list-group-item">{{letters|length}} lettres (
{% for letter in letters %}
<strong>{{letter.value}}</strong> -
{% endfor %}
)</li>
<li class="list-group-item">{{countGrids}} grilles</li>
<li class="list-group-item">{{countWords}} words</li>
<li class="list-group-item">{{countRoots}} roots</li>
<li class="list-group-item">{{countWordStarts}} wordstarts</li>
</ul>
<ul class="list-group mb-2">
<li class="list-group-item list-group-item-secondary">Meilleures grilles</li>
{% for grid in bestGrids %}
<li class="list-group-item">[{{grid.foundableForms|length}}] -
{% for square in grid.squares %}
{{square.letter.value}}
{% endfor %}
</li>
{% endfor %}
</ul>
<ul class="list-group mb-2">
<li class="list-group-item list-group-item-secondary">Moins bonnes grilles</li>
{% for grid in worstGrids %}
<li class="list-group-item">[{{grid.foundableForms|length}}] -
{% for square in grid.squares %}
{{square.letter.value}}
{% endfor %}
</li>
{% endfor %}
</ul>
<div class="row">
<div class="col-sm-6">
<ul class="list-group mb-2">
<li class="list-group-item list-group-item-secondary">Stats</li>
<li class="list-group-item">{{letters|length}} lettres (
{% for letter in letters %}
<strong>{{letter.value}}</strong> -
{% endfor %}
)</li>
<li class="list-group-item">{{countWords}} mots</li>
<li class="list-group-item">{{countRoots}} roots</li>
{% set ratio = countWords/countRoots %}
<li class="list-group-item">{{ratio |round(1) }} mots par root</li>
<li class="list-group-item">{{countWordStarts}} wordstarts</li>
<li class="list-group-item">{{countGrids}} grilles</li>
</ul>
</div>
<div class="col-sm-6">
<ul class="list-group mb-2">
<li class="list-group-item list-group-item-secondary">Bigrammes fréquents</li>
{% for bigram in bigrams %}
<li class="list-group-item">
{{bigram}}
</li>
{% endfor %}
<li class="list-group-item list-group-item">...</li>
</ul>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<ul class="list-group mb-2">
<li class="list-group-item list-group-item-secondary">Meilleures grilles</li>
{% for grid in bestGrids %}
<li class="list-group-item">[{{grid.foundableForms|length}}] -
{% for square in grid.squares %}
{{square.letter.value}}
{% endfor %}
</li>
{% endfor %}
</ul>
</div>
<div class="col-sm-6">
<ul class="list-group mb-2">
<li class="list-group-item list-group-item-secondary">Moins bonnes grilles</li>
{% for grid in worstGrids %}
<li class="list-group-item">[{{grid.foundableForms|length}}] -
{% for square in grid.squares %}
{{square.letter.value}}
{% endfor %}
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endblock %}
......@@ -29,10 +29,6 @@
{{"save_all"|trans}}
</span>
{% endif %}
<a href="{{ path('massive_builder', {"id": round.game.id}) }}" class="btn btn-sm btn-outline-secondary">
<i class="fa fa-chevron-left" aria-hidden="true"></i>
{{ 'back_to_editor' | trans }}
</a>
</span>
</div>
<div class="card-body">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment