Adds participants to monthly stats widget

main
Yasen Pramatarov 2024-07-31 21:54:30 +03:00
parent c011321403
commit 55b53ef30a
5 changed files with 64 additions and 11 deletions

View File

@ -85,7 +85,7 @@ class Conference {
} }
// number of conferences // number of conferences
public function conferencesNumber($from_time, $until_time) { public function conferenceNumber($from_time, $until_time) {
// time period drill-down // time period drill-down
// FIXME make it similar to the bash version // FIXME make it similar to the bash version
@ -99,7 +99,7 @@ class Conference {
// this is needed for compatibility with the bash version, so we use '%s' placeholders // this is needed for compatibility with the bash version, so we use '%s' placeholders
$from_time = htmlspecialchars(strip_tags($from_time)); $from_time = htmlspecialchars(strip_tags($from_time));
$until_time = htmlspecialchars(strip_tags($until_time)); $until_time = htmlspecialchars(strip_tags($until_time));
$sql = $this->queries['conferences_number']; $sql = $this->queries['conference_number'];
$sql = sprintf($sql, $from_time, $until_time); $sql = sprintf($sql, $from_time, $until_time);
$query = $this->db->prepare($sql); $query = $this->db->prepare($sql);

View File

@ -109,6 +109,30 @@ class Participant {
return $query->fetchAll(PDO::FETCH_ASSOC); return $query->fetchAll(PDO::FETCH_ASSOC);
} }
// number of conferences
public function participantNumber($from_time, $until_time) {
// time period drill-down
// FIXME make it similar to the bash version
if (empty($from_time)) {
$from_time = '0000-01-01';
}
if (empty($until_time)) {
$until_time = '9999-12-31';
}
// this is needed for compatibility with the bash version, so we use '%s' placeholders
$from_time = htmlspecialchars(strip_tags($from_time));
$until_time = htmlspecialchars(strip_tags($until_time));
$sql = $this->queries['participant_number'];
$sql = sprintf($sql, $from_time, $until_time);
$query = $this->db->prepare($sql);
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
} }

View File

@ -5,7 +5,7 @@
return [ return [
// number of conferences for time period (if given) // number of conferences for time period (if given)
'conferences_number' => " 'conference_number' => "
SELECT COUNT(c.conference_id) as conferences SELECT COUNT(c.conference_id) as conferences
FROM FROM
conferences c conferences c
@ -201,6 +201,18 @@ ORDER BY
pe.time;", pe.time;",
// number of participants for time period (if given)
'participant_number' => "
SELECT COUNT(p.endpoint_id) as participants
FROM
participants p
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
(pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59')
AND pe.event_type = 'pair selected'",
// list all participants // list all participants
'participants_all' => " 'participants_all' => "
SELECT DISTINCT SELECT DISTINCT

View File

@ -2,6 +2,7 @@
require_once 'classes/database.php'; require_once 'classes/database.php';
require 'classes/conference.php'; require 'classes/conference.php';
require 'classes/participant.php';
// connect to database // connect to database
try { try {
@ -20,6 +21,7 @@ try {
//// ////
// monthly usage // monthly usage
$conference = new Conference($db); $conference = new Conference($db);
$participant = new Participant($db);
// monthly conferences for the last year // monthly conferences for the last year
$fromMonth = (new DateTime())->sub(new DateInterval('P1Y')); $fromMonth = (new DateTime())->sub(new DateInterval('P1Y'));
@ -29,7 +31,8 @@ $from_time = $fromMonth->format('Y-m-d');
$until_time = $thisMonth->format('Y-m-d'); $until_time = $thisMonth->format('Y-m-d');
$widget['table_headers'] = array(); $widget['table_headers'] = array();
$widget['table_records'] = array(); $widget['table_records_conferences'] = array();
$widget['table_records_participants'] = array();
// loop 1 year in the past // loop 1 year in the past
while ($fromMonth < $thisMonth) { while ($fromMonth < $thisMonth) {
@ -37,17 +40,23 @@ while ($fromMonth < $thisMonth) {
$untilMonth = clone $fromMonth; $untilMonth = clone $fromMonth;
$untilMonth->modify('last day of this month'); $untilMonth->modify('last day of this month');
$search = $conference->conferencesNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d')); $searchConferenceNumber = $conference->conferenceNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d'));
$searchParticipantNumber = $participant->participantNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d'));
// pretty format for displaying the month in the widget // pretty format for displaying the month in the widget
$month = $fromMonth->format('F Y'); $month = $fromMonth->format('F Y');
// populate the table // populate the table
array_push($widget['table_headers'], $month); array_push($widget['table_headers'], $month);
if (isset($search[0]['conferences'])) { if (isset($searchConferenceNumber[0]['conferences'])) {
array_push($widget['table_records'], $search[0]['conferences']); array_push($widget['table_records_conferences'], $searchConferenceNumber[0]['conferences']);
} else { } else {
array_push($widget['table_records'], '0'); array_push($widget['table_records_conferences'], '0');
}
if (isset($searchParticipantNumber[0]['participants'])) {
array_push($widget['table_records_participants'], $searchParticipantNumber[0]['participants']);
} else {
array_push($widget['table_records_participants'], '0');
} }
// move everything one month in future // move everything one month in future
@ -60,11 +69,11 @@ $time_range_specified = true;
// prepare the widget // prepare the widget
$widget['full'] = false; $widget['full'] = false;
$widget['name'] = 'LastYearMonths'; $widget['name'] = 'LastYearMonths';
$widget['title'] = 'Conferences monthly number for the last year'; $widget['title'] = 'Conferences monthly stats for the last year';
$widget['collapsible'] = true; $widget['collapsible'] = true;
$widget['collapsed'] = false; $widget['collapsed'] = false;
$widget['filter'] = false; $widget['filter'] = false;
if (!empty($search)) { if (!empty($searchConferenceNumber) && !empty($searchParticipantNumber)) {
$widget['full'] = true; $widget['full'] = true;
} }

View File

@ -24,6 +24,7 @@
<table class="table table-striped table-hover table-bordered"> <table class="table table-striped table-hover table-bordered">
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<th scope="col"></th>
<?php foreach ($widget['table_headers'] as $header) { ?> <?php foreach ($widget['table_headers'] as $header) { ?>
<th scope="col"><?= htmlspecialchars($header) ?></th> <th scope="col"><?= htmlspecialchars($header) ?></th>
<?php } ?> <?php } ?>
@ -31,7 +32,14 @@
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<?php foreach ($widget['table_records'] as $row) { ?> <td>conferences</td>
<?php foreach ($widget['table_records_conferences'] as $row) { ?>
<td><?= htmlspecialchars($row ?? '') ?></td>
<?php } ?>
</tr>
<tr>
<td>participants</td>
<?php foreach ($widget['table_records_participants'] as $row) { ?>
<td><?= htmlspecialchars($row ?? '') ?></td> <td><?= htmlspecialchars($row ?? '') ?></td>
<?php } ?> <?php } ?>
</tr> </tr>