Commits

Juliette Culver  committed 927349d

#192 Review and improve statistics interface - admins

https://bitbucket.org/cloudengine/cloudengine/issue/192/review-and-improve-statistics-interface

Additional stats based on conversation with Rebecca.
Also removed unused admin views with are duplicates of stats
views and possible cause of confusion

  • Participants
  • Parent commits ffa4ec2

Comments (0)

Files changed (10)

File _design/styles_1_1.css

 
 tr.even td {background:#FEF9E5;}
 
-
-
 /* Paged navigation ( < Prev 1 2 3 4 5 Next > )
 ----------------------------------------------------------------------------------- */
 

File system/application/controllers/statistics.php

 <?php
 /**
  * Controller for functionality related to site statistics 
- * @copyright 2009, 2010 The Open University. See CREDITS.txt
+ * @copyright 2009, 2010, 2012 The Open University. See CREDITS.txt
  * @license   http://gnu.org/licenses/gpl-2.0.html GNU GPL v2
  * @package Statistics
  */
         $data['embed_team_total']      = $this->statistics_model->get_total_embeds(true);        
 
         $data['title'] = 'Statistics';
-	    $this->layout->view('statistics/stats', $data);	    
+	    $this->layout->view('statistics/stats', $data);
 	}
 
 	/**
 	}
 
     /**
+     * Display site statistics related to users
+     */
+    function user_stats() {
+        ini_set('memory_limit','128M');
+        set_time_limit(900);
+        $data['user_total'] = $this->statistics_model->get_total_users(); 
+        $data['contrib']    = $this->statistics_model->get_user_contrib();
+        $data['contrib_last_60_days'] = 
+                        $this->statistics_model->get_user_contrib(time() - 60*24*60*60, time());        
+        $data['contrib_month_after_registration'] = 
+                        $this->statistics_model->get_user_contrib(false, false, 30*24*60*60);        
+        $data['contrib_year_after_registration'] = 
+                        $this->statistics_model->get_user_contrib(false, false, 365*24*60*60);        
+           
+        $data['title'] = 'Statistics';
+        $this->layout->view('statistics/user_stats', $data);
+    }
+    
+    /**
      * Show stats for a specified cloudscape
      * 
      */

File system/application/models/statistics_model.php

 /**
  * Functions related to site statistics
  * 
- * @copyright 2009, 2010 The Open University. See CREDITS.txt
+ * @copyright 2009, 2010, 2012 The Open University. See CREDITS.txt
  * @license   http://gnu.org/licenses/gpl-2.0.html GNU GPL v2
  * @package Statistics
  */
                         $this->get_cloudscape_cloud_visitors_guest($cloudscape_id, 0, time());
         
         return $cloudscape;
