= '$current_episode_date' ORDER BY date DESC"; if ($result = mysqli_query($connection, $ep_retrieve)) { while ($row = mysqli_fetch_array($result)) { $id = $row['id']; $id = fixid($id); $date = $row['date']; $title = $row['title']; $host = $row['host']; if ( file_exists("./eps/hpr$id.ogg") and file_exists("./eps/hpr$id.spx") and file_exists("./eps/hpr$id.mp3") ) { $delivered = 1; if ($un_delivered === -1 ) { $days_to_undelivered++; } } else { $delivered = 0; $un_delivered = $days_to_undelivered; } $show_array[$id] = array ( "date" => $date, "title" => $title, "host" => $host, "delivered" => $delivered ); } } // -------------------------------------------- // Calculate the time to the next show $next_show_date = date('Y-m-d', strtotime($show_array[$next_show_num - 1 ]["date"] . ' + 1 weekday')); $days_to_wait = floor((strtotime($next_show_date) - strtotime(gmdate('Y-m-d')))/(60*60*24)); // -------------------------------------------- // Future Hosts $ep_retrieve = "SELECT DISTINCT hostid FROM eps WHERE eps.date > UTC_DATE()"; // $ep_retrieve = "SELECT id, type, date, title, notes, host, hostid FROM eps WHERE valid = '1' ORDER BY id DESC LIMIT 10"; if ($result = mysqli_query($connection, $ep_retrieve)) { $num_future_hosts = mysqli_num_rows($result); } // -------------------------------------------- // Shows in the Queue $ep_retrieve = "SELECT DISTINCT id FROM eps WHERE eps.date > UTC_DATE() AND duration <> 0"; // $ep_retrieve = "SELECT id, type, date, title, notes, host, hostid FROM eps WHERE valid = '1' ORDER BY id DESC LIMIT 10"; if ($result = mysqli_query($connection, $ep_retrieve)) { $num_future_shows = mysqli_num_rows($result); } // -------------------------------------------- // Shows in the Queue $result=mysqli_query($connection, "SELECT count(*) as total FROM `reservations` WHERE `status` LIKE 'SHOW_SUBMITTED' ORDER BY `ip` ASC "); $data=mysqli_fetch_assoc($result); $num_submitted_shows = $data['total']; // -------------------------------------------- // Duration of all shows $result=mysqli_query($connection, "SELECT SUM(duration) as total_duration FROM `eps`"); $data=mysqli_fetch_assoc($result); $total_duration = $data['total_duration']; $human_total_duration = convertSecToTime($total_duration); // -------------------------------------------- // Reserve Shows $result = mysqli_query($connection, 'SELECT COUNT(*) FROM reservations WHERE status="RESERVE_SHOW_SUBMITTED";'); if (!isset($result)) { naughty("cac33babd8a24edd138087ef7e4280f6"); } $reserve_array = mysqli_fetch_row( $result ); $reserve_shows = $reserve_array[0]; mysqli_free_result($result); // -------------------------------------------- // workflow $ep_retrieve = "SELECT status, COUNT(*) AS total FROM reservations WHERE status != 'RESERVE_SHOW_SUBMITTED' GROUP BY status;"; $workflow="\"workflow\": {"; if ($result = mysqli_query($connection, $ep_retrieve)) { while ($row = mysqli_fetch_array($result)) { $status = $row['status']; $total = $row['total']; $workflow=$workflow." \"$status\": \"$total\","; } } $workflow=$workflow." \"RESERVE_SHOW_SUBMITTED\": \"$reserve_shows\" },"; // -------------------------------------------- // duration $result=mysqli_query($connection, "SELECT SUM(duration) as total_duration FROM `eps`"); $data=mysqli_fetch_assoc($result); $total_duration = $data['total_duration']; $human_total_duration = convertSecToTime($total_duration); // -------------------------------------------- // Unprocessed comments $comment_directory = "/home/hpr/comments"; $unprocessed_comments = iterator_count(new FilesystemIterator("$comment_directory", FilesystemIterator::SKIP_DOTS)); // -------------------------------------------- // Shows on the FTP server $new_shows=0; if ($handle = opendir('/home/hpr/upload')) { while (false !== ($entry = readdir($handle))) { if ( $entry != "." && $entry != "..") { $new_shows++; } } closedir($handle); } // -------------------------------------------- // Produce output $current_time = time(); if ($format === "json") { header('Content-Type: application/json'); header("Content-disposition: inline; filename=hpr_stats.json"); echo "{ \"stats_generated\": ".$current_time.", \"age\": { \"start\": \"2005-09-19T00:00:00Z\", \"rename\": \"2007-12-31T00:00:00Z\", \"since_start\": { \"total_seconds\": ".$agetwat.", \"years\": ".$twat_years.", \"months\": ".$twat_months.", \"days\": ".$twat_days." }, \"since_rename\": { \"total_seconds\": ".$agehpr.", \"years\": ".$hpr_years.", \"months\": ".$hpr_months.", \"days\": ".$hpr_days." } }, \"shows\": { \"total\": ".$totalshows.", \"twat\": 300, \"hpr\": ".$totalhpr.", \"duration\": ".$total_duration.", \"human_duration\": \"".$human_total_duration."\" }, \"hosts\": ".$num_of_hosts.", \"slot\": { \"next_free\": ".$days_to_wait.", \"no_media\": ".$un_delivered." }, $workflow \"queue\": { \"number_future_hosts\": ".$num_future_hosts.", \"number_future_shows\": ".$num_future_shows.", \"unprocessed_comments\": ".$unprocessed_comments.", \"submitted_shows\": ".$num_submitted_shows.", \"shows_in_workflow\": ".$new_shows.", \"reserve\": ".$reserve_shows." } } "; } elseif ($format === "xml") { header("Content-type: application/xml"); header("Content-disposition: inline; filename=hpr_stats.xml"); echo " ".$current_time." 2005-09-19T00:00:00Z 2007-12-31T00:00:00Z ".$agetwat." ". $twat_years." ".$twat_months." ".$twat_days." ".$agehpr." ".$hpr_years." ".$hpr_months." ".$hpr_days." ".$totalshows." 300 ".$totalhpr." ".$total_duration." ".$human_total_duration." ".$num_of_hosts." ".$days_to_wait." ".$un_delivered." ".$num_future_hosts." ".$num_future_shows." ".$unprocessed_comments." ".$num_submitted_shows." ".$new_shows." ".$reserve_shows." "; } elseif ($format === "csv") { header("Content-type: text/csv"); header("Content-disposition: inline; filename=hpr_stats.csv"); print "stats_generated,age_start,age_rename,age_since_start_total_seconds,age_since_start_years,age_since_start_months,age_since_start_days,age_since_rename_total_seconds,age_since_rename_years,age_since_rename_months,age_since_rename_days,shows_total,shows_twat,shows_hpr,hosts,slot_next_free,slot_no_media,number_future_hosts,number_future_shows,unprocessed_comments,shows_in_workflow,queue_reserve,duration\n"; print "${current_time},2005-09-19T00:00:00Z,2007-12-31T00:00:00Z,${agetwat},${twat_years},${twat_months},${twat_days},${agehpr},${hpr_years},${hpr_months},${hpr_days},${totalshows},300,${totalhpr},${num_of_hosts},${days_to_wait},${un_delivered},${num_future_hosts},${num_future_shows},${unprocessed_comments},${new_shows},${reserve_shows},${total_duration}\n"; } else { Header('Content-type: text/tab-separated-values'); header("Content-disposition: inline; filename=hpr_stats.txt"); printf("Started:\t%d years, %d months, %d days ago (2005-09-19)\n", $twat_years, $twat_months, $twat_days); printf("Renamed HPR:\t%d years, %d months, %d days ago (2007-12-31)\n", $hpr_years, $hpr_months, $hpr_days); echo "Total Shows:\t" . $totalshows . "\n"; echo "Total TWAT:\t300\n"; echo "Total HPR:\t" . $totalhpr . "\n"; echo "Duration:\t" . $total_duration . "\n"; echo "Human Duration:\t" . $human_total_duration . "\n"; echo "HPR Hosts:\t${num_of_hosts}\n"; echo "Days to next free slot:\t${days_to_wait}\n"; echo "Hosts in Queue:\t$num_future_hosts\n"; echo "Shows in Queue:\t$num_future_shows\n"; echo "Comments waiting approval:\t$unprocessed_comments\n"; echo "Files on the FTP Server:\t$new_shows\n"; echo "Number of Reserve Shows:\t$reserve_shows\n"; echo "Days until show without media:\t$un_delivered\n"; print "$current_time,$agetwat,$agehpr,$totalshows,300,$totalhpr,$num_of_hosts,$days_to_wait,$num_future_hosts,$num_future_shows,$unprocessed_comments,$new_shows,$reserve_shows,$un_delivered"; // print_r($show_array); } mysqli_close($connection); ?>