| <?php |
| |
| /************************************************************************* |
| * File : live.class.php |
| * Author : Bjorn Freeman-Benson/Diego Figueroa |
| * Date : |
| * Last modified: Feb 02, 2006 |
| * Description : This class is responsible for calculating the liveness |
| * of a project based on the data stored in the stats |
| * table of the dashboard database. It will itself store |
| * the result of the liveness in the dashboard.stats table |
| *************************************************************************/ |
| |
| |
| require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection_dashboard_rw.class.php"; |
| |
| /* |
| * function logNotZero($value) |
| * |
| * Returns the logarithm of $value if $value is different from zero and |
| * returns zero otherwise. |
| */ |
| |
| function logNotZero($value) { |
| if( $value == 0 ) { |
| return $value; |
| } else { |
| return log($value); |
| } |
| } |
| |
| /* |
| * function logAbsZero($value) |
| * |
| * Returns the logarithm of $value if $value is different from zero and |
| * returns zero otherwise. If $value is negative then the function will |
| * obtain the logarithm of the absolute value of $value and then make |
| * the number negative. |
| */ |
| |
| function logAbsZero($value) { |
| if( $value == 0 ) { |
| return $value; |
| } else { |
| if( $value < 0 ) { |
| return -1 * log(abs($value)); |
| } else { |
| return log($value); |
| } |
| } |
| } |
| |
| /* |
| * function inverseNotZero($value) |
| * |
| * Returns the inverse of $value if $value is different from zero and |
| * returns zero otherwise. |
| */ |
| |
| function inverseNotZero($value) { |
| if($value == 0) { |
| return $value; |
| } else { |
| return 1.0 / $value; |
| } |
| } |
| |
| class Live { |
| var $db_connection; |
| var $db_handle; |
| |
| function Live(){ |
| // Initialize the DB connection |
| $this->db_connection = new DBConnectionDashboard(); |
| $this->db_handle = $this->db_connection->connect(); |
| } |
| |
| function computeData($table){ |
| $i = 0; |
| $livenesss = Array(); |
| $today = date('Y-m-d'); |
| |
| /* Select all stats from the table for the lastest data which should |
| * be today's |
| */ |
| $query = "SELECT * FROM ".$table." WHERE stats_date = \"".$today."\""; |
| $result = mysql_query($query,$this->db_handle); |
| while($row = mysql_fetch_assoc($result)){ |
| $project[$i] = $row['project_id']; |
| $delta_bugs_7 = 1 * logNotZero($row['bugs_7_delta']); |
| $percent_bugs_7 = 1 * logAbsZero($row['bugs_7_percentage']); |
| $percent_bugs_30 = 2 * logAbsZero($row['bugs_30_percentage']); |
| $percent_bugs_180 = 1 * logAbsZero($row['bugs_180_percentage']); |
| $posts_news_7 = 2 * logAbsZero($row['news_7_number_posts']); |
| $answers_news_7 = 2 * inverseNotZero($row['news_7_answer_average_time']); |
| $posts_news_30 = 3 * logAbsZero($row['news_30_number_posts']); |
| $answers_news_30 = 3 * inverseNotZero($row['news_30_answer_average_time']); |
| $art_count = 2 * logNotZero($row['num_articles']); |
| |
| $total = $delta_bugs_7 + |
| $percent_bugs_7 + |
| $percent_bugs_30 + |
| $percent_bugs_180 + |
| $posts_news_7 + |
| $answers_news_7 + |
| $posts_news_30 + |
| $answers_news_30 + |
| $art_count; |
| |
| /* |
| * For the liveness if the project has all zeros or there has not |
| * been any bugs in the last 6 months then the liveness drops. |
| */ |
| if( ($total == 0) && ($percent_bugs_180 == 0) ) { |
| $total = -1000; |
| } |
| |
| $liveness[$i] = $total; |
| $i++; |
| } |
| echo "<html>\n<body>\n"; |
| while(--$i >= 0){ |
| echo "<b>Processing project:</b> ".$project[$i]." <b>Liveness:</b> ".$liveness[$i]."<br>\n"; |
| $query = "UPDATE ".$table." SET liveness = ".$liveness[$i]." WHERE project_id = \"".$project[$i]."\" AND stats_date = \"".$today."\""; |
| mysql_query($query,$this->db_handle) or die("Could not update stats: ".mysql_error()); |
| } |
| echo "\n</body>\n</html>\n"; |
| } |
| |
| function destroyLive(){ |
| $this->db_handle = null; |
| $this->db_connection = null; |
| } |
| } |
| |
| ?> |