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:
parent
7e7ec8f3a9
commit
36a9b55716
@ -578,17 +578,19 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract basic info
|
||||
// Extract basic info, all items are optional
|
||||
BString languageCode;
|
||||
BString comment;
|
||||
double rating;
|
||||
if (item.FindString("naturalLanguageCode",
|
||||
&languageCode) != B_OK
|
||||
|| item.FindString("comment", &comment) != B_OK
|
||||
|| item.FindDouble("rating", &rating) != B_OK) {
|
||||
// Ignore this entry, we need the basics
|
||||
item.FindString("naturalLanguageCode", &languageCode);
|
||||
item.FindString("comment", &comment);
|
||||
if (item.FindDouble("rating", &rating) != B_OK)
|
||||
rating = -1;
|
||||
if (comment.Length() == 0 && rating == -1) {
|
||||
// No useful information given.
|
||||
continue;
|
||||
}
|
||||
|
||||
// For which version of the package was the rating?
|
||||
BString major = "?";
|
||||
BString minor = "?";
|
||||
@ -927,18 +929,12 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data)
|
||||
}
|
||||
|
||||
double derivedRating;
|
||||
double derivedRatingSampleSize;
|
||||
if (data.FindDouble("derivedRating", &derivedRating) == B_OK
|
||||
&& data.FindDouble("derivedRatingSampleSize",
|
||||
&derivedRatingSampleSize) == B_OK) {
|
||||
if (derivedRatingSampleSize > 0) {
|
||||
RatingSummary summary;
|
||||
summary.averageRating = derivedRating;
|
||||
summary.ratingCount = (int)derivedRatingSampleSize;
|
||||
package->SetRatingSummary(summary);
|
||||
if (data.FindDouble("derivedRating", &derivedRating) == B_OK) {
|
||||
RatingSummary summary;
|
||||
summary.averageRating = derivedRating;
|
||||
package->SetRatingSummary(summary);
|
||||
|
||||
append_word_list(foundInfo, "rating");
|
||||
}
|
||||
append_word_list(foundInfo, "rating");
|
||||
}
|
||||
|
||||
BMessage screenshots;
|
||||
|
@ -923,17 +923,21 @@ PackageInfo::CalculateRatingSummary() const
|
||||
|
||||
float ratingSum = 0.0f;
|
||||
|
||||
int ratingsSpecified = summary.ratingCount;
|
||||
for (int i = 0; i < summary.ratingCount; i++) {
|
||||
float rating = fUserRatings.ItemAtFast(i).Rating();
|
||||
|
||||
if (rating < 0.0f)
|
||||
rating = 0.0f;
|
||||
rating = -1.0f;
|
||||
else if (rating > 5.0f)
|
||||
rating = 5.0f;
|
||||
|
||||
ratingSum += rating;
|
||||
if (rating >= 0.0f)
|
||||
ratingSum += rating;
|
||||
|
||||
if (rating <= 1.0f)
|
||||
if (rating <= 0.0f)
|
||||
ratingsSpecified--; // No rating specified by user
|
||||
else if (rating <= 1.0f)
|
||||
summary.ratingCountByStar[0]++;
|
||||
else if (rating <= 2.0f)
|
||||
summary.ratingCountByStar[1]++;
|
||||
@ -945,7 +949,12 @@ PackageInfo::CalculateRatingSummary() const
|
||||
summary.ratingCountByStar[4]++;
|
||||
}
|
||||
|
||||
summary.averageRating = ratingSum / summary.ratingCount;
|
||||
if (ratingsSpecified > 1)
|
||||
ratingSum /= ratingsSpecified;
|
||||
|
||||
summary.averageRating = ratingSum;
|
||||
summary.ratingCount = ratingsSpecified;
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
|
@ -1030,7 +1030,8 @@ public:
|
||||
fRatingView->SetRating(rating.Rating());
|
||||
|
||||
BString ratingLabel;
|
||||
ratingLabel.SetToFormat("%.1f", rating.Rating());
|
||||
if (rating.Rating() >= 0.0f)
|
||||
ratingLabel.SetToFormat("%.1f", rating.Rating());
|
||||
fRatingLabelView = new BStringView("rating label", ratingLabel);
|
||||
|
||||
BString versionLabel(B_TRANSLATE("for %Version%"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user