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;
|
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 {
|
return {
|
||||||
pdgaNumber: cachedPlayer.pdga_number,
|
pdgaNumber: cachedPlayer.pdga_number,
|
||||||
name: cachedPlayer.name,
|
name: cachedPlayer.name,
|
||||||
rating: cachedPlayer.current_rating,
|
rating,
|
||||||
ratingChange: cachedPlayer.rating_change,
|
ratingChange,
|
||||||
predictedRating: predictedRating > 0 ? predictedRating : null,
|
predictedRating: resolvedPredicted,
|
||||||
stdDev: stdDev > 0 ? stdDev : null
|
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;
|
return null;
|
||||||
@@ -161,12 +171,18 @@ async function getAllRatingsFromDB(progressCallback = null) {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Failed to load PDGA ${pdgaNumber} from database:`, error.message);
|
logger.error(`Failed to load PDGA ${pdgaNumber} from database:`, error.message);
|
||||||
|
const errorRating = player.current_rating;
|
||||||
|
const errorRatingChange = player.rating_change;
|
||||||
const errorData = {
|
const errorData = {
|
||||||
pdgaNumber: parseInt(pdgaNumber),
|
pdgaNumber: parseInt(pdgaNumber),
|
||||||
name: player.name || 'Database Error',
|
name: player.name || 'Database Error',
|
||||||
rating: player.current_rating,
|
rating: errorRating,
|
||||||
ratingChange: player.rating_change,
|
ratingChange: errorRatingChange,
|
||||||
predictedRating: null
|
predictedRating: null,
|
||||||
|
stdDev: null,
|
||||||
|
lastMonthRating: (errorRating != null && errorRatingChange != null) ? errorRating - errorRatingChange : null,
|
||||||
|
deltaPredicted: null,
|
||||||
|
monthlyHistory: []
|
||||||
};
|
};
|
||||||
ratings.push(errorData);
|
ratings.push(errorData);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user