Skip to content

Commit

Permalink
Fix openretro rating calculation (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemba authored Nov 27, 2024
1 parent aea3e4b commit 5500a32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ humans](https://keepachangelog.com).
`/home/<USER>/.skyscraper/whdload_cached_etag.txt` will force a new download.
- Fixed: Performing Ctrl-C in `--cache edit` mode will now dismiss any changes
made instead of persisting them
- Fixed: Game rating calculation in Openretro scraping module

### Version 3.13.0 (2024-11-06)

Expand Down
9 changes: 6 additions & 3 deletions src/openretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "nametools.h"
#include "strtools.h"

#include <QDebug>
#include <QRegularExpression>

OpenRetro::OpenRetro(Settings *config, QSharedPointer<NetManager> manager)
Expand Down Expand Up @@ -244,7 +245,7 @@ void OpenRetro::getRating(GameEntry &game) {
bool ratingDecimal = true;

if (checkNom(ratingPre.at(0))) {
// "0 ... 100%" or "n/d" (from mags/ext. websites)
// "0 ... 100%" or "numerator/denominator" (from mags or ext. websites)
nomNom(ratingPre.at(0));
nomNom(ratingPre.at(1));
ratingDecimal = false;
Expand All @@ -258,6 +259,8 @@ void OpenRetro::getRating(GameEntry &game) {

bool toDoubleOk = false;
game.rating = data.left(data.indexOf(ratingPost.toUtf8()));
qDebug() << "game.rating" << game.rating;
qDebug() << "ratingDecimal" << ratingDecimal;

if (!ratingDecimal) {
if (game.rating.endsWith("%")) {
Expand All @@ -268,7 +271,7 @@ void OpenRetro::getRating(GameEntry &game) {
if (toDoubleOk) {
double den = parts.value(1).toDouble(&toDoubleOk);
if (toDoubleOk && den > 0.0) {
game.rating = QString::number(num / den);
game.rating = QString::number(num / den, 'g', 2);
return;
}
}
Expand All @@ -280,7 +283,7 @@ void OpenRetro::getRating(GameEntry &game) {

double rating = game.rating.toDouble(&toDoubleOk);
if (toDoubleOk) {
game.rating = QString::number(rating / (ratingDecimal ? 10.0 : 1.0));
game.rating = QString::number(rating / (ratingDecimal ? 1.0 : 100.0));
} else {
game.rating = "";
}
Expand Down

0 comments on commit 5500a32

Please sign in to comment.