Ticket #1583: mythweb-stats.patch

File mythweb-stats.patch, 9.3 KB (added by Rob Smith, 15 years ago)

mythweb stats patch

  • themes/default/stats/welcome.php

     
     1<?php
     2/**
     3 * Welcome page description of the status module.
     4 *
     5 * @url         $URL: http://svn.mythtv.org/svn/trunk/mythplugins/mythweb/themes/default/status/welcome.php $
     6 * @date        $Date: 2005-12-12 23:23:18 -0800 (Mon, 12 Dec 2005) $
     7 * @version     $Revision: 8252 $
     8 * @author      $Author: xris $
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 *
     13/**/
     14
     15// Open with a div and an image
     16    echo '<div id="info_stats" class="hidden">',
     17         '<img src="', skin_url, '/img/stats.png" class="module_icon" />',
     18
     19// Print a basic overview of what this module does
     20         t('welcome: stats'),
     21
     22// Close the div
     23         "</div>\n";
     24 No newline at end of file
  • themes/default/stats/stats.php

     
     1<?php
     2/**
     3 * The display code for the main welcome page that lists the available mythweb
     4 * sections.
     5 *
     6 * @url         $URL: http://svn.mythtv.org/svn/trunk/mythplugins/mythweb/themes/default/status/status.php $
     7 * @date        $Date: 2005-11-07 19:37:20 -0800 (Mon, 07 Nov 2005) $
     8 * @version     $Revision: 7792 $
     9 * @author      $Author: xris $
     10 * @license     GPL
     11 *
     12 * @package     MythWeb
     13 *
     14/**/
     15
     16// Set the desired page title
     17    $page_title = 'MythTV Statistics';
     18
     19// Custom headers
     20    $headers[] = '<link rel="stylesheet" type="text/css" href="'.skin_url.'/stats.css" />';
     21
     22// Print the page header
     23    require_once theme_dir.'/header.php';
     24
     25// Print the content itself
     26?>
     27
     28    <div id="content_wrapper">
     29        <center>
     30        <form id="query_time_form" name="query_time_form" action="<?php echo root ?>stats">
     31        <div id="count_div" style="position: absolute; top: 10em; left: 1em;">
     32                <select name="count_dropdown" onchange="submit_form(null, null, query_time_form);">
     33                        <option <?php if($_GET['count_dropdown']=='10') echo 'selected'; ?> value="10">Top 10</option>
     34                        <option <?php if($_GET['count_dropdown']=='25') echo 'selected'; ?> value="25">Top 25</option>
     35                        <option <?php if($_GET['count_dropdown']=='50') echo 'selected'; ?> value="50">Top 50</option>
     36                        <option <?php if($_GET['count_dropdown']=='100') echo 'selected'; ?> value="100">Top 100</option>
     37                        <option <?php if($_GET['count_dropdown']=='all') echo 'selected'; ?> value="all">All</option>
     38                </select>
     39        </div>
     40        <div id="query_time_dropdown" style="position: absolute; right: 1em; top: 10em;">
     41                <select name="query_time" onchange="submit_form(null, null, query_time_form);">
     42                    <option <?php if($_GET['query_time']=='All_time') echo 'selected'; ?> value="All_time">All</option>
     43                    <option <?php if($_GET['query_time']=='year') echo 'selected'; ?> value="year">Past Year</option>
     44                    <option <?php if($_GET['query_time']=='month') echo 'selected'; ?> value="month">Past Month</option>
     45                    <option <?php if($_GET['query_time']=='week') echo 'selected'; ?> value="week">Past Week</option>
     46                    <option <?php if($_GET['query_time']=='day') echo 'selected'; ?> value="day">Yesterday</option>
     47                </select>
     48        </div>
     49        </form>
     50        <h2>MythTV Statistics</h2>
     51        <br /><br />
     52        <div id="general_stats">
     53            Number of shows: <?php echo $title_count; ?><br />
     54            Number of epsodes: <?php echo $show_count; ?><br />
     55            First recording: <?php echo date('l jS \of F, Y', $first); ?><br />
     56            Last recording: <?php echo date('l jS \of F, Y', $last); ?><br />
     57            Total Time: <?php echo $time; ?> seconds ( <?php echo round($time/60/60/24, 2); ?> days) wasted<br />
     58        </div><br /><br />
     59        <table><tr><td>
     60            <table id="top_ten_shows" style="text-align: left;">
     61            <caption>Top <?php echo $_REQUEST['count_dropdown']; ?> recorded shows</caption>
     62            <tr><td>Title</td><td>Count</td><td>Last Recorded</td></tr>
     63            <?php
     64            foreach($top_ten_shows as $row)
     65                echo "<tr><td>".$row['title']."</td><td>".$row['cnt']."</td><td>".date('F j Y', $row['last_recorded'])."</td></tr>\n";
     66            ?>
     67            </table>
     68        </td><td>
     69            <table id="top_ten_chan" style="text-align: left;">
     70            <caption>Top <?php echo $_REQUEST['count_dropdown']; ?> recorded channels</caption>
     71            <tr><td>Name</td><td>Count</td><td>Last Recorded</td></tr>
     72            <?php
     73            foreach($top_ten_chans as $row)
     74                echo "<tr><td>".$row['name']."</td><td>".$row['cnt']."</td><td>".date('F j Y', $row['last_recorded'])."</td></tr>\n";
     75            ?>
     76            </table>
     77        </td></tr></table>
     78    </div>
     79<?php
     80// Print the page footer
     81    require_once theme_dir.'/footer.php';
     82
  • modules/stats/handler.php

     
     1<?php
     2/**
     3 * A straight passthrough for the mythbackend status web page (usually on
     4 * port 6544)
     5 *
     6 * @url         $URL$
     7 * @date        $Date: 2005-12-07 21:00:04 -0800 (Wed, 07 Dec 2005) $
     8 * @version     $Revision: 8171 $
     9 * @author      $Author: xris $
     10 * @license     GPL
     11 *
     12 * @package     MythWeb
     13 * @subpackage  Status
     14 *
     15/**/
     16    $where = ' WHERE true';
     17    if ($_REQUEST['query_time'] == 'day')
     18        $where = ' WHERE UNIX_TIMESTAMP(starttime) > '.(time()-24*60*60);
     19    if ($_REQUEST['query_time'] == 'week')
     20        $where = ' WHERE UNIX_TIMESTAMP(starttime) > '.(time()-7*24*60*60);
     21    if ($_REQUEST['query_time'] == 'month')
     22        $where = ' WHERE UNIX_TIMESTAMP(starttime) > '.(time()-31*24*60*60);
     23    if ($_REQUEST['query_time'] == 'year')
     24        $where = ' WHERE UNIX_TIMESTAMP(starttime) > '.(time()-365*24*60*60);
     25
     26    $limit = 'LIMIT 10';
     27    if($_REQUEST['count_dropdown'] == 25)
     28        $limit = 'LIMIT 25';
     29    if($_REQUEST['count_dropdown'] == 50)
     30        $limit = 'LIMIT 50';
     31    if($_REQUEST['count_dropdown'] == 100)
     32        $limit = 'LIMIT 100';
     33    if($_REQUEST['count_dropdown'] == 'all')
     34        $limit = '';
     35
     36
     37// Get how many show titles their are
     38    $sh = $db->query('SELECT DISTINCT title FROM oldrecorded'.$where);
     39    $title_count = $sh->num_rows();
     40    $sh->finish();
     41
     42// Get how many shows ever recorded
     43    $show_count = $db->query_col('SELECT COUNT(title) FROM oldrecorded '.$where.' AND oldrecorded.recstatus = -3');
     44
     45// Get the time of the first recording
     46    $first = $db->query_col('SELECT UNIX_TIMESTAMP(starttime) FROM oldrecorded '.$where.' AND oldrecorded.recstatus = -3 ORDER BY starttime ASC LIMIT 1');
     47
     48// Get the time of the last recording
     49    $last = $db->query_col('SELECT UNIX_TIMESTAMP(endtime) FROM oldrecorded '.$where.' AND oldrecorded.recstatus = -3 ORDER BY endtime DESC LIMIT 1');
     50
     51// Get the total time of the recorded shows
     52    $time = $db->query_col('SELECT SUM(UNIX_TIMESTAMP(endtime) - UNIX_TIMESTAMP(starttime)) FROM oldrecorded '.$where.' AND oldrecorded.recstatus = -3');
     53
     54// Get the top ten recorded shows
     55    $sh = $db->query('SELECT title, COUNT(programid) AS cnt, MAX(UNIX_TIMESTAMP(starttime)) AS last_recorded FROM oldrecorded '.$where.' AND recstatus = -3 GROUP BY title ORDER BY cnt DESC '.$limit);
     56    while($row = $sh->fetch_assoc())
     57        $top_ten_shows[] = $row;
     58    $sh->finish();
     59
     60// Get the top ten recorded shows
     61    $sh = $db->query('SELECT COUNT(oldrecorded.chanid) as cnt,
     62                             channel.name,
     63                             channel.channum,
     64                             MAX(UNIX_TIMESTAMP(oldrecorded.starttime)) as last_recorded
     65                        FROM oldrecorded
     66                             LEFT JOIN channel
     67                                    ON channel.chanid = oldrecorded.chanid
     68                    '.$where.'
     69                             AND channel.channum IS NOT NULL
     70                             AND oldrecorded.recstatus = -3
     71                    GROUP BY oldrecorded.chanid
     72                    ORDER BY cnt DESC
     73                    '.$limit);
     74    while($row = $sh->fetch_assoc())
     75        $top_ten_chans[] = $row;
     76    $sh->finish();
     77
     78// Print the stats page template
     79    require_once theme_dir.'/stats/stats.php';
     80
     81// Yup, that really is it.
     82    exit;
  • modules/stats/init.php

     
     1<?php
     2/**
     3 * Initialization routines for the MythWeb Status module
     4 *
     5 * @url         $URL: http://svn.mythtv.org/svn/trunk/mythplugins/mythweb/modules/status/init.php $
     6 * @date        $Date: 2005-12-15 22:55:02 -0800 (Thu, 15 Dec 2005) $
     7 * @version     $Revision: 8285 $
     8 * @author      $Author: xris $
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Stats
     13 *
     14/**/
     15
     16// The stats module is always enabled.
     17    $Modules['stats'] = array('path'        => 'stats',
     18                              'name'        => t('Statistics'),
     19                          );
     20