feat: expose lastMonthRating and deltaPredicted on player objects (#3)
Add two derived fields to all player objects returned by getPlayerDataFromDB and the error branch in getAllRatingsFromDB. No new DB columns — both fields are pure arithmetic derivations. monthlyHistory placeholder [] included ahead of A2 implementation.
This commit is contained in:
@@ -18,13 +18,23 @@ async function getPlayerDataFromDB(pdgaNumber) {
|
||||
stdDev = updatedPlayer?.std_dev;
|
||||
}
|
||||
|
||||
const rating = cachedPlayer.current_rating;
|
||||
const ratingChange = cachedPlayer.rating_change;
|
||||
const resolvedPredicted = predictedRating > 0 ? predictedRating : null;
|
||||
const resolvedStdDev = stdDev > 0 ? stdDev : null;
|
||||
|
||||
return {
|
||||
pdgaNumber: cachedPlayer.pdga_number,
|
||||
name: cachedPlayer.name,
|
||||
rating: cachedPlayer.current_rating,
|
||||
ratingChange: cachedPlayer.rating_change,
|
||||
predictedRating: predictedRating > 0 ? predictedRating : null,
|
||||
stdDev: stdDev > 0 ? stdDev : null
|
||||
rating,
|
||||
ratingChange,
|
||||
predictedRating: resolvedPredicted,
|
||||
stdDev: resolvedStdDev,
|
||||
// previous month's official rating (null when either value is missing)
|
||||
lastMonthRating: (rating != null && ratingChange != null) ? rating - ratingChange : null,
|
||||
// gap between next predicted update and current rating (null when either is missing)
|
||||
deltaPredicted: (resolvedPredicted != null && rating != null) ? resolvedPredicted - rating : null,
|
||||
monthlyHistory: []
|
||||
};
|
||||
}
|
||||
return null;
|
||||
@@ -161,12 +171,18 @@ async function getAllRatingsFromDB(progressCallback = null) {
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Failed to load PDGA ${pdgaNumber} from database:`, error.message);
|
||||
const errorRating = player.current_rating;
|
||||
const errorRatingChange = player.rating_change;
|
||||
const errorData = {
|
||||
pdgaNumber: parseInt(pdgaNumber),
|
||||
name: player.name || 'Database Error',
|
||||
rating: player.current_rating,
|
||||
ratingChange: player.rating_change,
|
||||
predictedRating: null
|
||||
rating: errorRating,
|
||||
ratingChange: errorRatingChange,
|
||||
predictedRating: null,
|
||||
stdDev: null,
|
||||
lastMonthRating: (errorRating != null && errorRatingChange != null) ? errorRating - errorRatingChange : null,
|
||||
deltaPredicted: null,
|
||||
monthlyHistory: []
|
||||
};
|
||||
ratings.push(errorData);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user