refactor: address review feedback — extract date helper, rename listener

This commit is contained in:
Samuel Enocsson
2026-05-22 11:47:47 +02:00
parent a63da6f3ca
commit fba1bea247
4 changed files with 15 additions and 15 deletions
+9 -4
View File
@@ -4,6 +4,12 @@ const { fetchPlayerDataHTTP, parsePlayerData } = require('../scrapers/player-htt
const { calculatePredictedRating } = require('./rating-calculator');
const logger = require('../logger');
function formatDisplayDate(dateStr) {
return new Date(dateStr).toLocaleDateString('en-US', {
day: '2-digit', month: 'short', year: 'numeric'
});
}
// Derives previous-month rating and the delta to it. Prefers PDGA's reported
// rating_change (canonical), falls back to our own monthly snapshots when
// rating_change is missing — common for players whose latest scrape failed.
@@ -194,9 +200,7 @@ async function getAllRatingsFromDB(progressCallback = null) {
playerData.ratingHistory = rawHistory.map(row => ({
date: row.date,
rating: row.rating,
displayDate: new Date(row.date).toLocaleDateString('en-US', {
day: '2-digit', month: 'short', year: 'numeric'
})
displayDate: formatDisplayDate(row.date)
}));
// Re-derive now that history is attached — bulk path skipped includeMonthlyHistory
const derived = deriveMonthlyDeltas(playerData.rating, player.rating_change, playerData.monthlyHistory);
@@ -354,5 +358,6 @@ module.exports = {
getPredictedRatingFromDB,
getAllRatingsFromDB,
refreshAllPlayersInDB,
computeKpis
computeKpis,
formatDisplayDate
};