This commit is contained in:
Antoine M 2024-03-13 17:55:27 +01:00
parent 26df4edcce
commit cc73ee13dd

View File

@ -2,117 +2,132 @@
if (!current_user_can('manage_options')) return; if (!current_user_can('manage_options')) return;
global $wpdb; global $wpdb;
$table_name = "wp_app_users_statistics"; $table_name = "wp_app_users_statistics";
$level_post_ids = $wpdb->get_col(" $level_post_ids = $wpdb->get_col("
SELECT DISTINCT level_post_id SELECT DISTINCT level_post_id
FROM $table_name FROM $table_name
"); ");
?> ?>
<div class="page-sessions-datas"> <div class="page-sessions-datas">
<h1 class="page-title"><?php echo esc_html(get_admin_page_title()); ?></h1> <h1 class="page-title"><?php echo esc_html(get_admin_page_title()); ?></h1>
<?php foreach ($level_post_ids as $level_post_id) : ?> <?php foreach ($level_post_ids as $level_post_id) : ?>
<?php $levelPost = get_post($level_post_id); ?> <?php $levelPost = get_post($level_post_id); ?>
<section class="game_stats"> <section class="game_stats">
<?php <?php
$users_locales = $wpdb->get_results(" $users_locales = $wpdb->get_results("
SELECT user_locale, COUNT(user_locale) as count SELECT user_locale, COUNT(user_locale) as count
FROM $table_name FROM $table_name
WHERE level_post_id = $level_post_id WHERE level_post_id = $level_post_id
GROUP BY user_locale GROUP BY user_locale
"); ");
$users_countries = $wpdb->get_results(" $users_countries = $wpdb->get_results("
SELECT user_country, COUNT(user_country) as count SELECT user_country, COUNT(user_country) as count
FROM $table_name FROM $table_name
WHERE level_post_id = $level_post_id WHERE level_post_id = $level_post_id
GROUP BY user_country GROUP BY user_country
"); ");
$notes_repartition = $wpdb->get_results(" $notes_repartition = $wpdb->get_results("
SELECT level_score, COUNT(level_score) as count SELECT level_score, COUNT(level_score) as count
FROM $table_name FROM $table_name
WHERE level_post_id = $level_post_id WHERE level_post_id = $level_post_id
GROUP BY level_score GROUP BY level_score
"); ");
$average_level_score = $wpdb->get_var(" $average_level_score = $wpdb->get_var("
SELECT AVG(level_score) as average SELECT AVG(level_score) as average
FROM $table_name FROM $table_name
WHERE level_post_id = $level_post_id WHERE level_post_id = $level_post_id
"); ");
$completeLevelsScores = $wpdb->get_results(" $completeLevelsScores = $wpdb->get_results("
SELECT level_score SELECT level_score
FROM $table_name FROM $table_name
WHERE level_post_id = $level_post_id WHERE level_post_id = $level_post_id
"); ");
?> ?>
<h2 class="game_stats__game-title"><?php echo $levelPost->post_title ?></h2> <h2 class="game_stats__game-title"><?php echo $levelPost->post_title ?></h2>
<div class="game_stats__stats-container"> <div class="game_stats__stats-container">
<div class="game_stats__statistics-section game-statistics"> <div class="game_stats__statistics-section game-statistics">
<div class="game_stats__average-score block-data-score"> <div class="game_stats__average-score block-data-score">
<h3>Score moyen</h3> <h3>Score moyen</h3>
<?php if ($average_level_score) : ?> <?php if ($average_level_score) : ?>
<div class="average-score"> <div class="average-score">
<svg viewBox="0 -1 40 40" class="circular-chart"> <svg viewBox="0 -1 40 40" class="circular-chart">
<path class="circle" stroke-dasharray="70, 800" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831" /> <path class="circle" stroke-dasharray="70, 800" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831" />
</svg> </svg>
<p class="text"><?php echo round($average_level_score, 1) ?></p> <p class="text"><?php echo round($average_level_score, 1) ?></p>
<!-- <div class="donut-average"></div> --> <!-- <div class="donut-average"></div> -->
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="game_stats__scores-distribution "> <div class="game_stats__scores-distribution ">
<h3>Répartition des scores</h3> <h3>Répartition des scores</h3>
<canvas id="graphic-score-repartition"></canvas> <canvas id="graphic-score-repartition"></canvas>
<ul>
<?php foreach ($notes_repartition as $note) : ?>
<li class="score-data" score="<?php echo $note->level_score ?>" count="<?php echo $note->count ?>"><span class="data-label"><?php echo $note->level_score ?></span> : <span class="data-value"><?php echo $note->count ?></span> <span class="joueurs">joueurs</span></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="game_stats__statistics-section geopraphy-statistics">
<h3 class=" section-title">Langue et Géographie</h3>
<div class="data-grid">
<div class="lang">
<h4>Répartition des langues</h4>
<ul> <ul>
<?php foreach ($notes_repartition as $note) : ?> <?php foreach ($users_locales as $users_locale) : ?>
<li class="score-data" score="<?php echo $note->level_score ?>" count="<?php echo $note->count ?>"><span class="data-label"><?php echo $note->level_score ?></span> : <span class="data-value"><?php echo $note->count ?></span> <span class="joueurs">joueurs</span></li> <li><span class="data-label"><?php echo $users_locale->user_locale ?></span> : <?php echo $users_locale->count ?></li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
</div> </div>
<div class="countries">
</div> <h4>Répartition des pays</h4>
<div class="game_stats__statistics-section geopraphy-statistics"> <ul>
<h3 class=" section-title">Langue et Géographie</h3> <?php foreach ($users_countries as $user_country) : ?>
<div class="data-grid"> <li><span class="data-label"><?php echo $user_country->user_country ?></span> : <?php echo $user_country->count ?> joueurs</li>
<?php endforeach; ?>
<div class="lang"> </ul>
<h4>Répartition des langues</h4>
<ul>
<?php foreach ($users_locales as $users_locale) : ?>
<li><span class="data-label"><?php echo $users_locale->user_locale ?></span> : <?php echo $users_locale->count ?></li>
<?php endforeach; ?>
</ul>
</div>
<div class="countries">
<h4>Répartition des pays</h4>
<ul>
<?php foreach ($users_countries as $user_country) : ?>
<li><span class="data-label"><?php echo $user_country->user_country ?></span> : <?php echo $user_country->count ?> joueurs</li>
<?php endforeach; ?>
</ul>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="download-btns"> </div>
<a href="<?php echo admin_url('admin-post.php?action=download_pdf'); ?>" class="button dowload-stats">Télécharger PDF</a> <div class="download-btns">
<a href="<?php echo admin_url('admin-post.php?action=export_csv'); ?>" class="button dowload-stats">Exporter vers CSV</a> <a href="<?php echo admin_url('admin-post.php?action=download_pdf'); ?>" class="button dowload-stats">Télécharger PDF</a>
</div> <a href="<?php echo admin_url('admin-post.php?action=export_csv'); ?>" class="button dowload-stats">Exporter vers CSV</a>
</div>
</section> </section>
<?php endforeach; ?> <?php endforeach; ?>
</div> <?php
<?php $ratings_table_name = "wp_app_ratings";
$ratings = $wpdb->get_results("
SELECT rating, COUNT(rating) as count
FROM $ratings_table_name
GROUP BY rating
");
echo '<pre>';
print_r($ratings);
echo '</pre>';
?>
<section class="ratings">
</section>
</div>