forked from HPR/hpr_hub
		
	Simplified and flattened the stats to json only
This commit is contained in:
		
							
								
								
									
										394
									
								
								cms/stats.php
									
									
									
									
									
								
							
							
						
						
									
										394
									
								
								cms/stats.php
									
									
									
									
									
								
							@@ -1,343 +1,133 @@
 | 
			
		||||
<?php
 | 
			
		||||
require "/home/hpr/php/include.php";
 | 
			
		||||
 | 
			
		||||
$format="json";
 | 
			
		||||
 | 
			
		||||
if (isset($_GET['format'])){
 | 
			
		||||
    if ($_GET['format'] === "txt") {
 | 
			
		||||
        $format="txt";
 | 
			
		||||
    }
 | 
			
		||||
    if ($_GET['format'] === "json") {
 | 
			
		||||
        $format="json";
 | 
			
		||||
    }
 | 
			
		||||
    if ($_GET['format'] === "xml") {
 | 
			
		||||
        $format="xml";
 | 
			
		||||
    }
 | 
			
		||||
    if ($_GET['format'] === "csv") {
 | 
			
		||||
        $format="csv";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
date_default_timezone_set('UTC');
 | 
			
		||||
 | 
			
		||||
$current_time = time();
 | 
			
		||||
$total_twt_shows = 300;
 | 
			
		||||
$twt_startdate = abs(strtotime(date("c")) - strtotime("2005-09-19T00:00:00Z"));
 | 
			
		||||
$twt_years = floor($twt_startdate / (365*60*60*24));
 | 
			
		||||
$twt_months = floor(($twt_startdate - $twt_years * 365*60*60*24) / (30*60*60*24));
 | 
			
		||||
$twt_days = floor(($twt_startdate - $twt_years * 365*60*60*24 - $twt_months*30*60*60*24)/ (60*60*24));
 | 
			
		||||
$agetwt = $twt_startdate;
 | 
			
		||||
 | 
			
		||||
$hpr_startdate = abs(strtotime(date("c")) - strtotime("2007-12-31T00:00:00Z"));
 | 
			
		||||
$hpr_years = floor($hpr_startdate / (365*60*60*24));
 | 
			
		||||
$hpr_months = floor(($hpr_startdate - $hpr_years * 365*60*60*24) / (30*60*60*24));
 | 
			
		||||
$hpr_days = floor(($hpr_startdate - $hpr_years * 365*60*60*24 - $hpr_months*30*60*60*24)/ (60*60*24));
 | 
			
		||||
$agehpr = $hpr_startdate;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
$last_show = mysqli_query($connection, "SELECT max(date), max(id) from eps");
 | 
			
		||||
$last_show_date = mysqli_fetch_row($last_show);
 | 
			
		||||
$twt_duration = 232812;
 | 
			
		||||
$start_date_twt = "2005-09-19";
 | 
			
		||||
$rename_date_hpr = "2007-12-31";
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Reserve Shows
 | 
			
		||||
// Get the number of published 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);
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Get total number of shows
 | 
			
		||||
 | 
			
		||||
$ep_retrieve = "SELECT id, COUNT(*) AS total_hpr_shows FROM eps ;";
 | 
			
		||||
$ep_retrieve = "SELECT max(date) as latest_episode_release_date, max(id) as latest_episode_id from eps WHERE eps.date <= UTC_DATE();";
 | 
			
		||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
 | 
			
		||||
  $data=mysqli_fetch_assoc($result);
 | 
			
		||||
  $total_hpr_shows = $data['total_hpr_shows'];
 | 
			
		||||
  $latest_episode_release_date = $data['latest_episode_release_date'];
 | 
			
		||||
  $latest_episode_id = intval( $data['latest_episode_id'] );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Shows in the Future Feed 
 | 
			
		||||
 | 
			
		||||
$ep_retrieve = "SELECT COUNT( DISTINCT id ) as num_future_shows FROM eps WHERE eps.date > UTC_DATE() AND duration <> 0";
 | 
			
		||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
 | 
			
		||||
  $data=mysqli_fetch_assoc($result);
 | 
			
		||||
  $num_future_shows = intval( $data['num_future_shows'] );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Shows in the Reserve Queue
 | 
			
		||||
 | 
			
		||||
$ep_retrieve = "SELECT COUNT(*) as num_reserve_shows FROM reservations WHERE status='RESERVE_SHOW_SUBMITTED'";
 | 
			
		||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
 | 
			
		||||
  $data=mysqli_fetch_assoc($result);
 | 
			
		||||
  $num_reserve_shows = intval( $data['num_reserve_shows'] );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Get the number of hosts
 | 
			
		||||
 | 
			
		||||
$ep_retrieve = "SELECT hostid FROM hosts WHERE valid = '1' ORDER BY hostid ASC";
 | 
			
		||||
$num_of_hosts = "1";
 | 
			
		||||
$ep_retrieve = "SELECT COUNT( DISTINCT hostid ) as num_hosts FROM hosts WHERE valid = '1'";
 | 
			
		||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
 | 
			
		||||
    while ($row = mysqli_fetch_array($result)) {
 | 
			
		||||
        $hostid = $row['hostid'];
 | 
			
		||||
        $last_show = mysqli_query($connection, "SELECT max(date) from eps WHERE hostid='$hostid' AND valid = '1'");
 | 
			
		||||
        $last_show_date = mysqli_fetch_row($last_show);
 | 
			
		||||
        if (!empty($last_show_date[0])) {
 | 
			
		||||
          $num_of_hosts++;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
  $data=mysqli_fetch_assoc($result);
 | 
			
		||||
  $num_hosts = intval( $data['num_hosts'] );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Get first free slot
 | 
			
		||||
// Get the next free slot
 | 
			
		||||
 | 
			
		||||
$query = mysqli_query($connection, "SELECT  id + 1 FROM eps mo
 | 
			
		||||
WHERE   NOT EXISTS
 | 
			
		||||
        (
 | 
			
		||||
        SELECT  NULL
 | 
			
		||||
        FROM    eps mi 
 | 
			
		||||
        WHERE   mi.id = mo.id + 1
 | 
			
		||||
        )
 | 
			
		||||
ORDER BY
 | 
			
		||||
        id
 | 
			
		||||
LIMIT 1");
 | 
			
		||||
$next_show_num_array = mysqli_fetch_row($query);
 | 
			
		||||
$next_show_num = $next_show_num_array[0];
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Get latest published show
 | 
			
		||||
 | 
			
		||||
$query = mysqli_query($connection, "SELECT max(date), max(id) from eps WHERE eps.date <= UTC_DATE()");
 | 
			
		||||
$current_episode_array = mysqli_fetch_row($query);
 | 
			
		||||
$current_episode_date = $current_episode_array[0];
 | 
			
		||||
$current_episode_number = $current_episode_array[1];
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Populate array with future shows
 | 
			
		||||
$un_delivered = -1;
 | 
			
		||||
$days_to_undelivered = 0;
 | 
			
		||||
$show_array = array ();
 | 
			
		||||
$ep_retrieve = "SELECT hosts.host, eps.id, eps.title, eps.date FROM eps, hosts WHERE eps.valid=1 AND eps.hostid = hosts.hostid AND eps.date >= '$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_playtime FROM `eps`");
 | 
			
		||||
$data=mysqli_fetch_assoc($result);
 | 
			
		||||
$total_playtime = $data['total_playtime'];
 | 
			
		||||
$human_total_playtime = convertSecToTime($total_playtime);
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// 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\"
 | 
			
		||||
    },";
 | 
			
		||||
$next_free_slot = "https://repo.anhonesthost.net/HPR/hpr_hub/issues/71";
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// playtime
 | 
			
		||||
$result=mysqli_query($connection, "SELECT SUM(duration) as total_playtime FROM `eps`");
 | 
			
		||||
$data=mysqli_fetch_assoc($result);
 | 
			
		||||
$total_playtime = $data['total_playtime'];
 | 
			
		||||
$human_total_playtime = convertSecToTime($total_playtime);
 | 
			
		||||
$ep_retrieve = "SELECT SUM(duration) as total_playtime_all_hpr_shows_seconds FROM `eps`";
 | 
			
		||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
 | 
			
		||||
  $data=mysqli_fetch_assoc($result);
 | 
			
		||||
  $total_playtime_all_hpr_shows_seconds = intval( $data['total_playtime_all_hpr_shows_seconds'] );
 | 
			
		||||
  $total_playtime_all_shows_seconds = $twt_duration + $total_playtime_all_hpr_shows_seconds;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$total_playtime_all_shows_human_readable = convertSecToTime( $total_playtime_all_shows_seconds );
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Unprocessed comments
 | 
			
		||||
$comment_directory = "/home/hpr/comments";
 | 
			
		||||
// Comments
 | 
			
		||||
 | 
			
		||||
$unprocessed_comments = iterator_count(new FilesystemIterator("$comment_directory", FilesystemIterator::SKIP_DOTS));
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Shows on the FTP server
 | 
			
		||||
// Calculations
 | 
			
		||||
 | 
			
		||||
$new_shows=0;
 | 
			
		||||
if ($handle = opendir('/home/hpr/upload')) {
 | 
			
		||||
  while (false !== ($entry = readdir($handle))) {
 | 
			
		||||
    if ( $entry != "." && $entry != "..") {
 | 
			
		||||
      $new_shows++;
 | 
			
		||||
    }
 | 
			
		||||
$total_released_shows = $latest_episode_id + $total_twt_shows;
 | 
			
		||||
$total_submitted_shows = $latest_episode_id + $total_twt_shows + $num_future_shows + $num_reserve_shows;
 | 
			
		||||
 | 
			
		||||
$project_age_seconds = strtotime( $start_date_twt ) - $current_time;
 | 
			
		||||
$project_age =  convertSecToTime( $project_age_seconds );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Display the workflow
 | 
			
		||||
 | 
			
		||||
$workflow = array();
 | 
			
		||||
 | 
			
		||||
$ep_retrieve = "SELECT status, COUNT(*) AS total FROM reservations WHERE status != 'RESERVE_SHOW_SUBMITTED' GROUP BY status;";
 | 
			
		||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
 | 
			
		||||
  while ($row = mysqli_fetch_array($result)) {
 | 
			
		||||
    $workflow[ $row['status'] ] = $row['total'];
 | 
			
		||||
  }
 | 
			
		||||
  closedir($handle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Calculate Total Shows
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
$total_shows = $current_episode_number + $total_twt_shows + $num_future_shows + $reserve_shows;
 | 
			
		||||
// Shows in the Reserve Queue
 | 
			
		||||
 | 
			
		||||
$ep_retrieve = "SELECT COUNT(*) AS num_unprocessed_shows FROM reservations WHERE status!='RESERVE_SHOW_SUBMITTED' AND status!='REQUEST_UNVERIFIED'";
 | 
			
		||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
 | 
			
		||||
  $data=mysqli_fetch_assoc($result);
 | 
			
		||||
  $num_unprocessed_shows = intval( $data['num_unprocessed_shows'] );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------
 | 
			
		||||
// Produce output
 | 
			
		||||
// Display the results
 | 
			
		||||
 | 
			
		||||
$current_time = time();
 | 
			
		||||
$arr = array(
 | 
			
		||||
  'stats_generated' => $current_time,
 | 
			
		||||
  'start_date_twt' => $start_date_twt,
 | 
			
		||||
  'rename_date_hpr' => $rename_date_hpr,
 | 
			
		||||
  'latest_episode_release_date' => $latest_episode_release_date,
 | 
			
		||||
  'project_age' => $project_age,
 | 
			
		||||
  'latest_episode_id' => $latest_episode_id,
 | 
			
		||||
  'total_twt_shows' => $total_twt_shows,
 | 
			
		||||
  'total_released_shows' => $total_released_shows,
 | 
			
		||||
  'num_future_shows' => $num_future_shows,
 | 
			
		||||
  'num_reserve_shows' => $num_reserve_shows,
 | 
			
		||||
  'total_submitted_shows' => $total_submitted_shows,
 | 
			
		||||
  'num_hosts' => $num_hosts,
 | 
			
		||||
  'days_to_next_free_slot' => "todo",
 | 
			
		||||
  'total_playtime_all_shows_seconds' => $total_playtime_all_shows_seconds,
 | 
			
		||||
  'total_playtime_all_shows_human_readable' => $total_playtime_all_shows_human_readable,
 | 
			
		||||
  'next_free_slot' => $next_free_slot,
 | 
			
		||||
  'unprocessed_comments' => $unprocessed_comments,
 | 
			
		||||
  'num_unprocessed_shows' => $num_unprocessed_shows,
 | 
			
		||||
  'show_processing_workflow' => $workflow
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
header('Content-Type: application/json');
 | 
			
		||||
header("Content-disposition: inline; filename=hpr_stats.json");
 | 
			
		||||
 | 
			
		||||
echo json_encode($arr);
 | 
			
		||||
 | 
			
		||||
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\": ".$agetwt.",
 | 
			
		||||
            \"years\": ".$twt_years.",
 | 
			
		||||
            \"months\": ".$twt_months.",
 | 
			
		||||
            \"days\": ".$twt_days."
 | 
			
		||||
        },
 | 
			
		||||
        \"since_rename\": {
 | 
			
		||||
            \"total_seconds\": ".$agehpr.",
 | 
			
		||||
            \"years\": ".$hpr_years.",
 | 
			
		||||
            \"months\": ".$hpr_months.",
 | 
			
		||||
            \"days\": ".$hpr_days."
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    \"shows\": {
 | 
			
		||||
        \"total\": ".$total_shows.",
 | 
			
		||||
        \"twt\": $total_twt_shows,
 | 
			
		||||
        \"hpr\": ".$current_episode_number.",
 | 
			
		||||
        \"future\": ".$num_future_shows.",
 | 
			
		||||
        \"reserve\": ".$reserve_shows.",        
 | 
			
		||||
        \"playtime\": ".$total_playtime.",
 | 
			
		||||
        \"human_playtime\": \"".$human_total_playtime."\"
 | 
			
		||||
    },
 | 
			
		||||
    \"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 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
 | 
			
		||||
<stats>
 | 
			
		||||
  <stats_generated>".$current_time."</stats_generated>
 | 
			
		||||
  <age>
 | 
			
		||||
    <start>2005-09-19T00:00:00Z</start>
 | 
			
		||||
    <rename>2007-12-31T00:00:00Z</rename>
 | 
			
		||||
    <since_start>
 | 
			
		||||
      <total_seconds>".$agetwt."</total_seconds>
 | 
			
		||||
      <years>". $twt_years."</years>
 | 
			
		||||
      <months>".$twt_months."</months>
 | 
			
		||||
      <days>".$twt_days."</days>
 | 
			
		||||
    </since_start>
 | 
			
		||||
    <since_rename>
 | 
			
		||||
      <total_seconds>".$agehpr."</total_seconds>
 | 
			
		||||
      <years>".$hpr_years."</years>
 | 
			
		||||
      <months>".$hpr_months."</months>
 | 
			
		||||
      <days>".$hpr_days."</days>
 | 
			
		||||
    </since_rename>
 | 
			
		||||
  </age>
 | 
			
		||||
  <shows>
 | 
			
		||||
    <total>".$total_shows."</total>
 | 
			
		||||
    <twt>$total_twt_shows</twt>
 | 
			
		||||
    <hpr>".$total_hpr_shows."</hpr>
 | 
			
		||||
    <playtime>".$total_playtime."</playtime>
 | 
			
		||||
    <human_playtime>".$human_total_playtime."</human_playtime>
 | 
			
		||||
  </shows>
 | 
			
		||||
  <hosts>".$num_of_hosts."</hosts>
 | 
			
		||||
  <slot>
 | 
			
		||||
    <next_free>".$days_to_wait."</next_free>
 | 
			
		||||
    <no_media>".$un_delivered."</no_media>
 | 
			
		||||
  </slot>
 | 
			
		||||
  <queue>
 | 
			
		||||
    <number_future_hosts>".$num_future_hosts."</number_future_hosts>
 | 
			
		||||
    <number_future_shows>".$num_future_shows."</number_future_shows>
 | 
			
		||||
    <unprocessed_comments>".$unprocessed_comments."</unprocessed_comments>
 | 
			
		||||
    <submitted_shows>".$num_submitted_shows."</submitted_shows>
 | 
			
		||||
    <shows_in_workflow>".$new_shows."</shows_in_workflow>
 | 
			
		||||
    <reserve>".$reserve_shows."</reserve>
 | 
			
		||||
  </queue>
 | 
			
		||||
</stats>";
 | 
			
		||||
}
 | 
			
		||||
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_twt,shows_hpr,hosts,slot_next_free,slot_no_media,number_future_hosts,number_future_shows,unprocessed_comments,shows_in_workflow,queue_reserve,playtime\n";
 | 
			
		||||
    print "${current_time},2005-09-19T00:00:00Z,2007-12-31T00:00:00Z,${agetwt},${twt_years},${twt_months},${twt_days},${agehpr},${hpr_years},${hpr_months},${hpr_days},${totalshows},${total_twt_shows},${$total_hpr_shows},${num_of_hosts},${days_to_wait},${un_delivered},${num_future_hosts},${num_future_shows},${unprocessed_comments},${new_shows},${reserve_shows},${total_playtime}\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", $twt_years, $twt_months, $twt_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" . $total_shows . "\n";
 | 
			
		||||
    echo "Total TWAT:\t$total_twt_shows\n";
 | 
			
		||||
    echo "Total HPR:\t" . $total_hpr_shows . "\n";
 | 
			
		||||
    echo "Duration:\t" . $total_playtime . "\n";
 | 
			
		||||
    echo "Human Duration:\t" . $human_total_playtime . "\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,$agetwt,$agehpr,$total_shows,$total_twt_shows,$total_hpr_shows,$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);
 | 
			
		||||
?>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user