Generate ratings from test results
This commit is contained in:
committed by
Chris Morgan
parent
274f256a63
commit
6a82a4fe3a
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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')
|
||||
{
|
||||
|
||||
@@ -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’s Rating</b></td><td>".$this->sTestedRating."</td></tr>\n";
|
||||
echo "<tr class=\"$sMaintainerColor\" valign=\"top\"><td><b>Maintainer’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))
|
||||
|
||||
Reference in New Issue
Block a user