-    }  
+    } 
+
+   /**
+    * Get the total number of contributions that a user has made to the site
+    * where a contribution is a cloud, cloudscape, comment, link,
+    * reference, extra content or embed
+    * @param integer The id of the user 
+    * @param integer $start_timestamp Date before which contributions must have
+    * been made to be included in the count, as a Unix timestamp (optional, 
+    * if not set defaults to current time)
+    * @param integer $after_registration Period of time in seconds after the 
+    * user has registered on the site for contributions to have been made in in
+    * order to  be included in the count. (optional, if not set, no restrictions
+    * made based on registration date) If this is set then $end_timestamp is 
+    * ignored
+    * @param integer The number of contributions 
+    */
+    function get_number_contributions($user_id, 
+                                      $start_timestamp = false, 
+                                      $end_timestamp = false, 
+                                      $after_registration = false) {
+        if (!$start_timestamp) {
+            $start_timestamp = 0;
+        }
+        
+        if (!$end_timestamp) {
+            $end_timestamp = time();
+        }
+        
+        if ($after_registration) {
+            // Get the timestamp for when the user registered and add this to 
+            // that
+            $this->db->where('id', $user_id);
+            $query = $this->db->get('user');
+            $row = $query->row_array();
+            $start_timestamp = strtotime($row['created']) + $after_registration;
+        }
+        
+        $query = $this->db->query(
+        "SELECT
+        (
+        (SELECT COUNT(*) FROM cloud WHERE user_id = $user_id
+           AND created > $start_timestamp AND created < $end_timestamp)
+        +
+        (SELECT COUNT(*) FROM cloudscape WHERE user_id = $user_id 
+        AND created > $start_timestamp AND created < $end_timestamp)
+        + 
+        (SELECT COUNT(*) FROM cloud_content  WHERE user_id = $user_id 
+        AND created > $start_timestamp AND created < $end_timestamp)
+        + 
+        (SELECT COUNT(*) FROM cloud_link WHERE user_id = $user_id 
+        AND timestamp > $start_timestamp AND timestamp< $end_timestamp)
+        + 
+        (SELECT COUNT(*) FROM cloud_reference WHERE user_id = $user_id 
+        AND timestamp> $start_timestamp AND timestamp < $end_timestamp)
+        + 
+        (SELECT COUNT(*) FROM cloud_embed  WHERE user_id = $user_id 
+        AND timestamp > $start_timestamp AND timestamp < $end_timestamp)
+        + 
+        (SELECT COUNT(*) FROM comment WHERE user_id = $user_id 
+        AND timestamp > $start_timestamp AND timestamp < $end_timestamp)
+        )
+        AS no_contributions"
+        );
+        
+        $row = $query->row_array();
+        return $row['no_contributions'];      
+    }
+    
+   /**
+    * Get the distribution of user contributions to the site - this is divided into 
+    * number of users who have made 0 contributions, 1-5 contributions,
+    * 5-9 contributions, 10-49 contribtuions, 50+ contributions 
+    * @param integer $start_timestamp Date after which contributions must have
+    * been made to be included in the count, as a Unix timestamp (optional,
+    * if not set defaults to 0)
+    * @param integer $start_timestamp Date before which contributions must have
+    * been made to be included in the count, as a Unix timestamp (optional, 
+    * if not set defaults to current time)
+    * @param integer $after_registration Period of time in seconds after the 
+    * user has registered on the site for contributions to have been made in in
+    * order to  be included in the count (optional, if not set, no restrictions
+    * made based on registration date) If this is set then $end_timestamp is 
+    * ignored
+    * @param Array. An array containing the number of users with number of
+    * contributions in each of the specified ranges
+    */
+    function get_user_contrib($start_timestamp = false, 
+                              $end_timestamp = false,
+                              $after_registration = false) {
+        $contrib = array();
+        $contrib['0']    = 0;
+        $contrib['1-5']  = 0;
+        $contrib['5-9'] = 0;
+        $contrib['10-49'] = 0;
+        $contrib['50+']  = 0;
+        
+        // Get all the users and loop through them, getting the number of 
+        // contributions for each and then incrementing the appropriate 
+        // variable
+        $query = $this->db->get('user');       
+        foreach ($query->result() as $row) {
+            $num_contrib = $this->get_number_contributions($row->id, 
+                                                           $start_timestamp, 
+                                                           $end_timestamp,
+                                                           $after_registration);
+            if ($num_contrib == 0) {
+                $contrib['0']++;
+            } elseif ($num_contrib < 6) {
+                $contrib['1-5']++;
+            } elseif ($num_contrib < 10) {
+                $contrib['5-9']++;  
+            } elseif ($num_contrib < 50) {
+                $contrib['10-49']++;
+            } else {
+                $contrib['50+']++;
+            }
+        }
+        return $contrib;
+    }
 }

File system/application/views/admin/index.php

 <li><?= anchor('event/admin', t("Admin Cloudstream")) ?></li>
 <li><?= anchor('statistics/stats', t("Site Statistics")) ?></li>
 <li><?= anchor('statistics/stats_dates', t("Site Statistics By Date")) ?></li>
+<li><?= anchor('statistics/user_stats', t("Site User Statistics (takes a while)")) ?></li>
 <li><?= anchor('statistics/cloudscape', t("Cloudscape Statistics")) ?></li>
 <li><?= anchor('statistics/cloudscape_date', t("Cloudscape Statistics By Date")) ?></li>
 </ul>

File system/application/views/admin/stats.php

