More analytics for bookings by state
This commit is contained in:
@@ -59,36 +59,58 @@ function booking_report_summary() {
|
|||||||
$header[] = array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required');
|
$header[] = array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required');
|
||||||
$header[] = array('data' => t('Committee?'), 'field' => 'booking_committee_member');
|
$header[] = array('data' => t('Committee?'), 'field' => 'booking_committee_member');
|
||||||
$rows = array();
|
$rows = array();
|
||||||
$state_header = array('State', 'Count');
|
|
||||||
|
//the state summary table
|
||||||
|
$state_header = array('State', 'Count', 'Males', 'Male Average Age', 'Females', 'Female Average Age', 'Overall Average Age', 'Baptised');
|
||||||
$state_rows = array();
|
$state_rows = array();
|
||||||
$ecclesia_header = array('State','Ecclesia', 'Count');
|
$state_statistics = array();
|
||||||
$ecclesia_rows = array();
|
|
||||||
|
|
||||||
//do some analysis about the people booked in
|
//do some analysis about the people booked in
|
||||||
//first the summary of states
|
//first the summary of states
|
||||||
$query = db_select('booking_person', 'p')
|
$query = db_select('booking_person', 'p')
|
||||||
->fields('p', array('booking_state', 'booking_country'));
|
->fields('p', array('booking_state', 'booking_country'));
|
||||||
|
//include people either booked in or on the waiting list, that belong to the current event id
|
||||||
$db_or = db_or();
|
$db_or = db_or();
|
||||||
$db_or->condition('p.booking_status', 1, '=');
|
$db_or->condition('p.booking_status', 1, '=');
|
||||||
$db_or->condition('p.booking_status', 2, '=');
|
$db_or->condition('p.booking_status', 2, '=');
|
||||||
$db_and = db_and()->condition($db_or)->condition('p.booking_event_id', $event->eid, '=');
|
$db_and = db_and()->condition($db_or)->condition('p.booking_event_id', $event->eid, '=');
|
||||||
$query->condition($db_and);
|
$query->condition($db_and);
|
||||||
|
|
||||||
$query->groupBy('p.booking_state');
|
$query->groupBy('p.booking_state');
|
||||||
$query->addExpression('COUNT(p.booking_state)', 'state_count');
|
$query->addExpression('COUNT(p.booking_state)', 'state_count');
|
||||||
$query->orderBy('state_count', 'DESC');
|
$query->orderBy('state_count', 'DESC');
|
||||||
$state_stats = $query->execute();
|
$state_stats = $query->execute();
|
||||||
|
|
||||||
|
//TODO: add some info to a hash so we can calculate age info and generate the actual rows after the more detailed summary loop
|
||||||
|
//include count of guys, girls, minimum, maximum and average ages
|
||||||
foreach ($state_stats as $state) {
|
foreach ($state_stats as $state) {
|
||||||
if (strcmp($state->booking_country,'Australia') == 0 )
|
if (strcmp($state->booking_country,'Australia') == 0 ) {
|
||||||
$state_rows[] = array($state->booking_state, $state->state_count);
|
//$state_rows[] = array($state->booking_state, $state->state_count);
|
||||||
else
|
//store the total count for this state
|
||||||
|
$state_statistics[$state->booking_state]->total_count = $state->state_count;
|
||||||
|
$state_statistics[$state->booking_state]->male_count = 0;
|
||||||
|
$state_statistics[$state->booking_state]->male_avg = 0;
|
||||||
|
$state_statistics[$state->booking_state]->female_count = 0;
|
||||||
|
$state_statistics[$state->booking_state]->female_avg = 0;
|
||||||
|
$state_statistics[$state->booking_state]->total_avg = 0;
|
||||||
|
$state_statistics[$state->booking_state]->baptised_count = 0;
|
||||||
|
} else {
|
||||||
$non_australia_count += $state->state_count;
|
$non_australia_count += $state->state_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//non australian states
|
//non australian states
|
||||||
$state_rows[] = array('International', $non_australia_count);
|
//$state_rows[] = array('International', $non_australia_count);
|
||||||
|
$state_statistics['International']->total_count = $non_australia_count;
|
||||||
|
$state_statistics['International']->male_count = 0;
|
||||||
|
$state_statistics['International']->male_avg = 0;
|
||||||
|
$state_statistics['International']->female_count = 0;
|
||||||
|
$state_statistics['International']->female_avg = 0;
|
||||||
|
$state_statistics['International']->total_avg = 0;
|
||||||
|
$state_statistics['International']->baptised_count = 0;
|
||||||
|
|
||||||
|
//the ecclesia summary table
|
||||||
|
$ecclesia_header = array('State','Ecclesia', 'Count');
|
||||||
|
$ecclesia_rows = array();
|
||||||
|
|
||||||
//bookings by ecclesia
|
//bookings by ecclesia
|
||||||
$query = db_select('booking_person', 'p')
|
$query = db_select('booking_person', 'p')
|
||||||
->fields('p', array('booking_ecclesia','booking_state'))
|
->fields('p', array('booking_ecclesia','booking_state'))
|
||||||
@@ -168,7 +190,6 @@ function booking_report_summary() {
|
|||||||
{
|
{
|
||||||
$total_refunds += $person->booking_refund_due;
|
$total_refunds += $person->booking_refund_due;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//travel form completed?
|
//travel form completed?
|
||||||
if (! empty($person->tid))
|
if (! empty($person->tid))
|
||||||
@@ -200,29 +221,48 @@ function booking_report_summary() {
|
|||||||
|
|
||||||
$person_count++;
|
$person_count++;
|
||||||
|
|
||||||
|
$state = strcmp($person->booking_country,'Australia') == 0 ? $person->booking_state : 'International';
|
||||||
|
|
||||||
//general stats for booked in people
|
//general stats for booked in people
|
||||||
if ($person->booking_status == 1)
|
if ($person->booking_status == 1) {
|
||||||
{
|
//for overall average age
|
||||||
$dob_total += $person->booking_dob;
|
$dob_total += $person->booking_dob;
|
||||||
|
|
||||||
|
//store data for average ages per gender and state
|
||||||
if ($person->booking_gender == 'M')
|
if ($person->booking_gender == 'M')
|
||||||
{
|
{
|
||||||
$male_count++;
|
$male_count++;
|
||||||
$male_dob_total += $person->booking_dob;
|
$male_dob_total += $person->booking_dob;
|
||||||
}
|
$state_statistics[$state]->male_avg += $person->booking_dob;
|
||||||
else
|
$state_statistics[$state]->male_count++;
|
||||||
{
|
} else {
|
||||||
$female_count++;
|
$female_count++;
|
||||||
$female_dob_total += $person->booking_dob;
|
$female_dob_total += $person->booking_dob;
|
||||||
|
$state_statistics[$state]->female_avg += $person->booking_dob;
|
||||||
|
$state_statistics[$state]->female_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($person->booking_baptised == 'Y')
|
if ($person->booking_baptised == 'Y') {
|
||||||
$baptised_count++;
|
$baptised_count++;
|
||||||
|
$state_statistics[$state]->baptised_count++;
|
||||||
|
}
|
||||||
|
|
||||||
if ($person->booking_married == 'Y')
|
if ($person->booking_married == 'Y')
|
||||||
$married_count++;
|
$married_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//generate the table for state statistics
|
||||||
|
foreach ($state_statistics as $key => $value) {
|
||||||
|
//$state_rows[] = array($state, $state->total_count, $state->male_count, $state->female_count, 0);
|
||||||
|
$male_average_age = _booking_avg_age($value->male_avg, $value->male_count, $event->booking_event_start);
|
||||||
|
$female_average_age = _booking_avg_age($value->female_avg, $value->female_count, $event->booking_event_start);
|
||||||
|
$state_average_age = _booking_avg_age($value->female_avg + $value->male_avg, $value->female_count + $value->male_count, $event->booking_event_start);
|
||||||
|
|
||||||
|
$data = array($key, $value->total_count, $value->male_count, $male_average_age, $value->female_count, $female_average_age, $state_average_age, $value->baptised_count);
|
||||||
|
//watchdog('booking', "<pre>State statistics:\n@info</pre>", array('@info' => print_r( $data, true)));
|
||||||
|
$state_rows[] = $data;
|
||||||
|
}
|
||||||
|
|
||||||
//output everything
|
//output everything
|
||||||
$output .= t("<h2>General Statistics</h2>");
|
$output .= t("<h2>General Statistics</h2>");
|
||||||
@@ -246,7 +286,7 @@ function booking_report_summary() {
|
|||||||
));
|
));
|
||||||
$output .= t("Total amount paid: $!paid, minus $!refunds in refunds.</p>", array('!paid' => $total_paid, '!refunds' => $total_refunds));
|
$output .= t("Total amount paid: $!paid, minus $!refunds in refunds.</p>", array('!paid' => $total_paid, '!refunds' => $total_refunds));
|
||||||
$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));
|
||||||
$output .= t("<h3>Bookings by ecclesia</h3>");
|
$output .= t("<h3>Bookings by ecclesia</h3>");
|
||||||
$output .= theme('table', array('header' => $ecclesia_header, 'rows' => $ecclesia_rows, 'attributes' => $stats_attributes));
|
$output .= theme('table', array('header' => $ecclesia_header, 'rows' => $ecclesia_rows, 'attributes' => $stats_attributes));
|
||||||
$output .= t("<h3>Summary of attendees for !event.</h3>", array('!event' => $event->booking_eventname));
|
$output .= t("<h3>Summary of attendees for !event.</h3>", array('!event' => $event->booking_eventname));
|
||||||
|
Reference in New Issue
Block a user