Changed average age from now to start of event
This commit is contained in:
@@ -269,7 +269,7 @@ function _booking_convert_ts($timestamp)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to ensure timestamp is converted to correct local time
|
* Helper function to calculate the timestamp corresponding with the DOB requirements
|
||||||
*/
|
*/
|
||||||
function _booking_max_dob_ts()
|
function _booking_max_dob_ts()
|
||||||
{
|
{
|
||||||
@@ -278,6 +278,22 @@ function _booking_max_dob_ts()
|
|||||||
return mktime(12, 0, 0, $max_dob_matches[2], $max_dob_matches[3], $max_dob_matches[1]);
|
return mktime(12, 0, 0, $max_dob_matches[2], $max_dob_matches[3], $max_dob_matches[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to calculate the average age in days, months and years at the start of the event
|
||||||
|
*/
|
||||||
|
function _booking_avg_age($sum, $count, $reference_ts)
|
||||||
|
{
|
||||||
|
global $event;
|
||||||
|
//calculate the average age timestamp
|
||||||
|
$average = $sum / $count;
|
||||||
|
//get the difference between now and the average timestamp
|
||||||
|
$average_date = _booking_convert_ts(floor($average));
|
||||||
|
$now_date = _booking_convert_ts(floor($reference_ts));
|
||||||
|
$difference = $average_date->diff($now_date);
|
||||||
|
//convert the difference into english
|
||||||
|
return $difference->y . " years, " . $difference->m . " months, " . $difference->d . " days";
|
||||||
|
}
|
||||||
|
|
||||||
function _date_range_to_string($date_start, $date_end) {
|
function _date_range_to_string($date_start, $date_end) {
|
||||||
$start = _booking_split_date($date_start);
|
$start = _booking_split_date($date_start);
|
||||||
$end = _booking_split_date($date_end);
|
$end = _booking_split_date($date_end);
|
||||||
|
@@ -18,12 +18,11 @@ function booking_report_summary() {
|
|||||||
$married_count = 0;
|
$married_count = 0;
|
||||||
$total_paid = 0;
|
$total_paid = 0;
|
||||||
$dob_total = 0;
|
$dob_total = 0;
|
||||||
|
$male_dob_total = 0;
|
||||||
|
$female_dob_total = 0;
|
||||||
$person_count = 0;
|
$person_count = 0;
|
||||||
$average = 0;
|
|
||||||
$average_age = "";
|
|
||||||
//$year = 60 * 60 * 24 * 365.25;
|
|
||||||
$stats_attributes = array('style' => 'max-width:30%');
|
|
||||||
|
|
||||||
|
$stats_attributes = array('style' => 'max-width:30%');
|
||||||
$header = array('Id', 'Name', 'Email', 'Payment To Date', 'Total Payment Required');
|
$header = array('Id', 'Name', 'Email', 'Payment To Date', 'Total Payment Required');
|
||||||
$rows = array();
|
$rows = array();
|
||||||
$state_header = array('State', 'Count');
|
$state_header = array('State', 'Count');
|
||||||
@@ -61,9 +60,15 @@ function booking_report_summary() {
|
|||||||
$person_count++;
|
$person_count++;
|
||||||
|
|
||||||
if ($person->booking_gender == 'M')
|
if ($person->booking_gender == 'M')
|
||||||
|
{
|
||||||
$male_count++;
|
$male_count++;
|
||||||
|
$male_dob_total += $person->booking_dob;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
$female_count++;
|
$female_count++;
|
||||||
|
$female_dob_total += $person->booking_dob;
|
||||||
|
}
|
||||||
|
|
||||||
if ($person->booking_baptised == 'Y')
|
if ($person->booking_baptised == 'Y')
|
||||||
$baptised_count++;
|
$baptised_count++;
|
||||||
@@ -72,10 +77,8 @@ function booking_report_summary() {
|
|||||||
$married_count++;
|
$married_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//calculate the average age timestamp
|
|
||||||
$average = $dob_total / $person_count;
|
|
||||||
//convert that to years
|
//convert that to years
|
||||||
$average_age = floor((time() - $average) / (60 * 60 * 24 * 365.25));
|
//$average_age = floor((time() - $average) / (60 * 60 * 24 * 365.25));
|
||||||
|
|
||||||
//bookings by ecclesia
|
//bookings by ecclesia
|
||||||
$query = db_select('booking_person', 'p')
|
$query = db_select('booking_person', 'p')
|
||||||
@@ -113,11 +116,16 @@ function booking_report_summary() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//output everything
|
//output everything
|
||||||
$output .= t("<p>There are !boys males and !girls females registered. Of these, !baptised are baptised and !married are married. The average age is !average years.",
|
$output .= t("<h3>General Statistics</h3>");
|
||||||
|
$output .= t("<p>There are !boys males and !girls females registered. Of these, !baptised are baptised and !married are married.<br />",
|
||||||
array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count
|
array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count
|
||||||
'!average' => $average_age));
|
));
|
||||||
$output .= t("Total of !bookedin registrations currently booked in, !waiting on waiting list, and !notpaid haven't paid.<br />",
|
$output .= t("The overall average age at the start of the week will be !average. The male average age will be !maleaverage. The female average age will be !femaleaverage.<br />",
|
||||||
array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter));
|
array('!average' => _booking_avg_age($dob_total, $person_count, $event->booking_event_start), '!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start),
|
||||||
|
'!femaleaverage' => _booking_avg_age($female_dob_total, $female_count, $event->booking_event_start)
|
||||||
|
));
|
||||||
|
$output .= t("There are !bookedin registrations currently booked in, !waiting on waiting list, and !notpaid haven't paid, which comes to a total of !total people who have filled in the registration form.<br />",
|
||||||
|
array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter, '!total' => $person_count));
|
||||||
$output .= t("Total amount paid: $!paid</p>", array('!paid' => $total_paid));
|
$output .= t("Total amount paid: $!paid</p>", array('!paid' => $total_paid));
|
||||||
$output .= t("<h3>Bookings by state</h3>");
|
$output .= t("<h3>Bookings by state</h3>");
|
||||||
$output .= theme('table', array('header' => $state_header, 'rows' => $state_rows, 'attributes' => $stats_attributes));
|
$output .= theme('table', array('header' => $state_header, 'rows' => $state_rows, 'attributes' => $stats_attributes));
|
||||||
|
Reference in New Issue
Block a user