Alexander Nicolaysen Sørnes : Generate ratings from test results

Chris Morgan cmorgan at winehq.org
Wed Jan 2 20:51:43 CST 2008


Module: appdb
Branch: master
Commit: 6a82a4fe3ab487d6b0c4e8b6ad2fb455bf19fc48
URL:    http://source.winehq.org/git/appdb.git/?a=commit;h=6a82a4fe3ab487d6b0c4e8b6ad2fb455bf19fc48

Author: Alexander Nicolaysen Sørnes <alex at thehandofagony.com>
Date:   Tue Dec 25 19:26:35 2007 +0100

Generate ratings from test results

---

 cron/cleanup.php          |   16 ++++++
 include/config.php.sample |    3 +
 include/testData.php      |  112 +++++++++++++++++++++++++++++++++++++++++++++
 include/version.php       |   35 ++++++++++++--
 4 files changed, 161 insertions(+), 5 deletions(-)

diff --git a/cron/cleanup.php b/cron/cleanup.php
index 19619a8..473b057 100644
--- a/cron/cleanup.php
+++ b/cron/cleanup.php
@@ -33,6 +33,8 @@ removeScreenshotsWithMissingFiles();
 /* status since they aren't really maintaining the application/version */
 maintainerCheck();
 
+/* Updates the rating info for all versions based on test results */
+updateRatings();
 
 /*
  * Warn users that have been inactive for some number of months
@@ -356,4 +358,18 @@ function maintainerCheck()
   maintainer::notifyMaintainersOfQueuedData();
 }
 
+function updateRatings()
+{
+    $hResult = query_parameters("SELECT * FROM appVersion");
+
+    if(!$hResult)
+        return;
+
+    while($oRow = mysql_fetch_object($hResult))
+    {
+        $oVersion = new version(0, $oRow);
+        $oVersion->updateRatingInfo();
+    }
+}
+
 ?>
diff --git a/include/config.php.sample b/include/config.php.sample
index c0399ce..4a33336 100644
--- a/include/config.php.sample
+++ b/include/config.php.sample
@@ -30,6 +30,9 @@ define("BUGZILLA_ROOT","http://bugs.winehq.org/"); // path to bugzilla
 //if(!defined("PRINT_EMAIL"))
 // define("PRINT_EMAIL", true); // print email, see mail_appdb() in include/mail.php
 
+// How old (days) a test report has to before it is judged to be aged
+define("TESTDATA_AGED_THRESHOLD", 175);
+
 /*
  * apps database info
  */
diff --git a/include/testData.php b/include/testData.php
index 7146dd8..9b8a968 100644
--- a/include/testData.php
+++ b/include/testData.php
@@ -683,6 +683,118 @@ class testData{
         echo '</div>',"\n"; // end of the 'info_container' div
     }
 