-<h1>Statistics</h1>
-<p><?= anchor('/admin/panel', t("Back to admin panel")) ?></p>
-<p><strong>Total Users:</strong> <?= $user_total ?></p>
-<table width="200px">
-<tr><th></th><th>Everyone</th><th>Team</th><th>Non-team</th><th>% Non-team</th></tr>
-<tr><td>Clouds</td> <td><?= $cloud_total ?></td><td><?= $cloud_team_total ?></td><td><?= $cloud_total - $cloud_team_total?></td>
-<td><?= 0==$cloud_total? '-' :round(($cloud_total - $cloud_team_total)*100/$cloud_total, 1) ?>%</td>
-</tr>
-
-<tr><td>Cloudscapes: </td><td><?= $cloudscape_total ?></td><td><?= $cloudscape_team_total ?></td><td><?= $cloudscape_total - $cloudscape_team_total?></td>
-<td><?= 0==$cloudscape_total? '-' :round(($cloudscape_total - $cloudscape_team_total)*100/$cloudscape_total, 1) ?>%</td></tr>
-<tr><td>Tags:</td> <td><?= $tag_total ?></td><td></td><td></td>
-<td>&nbsp;</td></tr>
-<tr><td>Comments:</td> <td><?= $comment_total ?></td><td><?= $comment_team_total ?></td><td><?= $comment_total - $comment_team_total?></td>
-<td><?= 0==$comment_total? '-' :round(($comment_total - $comment_team_total)*100/$comment_total, 1) ?>%</td></tr>
-<tr><td>Links:</td><td> <?= $link_total ?></td><td> <?= $link_team_total ?></td><td><?= $link_total - $link_team_total?></td>
-<td><?= 0==$link_total? '-' :round(($link_total - $link_team_total)*100/$link_total, 1) ?>%</td></tr>
-<tr><td>Extra Content:</td> <td><?= $content_total ?></td><td><?= $content_team_total ?></td><td><?= $content_total - $content_team_total?></td>
-<td><?= 0==$content_total? '-' :round(($content_total - $content_team_total)*100/$content_total, 1) ?>%</td></tr>
-<tr><td>Embeds:</td> <td><?= $embed_total ?></td><td><?= $embed_team_total ?></td><td><?= $embed_total - $embed_team_total?></td>
-<td><?= 0==$embed_total? '-' :round(($embed_total - $embed_team_total)*100/$embed_total, 1) ?>%</td></tr>
-</table>
-
-<p><?= anchor('statistics/stats_dates', t("View data between specific dates")) ?></p>

File system/application/views/admin/stats_dates_form.php

-<h1>View statistics between dates</h1>
-<div id="region1">
-    
-    <?=form_open($this->uri->uri_string(), array('id' => 'stats-date-form'))?>
-       
-        <label for="title">Start Date:</label>
-        <input type="text" maxlength="20" name="start" id="start"  size="20" value="<?php echo date("j F Y", time() - 24*60*60*30)?>" />
-    
-        <label for="summary">End Date: </label>
-        <input type="text" maxlength="20" name="end" id="end"  size="20" value="<?php echo date("j F Y", time())?>" class="form-text" />
-    
-         
-        <input type="submit" name="submit" id="submit" class="submit" value="View Statistics" />
-        <?=form_close()?>
-</div>

File system/application/views/admin/stats_dates_results.php

-<h1>Statistics for <?= $startdate ?> to <?= $enddate ?></h1>
-<p><?= anchor('admin/stats', t("Back to statistics")) ?></p>
-<p><strong>Total new users registered in this period:</strong> <?= $user_total ?></p>
-<p><strong>Total distinct logged in users in this period:</strong> <?= $active_total ?></p>
-<table width="200px">
-<tr><th></th><th>Everyone</th><th>Team</th><th>Non-team</th><th>% Non-team</th></tr>
-<tr><td>Clouds</td> <td><?= $cloud_total ?></td><td><?= $cloud_team_total ?></td><td><?= $cloud_total - $cloud_team_total?></td>
-
-<td><?= 0==$cloud_total? '-' :round(($cloud_total - $cloud_team_total)*100/$cloud_total, 1) ?>%</td></tr>
-
-
-<tr><td>Cloudscapes: </td><td><?= $cloudscape_total ?></td><td><?= $cloudscape_team_total ?></td>
-<td><?= $cloudscape_total - $cloudscape_team_total?></td>
-
-<td><?= 0==$cloudscape_total? '-' :round(($cloudscape_total - $cloudscape_team_total)*100/$cloudscape_total, 1) ?>%</td></tr>
-
-<tr><td>Comments:</td> <td><?= $comment_total ?></td><td><?= $comment_team_total ?></td><td><?= $comment_total - $comment_team_total?></td>
-
-<td><?= 0==$comment_total? '-' :round(($comment_total - $comment_team_total)*100/$comment_total, 1) ?>%</td></tr>
-
-<tr><td>Links:</td><td> <?= $link_total ?></td><td> <?= $link_team_total ?></td><td><?= $link_total - $link_team_total?></td>
-
-<td><?= 0==$link_total? '-' :round(($link_total - $link_team_total)*100/$link_total, 1) ?>%</td></tr>
-
-<tr><td>Extra Content:</td> <td><?= $content_total ?></td><td><?= $content_team_total ?></td><td><?= $content_total - $content_team_total?></td>
-
-<td><?= 0==$content_total? '-' :round(($content_total - $content_team_total)*100/$content_total, 1) ?>%</td></tr>
-
-<tr><td>Embeds:</td> <td><?= $embed_total ?></td><td><?= $embed_team_total ?></td><td><?= $embed_total - $embed_team_total?></td>
-
-<td><?= 0==$embed_total? '-' :round(($embed_total - $embed_team_total)*100/$embed_total, 1) ?>%</td></tr>
-
-</table>
-<p><?= anchor('statistics/stats_dates', t("View data between specific dates")) ?></p>

