refining statistics handlin
This commit is contained in:
parent
10337a71c7
commit
c8dbc31ea3
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
require_once(__DIR__ . '/includes/errorlog.php');
|
||||
require_once(__DIR__ . '/includes/utilities.php');
|
||||
require_once(__DIR__ . '/includes/init.php');
|
||||
require_once(__DIR__ . '/includes/blocks.php');
|
||||
require_once(__DIR__ . '/includes/post_types.php');
|
||||
|
|
|
|||
|
|
@ -239,6 +239,7 @@ function get_interface_page_screen($request)
|
|||
|
||||
// ################ POST GAME STATISTICS ################
|
||||
|
||||
|
||||
function lhoist_sanitize_statistic_datas($datas)
|
||||
{
|
||||
$cleanDatas = array();
|
||||
|
|
@ -246,6 +247,7 @@ function lhoist_sanitize_statistic_datas($datas)
|
|||
$cleanDatas['user_locale'] = isset($datas['user_locale']) ? sanitize_text_field($datas['user_locale']) : null;
|
||||
$cleanDatas['user_country'] = isset($datas['user_country']) ? sanitize_text_field($datas['user_country']) : null;
|
||||
$cleanDatas['level_post_id'] = isset($datas['level_post_id']) ? (int) $datas['level_post_id'] : null;
|
||||
$cleanDatas['level_name'] = isset($datas['level_name']) ? sanitize_text_field($datas['level_name']) : null;
|
||||
$cleanDatas['level_score'] = isset($datas['level_score']) ? (int) $datas['level_score'] : null;
|
||||
$cleanDatas['level_completion_time'] = isset($datas['level_completion_time']) ? (int) $datas['level_completion_time'] : null;
|
||||
|
||||
|
|
@ -275,28 +277,25 @@ function lhoist_check_statistics_datas_formats($datas)
|
|||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function lhoist_convert_post_id($id)
|
||||
{
|
||||
$convertedId = apply_filters('wpml_object_id', $id, 'search-and-find', true);
|
||||
return $convertedId;
|
||||
}
|
||||
|
||||
function lhoist_post_game_datas_statistics(WP_REST_Request $request)
|
||||
{
|
||||
$datas = $request->get_json_params();
|
||||
|
||||
$datas['level_post_id'] = lhoist_convert_post_id($datas['level_post_id']);
|
||||
$datas['level_name'] = html_entity_decode(get_the_title($datas['level_post_id']), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$cleanDatas = lhoist_sanitize_statistic_datas($datas);
|
||||
lhoist_check_statistics_datas_formats($cleanDatas);
|
||||
|
||||
|
||||
global $wpdb;
|
||||
$datetime = new DateTime("now", new DateTimeZone('Europe/Brussels'));
|
||||
|
||||
$gameStats = array(
|
||||
'session_ID' => "qsdqsdqsdqsd",
|
||||
'user_locale' => "FR",
|
||||
'user_country' => "France",
|
||||
'level_post_id' => 43,
|
||||
'level_is_completed' => $level_is_completed ?? "0",
|
||||
'level_completion_time' => 200,
|
||||
'level_score' => 3,
|
||||
'date' => $datetime->format('Y-m-d H:i:s'),
|
||||
);
|
||||
$table_name = 'wp_app_users_statistics';
|
||||
$result_check = $wpdb->insert(
|
||||
$table_name,
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ function generate_pdf_from_html($html_content, $filename = 'export.pdf')
|
|||
$pdf->SetKeywords('Keywords');
|
||||
|
||||
// Définir l'en-tête et le pied de page
|
||||
$pdf->setHeaderData('', PDF_HEADER_LOGO_WIDTH, 'Title', 'Header text');
|
||||
$pdf->setHeaderData('', PDF_HEADER_LOGO_WIDTH, 'Statistiques de jeu ', 'Lhoist Stay safe');
|
||||
$pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
|
||||
|
||||
// Définir la police
|
||||
|
|
@ -133,7 +133,8 @@ function export_data_to_csv()
|
|||
|
||||
// Écrire les données dans le fichier CSV
|
||||
foreach ($data as $row) {
|
||||
$row["level_completion_time"] = $row["level_completion_time"] / 100;
|
||||
// $row["level_completion_time"] = $row["level_completion_time"] / 100;
|
||||
|
||||
fputcsv($file, $row);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@ $level_post_ids = $wpdb->get_col("
|
|||
FROM $table_name
|
||||
WHERE level_post_id = $level_post_id
|
||||
");
|
||||
$average_level_time = $wpdb->get_var("
|
||||
SELECT AVG(level_completion_time) as average
|
||||
FROM $table_name
|
||||
WHERE level_post_id = $level_post_id
|
||||
");
|
||||
$completeLevelsScores = $wpdb->get_results("
|
||||
SELECT level_score
|
||||
FROM $table_name
|
||||
|
|
@ -62,13 +67,20 @@ $level_post_ids = $wpdb->get_col("
|
|||
<div class="average-score">
|
||||
<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" />
|
||||
a 15.9155 15.9155 0 0 1 0 31.831
|
||||
a 15.9155 15.9155 0 0 1 0 -31.831" />
|
||||
</svg>
|
||||
<p class="text"><?php echo round($average_level_score, 1) ?></p>
|
||||
<!-- <div class="donut-average"></div> -->
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<h3>Temps moyen</h3>
|
||||
<?php if ($average_level_time) : ?>
|
||||
<div class="average-time">
|
||||
<p class="text"><?php echo round($average_level_time, 1) ?> secondes</p>
|
||||
<!-- <div class="donut-average"></div> -->
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
<div class="game_stats__scores-distribution ">
|
||||
|
|
@ -92,7 +104,7 @@ $level_post_ids = $wpdb->get_col("
|
|||
<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>
|
||||
<li><span class="data-label"><?php echo $users_locale->user_locale ?></span> : <?php echo $users_locale->count ?><span class="joueurs">joueurs</span></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user