HaikuDepot: Rating related fixes.
* Fixed retrieving rating summary for the list view. * Rating and command are optional in the web app (or probably you need to specify at least one of them). Handle ratings with just the comment but no rating in average calculation.
This commit is contained in:
@@ -578,17 +578,19 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract basic info
|
// Extract basic info, all items are optional
|
||||||
BString languageCode;
|
BString languageCode;
|
||||||
BString comment;
|
BString comment;
|
||||||
double rating;
|
double rating;
|
||||||
if (item.FindString("naturalLanguageCode",
|
item.FindString("naturalLanguageCode", &languageCode);
|
||||||
&languageCode) != B_OK
|
item.FindString("comment", &comment);
|
||||||
|| item.FindString("comment", &comment) != B_OK
|
if (item.FindDouble("rating", &rating) != B_OK)
|
||||||
|| item.FindDouble("rating", &rating) != B_OK) {
|
rating = -1;
|
||||||
// Ignore this entry, we need the basics
|
if (comment.Length() == 0 && rating == -1) {
|
||||||
|
// No useful information given.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For which version of the package was the rating?
|
// For which version of the package was the rating?
|
||||||
BString major = "?";
|
BString major = "?";
|
||||||
BString minor = "?";
|
BString minor = "?";
|
||||||
@@ -927,19 +929,13 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
double derivedRating;
|
double derivedRating;
|
||||||
double derivedRatingSampleSize;
|
if (data.FindDouble("derivedRating", &derivedRating) == B_OK) {
|
||||||
if (data.FindDouble("derivedRating", &derivedRating) == B_OK
|
|
||||||
&& data.FindDouble("derivedRatingSampleSize",
|
|
||||||
&derivedRatingSampleSize) == B_OK) {
|
|
||||||
if (derivedRatingSampleSize > 0) {
|
|
||||||
RatingSummary summary;
|
RatingSummary summary;
|
||||||
summary.averageRating = derivedRating;
|
summary.averageRating = derivedRating;
|
||||||
summary.ratingCount = (int)derivedRatingSampleSize;
|
|
||||||
package->SetRatingSummary(summary);
|
package->SetRatingSummary(summary);
|
||||||
|
|
||||||
append_word_list(foundInfo, "rating");
|
append_word_list(foundInfo, "rating");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
BMessage screenshots;
|
BMessage screenshots;
|
||||||
if (data.FindMessage("pkgScreenshots", &screenshots) == B_OK) {
|
if (data.FindMessage("pkgScreenshots", &screenshots) == B_OK) {
|
||||||
|
|||||||
@@ -923,17 +923,21 @@ PackageInfo::CalculateRatingSummary() const
|
|||||||
|
|
||||||
float ratingSum = 0.0f;
|
float ratingSum = 0.0f;
|
||||||
|
|
||||||
|
int ratingsSpecified = summary.ratingCount;
|
||||||
for (int i = 0; i < summary.ratingCount; i++) {
|
for (int i = 0; i < summary.ratingCount; i++) {
|
||||||
float rating = fUserRatings.ItemAtFast(i).Rating();
|
float rating = fUserRatings.ItemAtFast(i).Rating();
|
||||||
|
|
||||||
if (rating < 0.0f)
|
if (rating < 0.0f)
|
||||||
rating = 0.0f;
|
rating = -1.0f;
|
||||||
else if (rating > 5.0f)
|
else if (rating > 5.0f)
|
||||||
rating = 5.0f;
|
rating = 5.0f;
|
||||||
|
|
||||||
|
if (rating >= 0.0f)
|
||||||
ratingSum += rating;
|
ratingSum += rating;
|
||||||
|
|
||||||
if (rating <= 1.0f)
|
if (rating <= 0.0f)
|
||||||
|
ratingsSpecified--; // No rating specified by user
|
||||||
|
else if (rating <= 1.0f)
|
||||||
summary.ratingCountByStar[0]++;
|
summary.ratingCountByStar[0]++;
|
||||||
else if (rating <= 2.0f)
|
else if (rating <= 2.0f)
|
||||||
summary.ratingCountByStar[1]++;
|
summary.ratingCountByStar[1]++;
|
||||||
@@ -945,7 +949,12 @@ PackageInfo::CalculateRatingSummary() const
|
|||||||
summary.ratingCountByStar[4]++;
|
summary.ratingCountByStar[4]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
summary.averageRating = ratingSum / summary.ratingCount;
|
if (ratingsSpecified > 1)
|
||||||
|
ratingSum /= ratingsSpecified;
|
||||||
|
|
||||||
|
summary.averageRating = ratingSum;
|
||||||
|
summary.ratingCount = ratingsSpecified;
|
||||||
|
|
||||||
return summary;
|
return summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1030,6 +1030,7 @@ public:
|
|||||||
fRatingView->SetRating(rating.Rating());
|
fRatingView->SetRating(rating.Rating());
|
||||||
|
|
||||||
BString ratingLabel;
|
BString ratingLabel;
|
||||||
|
if (rating.Rating() >= 0.0f)
|
||||||
ratingLabel.SetToFormat("%.1f", rating.Rating());
|
ratingLabel.SetToFormat("%.1f", rating.Rating());
|
||||||
fRatingLabelView = new BStringView("rating label", ratingLabel);
|
fRatingLabelView = new BStringView("rating label", ratingLabel);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user