Adding stats and automating update. Check for url in uploads
This commit is contained in:
parent
da88c1afc4
commit
c44a6f0f04
@ -16,6 +16,16 @@ do
|
||||
echo "ERROR: \"${shownotes}\" not found"
|
||||
exit 1
|
||||
fi
|
||||
metadata_url="$( jq --raw-output '.metadata.url' "${shownotes}" )"
|
||||
if [ -n "${metadata_url}" ]
|
||||
then
|
||||
save_name=$( basename "${metadata_url}" | sed -e 's/[^A-Za-z0-9.]/_/g' -e 's/__/_/g' )
|
||||
if [ ! -s "${reserve_show_dir}/${save_name}" ]
|
||||
then
|
||||
echo "ERROR: \"${metadata_url}\" needs to be downloaded as \"${reserve_show_dir}/${save_name}\""
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
Host_ID="$( jq --raw-output '.host.Host_ID' "${shownotes}" )"
|
||||
Host_Name="$( jq --raw-output '.host.Host_Name' "${shownotes}" | sed -e 's/[^A-Za-z0-9]/_/g' -e 's/__/_/g' )"
|
||||
Key="$( jq --raw-output '.metadata.Key' "${shownotes}" )"
|
||||
|
8
bin/update-stats.bash
Normal file
8
bin/update-stats.bash
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
hub_dir="/home/hpr/hub"
|
||||
|
||||
for format in txt csv json xml
|
||||
do
|
||||
curl --silent --netrc-file /home/hpr/.netrc https://hub.hackerpublicradio.org/cms/stats.php?format=${format} --output ${hub_dir}/stats.${format}
|
||||
done
|
@ -1,7 +1,12 @@
|
||||
<?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";
|
||||
}
|
||||
@ -26,8 +31,8 @@ $hpr_days = floor(($hpr_startdate - $hpr_years * 365*60*60*24 - $hpr_months*30*6
|
||||
$agehpr = $hpr_startdate;
|
||||
|
||||
|
||||
$last_show = mysql_query("SELECT max(date), max(id) from eps");
|
||||
$last_show_date = mysql_fetch_row($last_show);
|
||||
$last_show = mysqli_query($connection, "SELECT max(date), max(id) from eps");
|
||||
$last_show_date = mysqli_fetch_row($last_show);
|
||||
$totalshows=$last_show_date[1]+300;
|
||||
$totalhpr=$last_show_date[1];
|
||||
|
||||
@ -36,11 +41,11 @@ $totalhpr=$last_show_date[1];
|
||||
|
||||
$ep_retrieve = "SELECT hostid FROM hosts WHERE valid = '1' ORDER BY hostid ASC";
|
||||
$num_of_hosts = "1";
|
||||
if ($result = mysql_query($ep_retrieve)) {
|
||||
while ($row = mysql_fetch_array($result)) {
|
||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
|
||||
while ($row = mysqli_fetch_array($result)) {
|
||||
$hostid = $row['hostid'];
|
||||
$last_show = mysql_query("SELECT max(date) from eps WHERE hostid='$hostid' AND valid = '1'");
|
||||
$last_show_date = mysql_fetch_row($last_show);
|
||||
$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++;
|
||||
}
|
||||
@ -50,7 +55,7 @@ if ($result = mysql_query($ep_retrieve)) {
|
||||
// --------------------------------------------
|
||||
// Get first free slot
|
||||
|
||||
$query = mysql_query("SELECT id + 1 FROM eps mo
|
||||
$query = mysqli_query($connection, "SELECT id + 1 FROM eps mo
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT NULL
|
||||
@ -60,14 +65,14 @@ WHERE NOT EXISTS
|
||||
ORDER BY
|
||||
id
|
||||
LIMIT 1");
|
||||
$next_show_num_array = mysql_fetch_row($query);
|
||||
$next_show_num_array = mysqli_fetch_row($query);
|
||||
$next_show_num = $next_show_num_array[0];
|
||||
|
||||
// --------------------------------------------
|
||||
// Get latest published show
|
||||
|
||||
$query = mysql_query("SELECT max(date), max(id) from eps WHERE eps.date <= UTC_DATE()");
|
||||
$current_episode_array = mysql_fetch_row($query);
|
||||
$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];
|
||||
|
||||
@ -77,8 +82,8 @@ $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 = mysql_query($ep_retrieve)) {
|
||||
while ($row = mysql_fetch_array($result)) {
|
||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
|
||||
while ($row = mysqli_fetch_array($result)) {
|
||||
$id = $row['id'];
|
||||
$id = fixid($id);
|
||||
$date = $row['date'];
|
||||
@ -113,8 +118,8 @@ $days_to_wait = floor((strtotime($next_show_date) - strtotime(gmdate('Y-m-d')))/
|
||||
$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 = mysql_query($ep_retrieve)) {
|
||||
$num_future_hosts = mysql_num_rows($result);
|
||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
|
||||
$num_future_hosts = mysqli_num_rows($result);
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
@ -122,20 +127,56 @@ if ($result = mysql_query($ep_retrieve)) {
|
||||
$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 = mysql_query($ep_retrieve)) {
|
||||
$num_future_shows = mysql_num_rows($result);
|
||||
if ($result = mysqli_query($connection, $ep_retrieve)) {
|
||||
$num_future_shows = mysqli_num_rows($result);
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
// Shows in the Queue
|
||||
$result=mysql_query("SELECT count(*) as total FROM `reservations` WHERE `status` LIKE 'SHOW_SUBMITTED' ORDER BY `ip` ASC ");
|
||||
$data=mysql_fetch_assoc($result);
|
||||
$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=mysql_query("SELECT SUM(duration) as total_duration FROM `eps`");
|
||||
$data=mysql_fetch_assoc($result);
|
||||
$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);
|
||||
|
||||
@ -158,9 +199,8 @@ if ($handle = opendir('/home/hpr/upload')) {
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
// Emergency Shows
|
||||
// Produce output
|
||||
|
||||
$emergency_shows = count(glob('/home/hpr/www/emergency/*.ogg'));
|
||||
$current_time = time();
|
||||
|
||||
if ($format === "json") {
|
||||
@ -196,13 +236,14 @@ if ($format === "json") {
|
||||
\"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.",
|
||||
\"emergency\": ".$emergency_shows."
|
||||
\"reserve\": ".$reserve_shows."
|
||||
}
|
||||
}
|
||||
";
|
||||
@ -247,7 +288,7 @@ elseif ($format === "xml") {
|
||||
<unprocessed_comments>".$unprocessed_comments."</unprocessed_comments>
|
||||
<submitted_shows>".$num_submitted_shows."</submitted_shows>
|
||||
<shows_in_workflow>".$new_shows."</shows_in_workflow>
|
||||
<emergency>".$emergency_shows."</emergency>
|
||||
<reserve>".$reserve_shows."</reserve>
|
||||
</queue>
|
||||
</stats>";
|
||||
}
|
||||
@ -255,8 +296,8 @@ 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_emergency,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},${emergency_shows},${total_duration}\n";
|
||||
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 {
|
||||
@ -275,10 +316,10 @@ else {
|
||||
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 Emergency Shows:\t$emergency_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,$emergency_shows,$un_delivered";
|
||||
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);
|
||||
}
|
||||
mysql_close();
|
||||
mysqli_close($connection);
|
||||
?>
|
Loading…
Reference in New Issue
Block a user