File system/application/views/admin/user_stats.php

+<h1>User Statistics</h1>
+<p><?= anchor('/admin/panel', t("Back to admin panel")) ?></p>
+<p><strong>Total Users:</strong> <?= $user_total ?></p>

File system/application/views/statistics/stats_dates_results.php

 <h1>Statistics for <?= $startdate ?> to <?= $enddate ?></h1>
-<p><?= anchor('admin/stats', t("Back to statistics")) ?></p>
+<p><?= anchor('statistics/stats', t("Back to statistics")) ?></p>
 <p><strong>Total new users registered in this period:</strong> <?= $user_total ?></p>
 <p><strong>Total distinct logged in users in this period:</strong> <?= $active_total ?></p>
 <table width="200px">

File system/application/views/statistics/user_stats.php

+<h1>User Statistics</h1>
+<p><?= anchor('/admin/panel', t("Back to admin panel")) ?></p>
+<p><strong>Total Users:</strong> <?= $user_total ?></p>
+<p><?= t("A contribution is the creation of a cloud, cloudscape, comment, extra content, link or embed.") ?>
+<h3><?= t("Number of users who have made given number of contributions over site lifetime") ?></h3>
+<table>
+<tr>
+<th scope="col">0</th>
+<th scope="col">1-5</th>
+<th scope="col">5-9</th>
+<th scope="col">10-49</th>
+<th scope="col">50+</th></tr>
+<tr>
+<td><?=$contrib['0']?></td>
+<td><?=$contrib['1-5']?></td>
+<td><?=$contrib['5-9']?></td>
+<td><?=$contrib['10-49']?></td>
+<td><?=$contrib['50+']?></td> </tr>
+</table>
+<h3><?= t("Number of users who have made given number of contributions in last 60 days") ?></h3>
+<table>
+<tr>
+<th scope="col">0</th>
+<th scope="col">1-5</th>
+<th scope="col">5-9</th>
+<th scope="col">10-49</th>
+<th scope="col">50+</th></tr>
+<tr>
+<td><?=$contrib_last_60_days['0']?></td> 
+<td><?=$contrib_last_60_days['1-5']?></td> 
+<td><?=$contrib_last_60_days['5-9']?></td> 
+<td><?=$contrib_last_60_days['10-49']?></td> 
+<td><?=$contrib_last_60_days['50+']?></td> 
+</table>
+<h3><?= t("Number of users who have made given number of contributions over 30 days after registration") ?></h3>
+<table>
+<tr>
+<th scope="col">0</th>
+<th scope="col">1-5</th>
+<th scope="col">5-9</th>
+<th scope="col">10-49</th>
+<th scope="col">50+</th></tr>
+<tr>
+<td><?=$contrib_month_after_registration['0']?></td> 
+<td><?=$contrib_month_after_registration['1-5']?></td> 
+<td><?=$contrib_month_after_registration['5-9']?></td> 
+<td><?=$contrib_month_after_registration['10-49']?></td> 
+<td><?=$contrib_month_after_registration['50+']?></td> 
+</table>
+<h3><?= t("Number of users who have made given number of contributions over 365 days after registration") ?></h3>
+<table>
+<tr>
+<th scope="col">0</th>
+<th scope="col">1-5</th>
+<th scope="col">5-9</th>
+<th scope="col">10-49</th>
+<th scope="col">50+</th></tr>
+<tr>
+<td><?=$contrib_year_after_registration['0']?></td> 
+<td><?=$contrib_year_after_registration['1-5']?></td> 
+<td><?=$contrib_year_after_registration['5-9']?></td> 
+<td><?=$contrib_year_after_registration['10-49']?></td> 
+<td><?=$contrib_year_after_registration['50+']?></td> 
+</table>