+    /* Convert a given rating string to a numeric scale */
+    public function ratingToNumber($sRating)
+    {
+        switch($sRating)
+        {
+            case GARBAGE_RATING:
+                return 0;
+            case BRONZE_RATING:
+                return 1;
+            case SILVER_RATING:
+                return 2;
+            case GOLD_RATING:
+                return 3;
+            case PLATINUM_RATING:
+                return 4;
+        }
+    }
+
+    /* Convert a numeric rating scale to a rating name */
+    public function numberToRating($iNumber)
+    {
+        switch($iNumber)
+        {
+            case 0:
+                return GARBAGE_RATING;
+            case 1:
+                return BRONZE_RATING;
+            case 2:
+                return SILVER_RATING;
+            case 3:
+                return GOLD_RATING;
+            case 4:
+                return PLATINUM_RATING;
+        }
+    }
+
+    /* Gets rating info for the selected version: an array with the elements
+       0 - Rating
+       1 - Wine version */
+    public function getRatingInfoForVersionId($iVersionId)
+    {
+        $sQuery = "SELECT testedRating,testedDate,testedRelease,versions.id as versionId
+                FROM testResults, ?.versions WHERE
+                versions.value = testResults.testedRelease
+                AND
+                versions.product_id = '?'
+                AND versionId = '?'
+                AND
+                state = '?'
+                AND
+                TO_DAYS(testedDate) > (TO_DAYS(NOW()) - ?)
+                    ORDER BY versions.id DESC,testedDate DESC";
+
+        $hResult = query_parameters($sQuery, BUGZILLA_DB, BUGZILLA_PRODUCT_ID, $iVersionId, 'accepted', TESTDATA_AGED_THRESHOLD);
+
+        $aEntries = array();
+
+        if($hResult)
+        {
+            $iPrevVersion = 0;
+            $iIndex = -1;
+            for($i = 0; $oRow = mysql_fetch_object($hResult); $i++)
+            {
+                if($iPrevRelease != $oRow->versionId)
+                {
+                    $iIndex++;
+                    $iPrevRelease = $oRow->versionId;
+                }
+
+                if(!$aEntries[$iIndex])
+                {
+                    $aEntries[$iIndex] = array();
+                    $aEntries[$iIndex][0] = 0;
+                    $aEntries[$iIndex][1] = 0;
+                    $aEntries[$iIndex][2] = $oRow->testedRelease;
+                }
+
+                $aEntries[$iIndex][0] += testData::RatingToNumber($oRow->testedRating);
+                $aEntries[$iIndex][1]++;
+            }
+        }
+
+        $sRelease = '';
+
+        if(sizeof($aEntries))
+        {
+            $fRating = 0.0;
+
+            for($i = 0; $i < sizeof($aEntries); $i++)
+            {
+                /* Discard the rating if it's the only one for that Wine version
+                   and its score is lower than previous averages */
+                if(($aEntries[$i][1] < 2) && sizeof($aEntries) > ($i+1) && ($aEntries[$i][0] < ($aEntries[$i+1][0] / $aEntries[$i+1][1])))
+                    continue;
+
+                $fRating = $aEntries[$i][0] / $aEntries[$i][1];
+                $sRelease = $aEntries[$i][2];
+                break;
+            }
+
+            $sRating = testData::NumberToRating(round($fRating, 0));
+        }
+
+        if(!$sRelease)
+        {
+            $iNewestId = testData::getNewestTestIdFromVersionId($iVersionId);
+            $oTestData = new testData($iNewestId);
+            return array($oTestData->sTestedRating, $oTestData->sTestedRelease);
+        }
+        return array($sRating,$sRelease);
+    }
+
     /* retrieve the latest test result for a given version id */
     function getNewestTestIdFromVersionId($iVersionId, $sState = 'accepted')
     {
diff --git a/include/version.php b/include/version.php
index f2df2cf..2017c1d 100644
--- a/include/version.php
+++ b/include/version.php
@@ -820,6 +820,29 @@ class version {
         return new application($this->iAppId);
     }
 
+    public function getRatingInfo()
+    {
+        return testData::getRatingInfoForVersionId($this->iVersionId);
+    }
+
+    public function updateRatingInfo()
+    {
+        $aRatingInfo = $this->getRatingInfo();
+
+        $hResult = query_parameters("UPDATE appVersion SET
+                                    maintainer_rating = '?',
+                                    maintainer_release = '?'
+                                    WHERE versionId = '?'",
+                                    $aRatingInfo[0],
+                                    $aRatingInfo[1],
+                                    $this->iVersionId);
+
+        if(!$hResult)
+            return false;
+
+        return true;
+    }
+
     public function display($aVars = array())
     {
         /* is this user supposed to view this version? */
@@ -863,10 +886,12 @@ class version {
             vote_count_version_total($this->iVersionId).$shVoteLink),
             "color0");
 
-        if($this->sTestedRating != "/" && $this->sTestedRating)
-            $sMaintainerColor = $this->sTestedRating;
+        $sRating = $this->sTestedRating;
+        $sRelease = $this->sTestedRelease;
+        if($sRating != "/" && $sRating)
+            $sRatingColor = $sRating;
         else
-            $sMaintainerColor = "color0";
+            $sRatingColor = 'color0';
 
         // URLs
         if($sUrls = url::display($this->iVersionId))
@@ -875,8 +900,8 @@ class version {
         }
 
         // rating Area
-        echo "<tr class=\"$sMaintainerColor\" valign=\"top\"><td><b>Maintainer&#8217;s Rating</b></td><td>".$this->sTestedRating."</td></tr>\n";
-        echo "<tr class=\"$sMaintainerColor\" valign=\"top\"><td><b>Maintainer&#8217;s Version</b></td><td>".$this->sTestedRelease."</td></tr>\n";
+                echo "<tr class=\"$sRatingColor\" valign=\"top\"><td><b>Rating</b></td><td>".$sRating."</td></tr>\n";
+        echo "<tr class=\"$sRatingColor\" valign=\"top\"><td><b>Wine Version</b></td><td>".$sRelease."</td></tr>\n";
 
         // Download URLs
         if($sDownloadurls = downloadurl::display($this->iVersionId))




More information about the wine-cvs mailing list