Add point-based award system with station-specific values
Implement a new award type where stations have different point values. Each confirmed QSO with a special station adds its points to the total. New Award: Special Stations Award - 10-point stations: DF2ET, DJ7NT, HB9HIL, LA8AJA - 5-point stations: DB4SCW, DG2RON, DG0TM, DO8MKR - Target: 50 points to complete Backend Changes - Add support for 'points' award type - Add calculatePointsAwardProgress() for point calculation - Add getPointsAwardEntityBreakdown() for station details - Track worked, confirmed, and totalPoints separately Frontend Changes - Awards page: Show stations and points for point awards - Details page: Show point summary cards - Details page: Show points badge next to station callsign - Gold/amber gradient badge for point values Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -87,6 +87,15 @@ function normalizeAwardRules(rules) {
|
||||
};
|
||||
}
|
||||
|
||||
// Handle "points" type awards (station-specific point values)
|
||||
// Keep as-is but validate stations array exists
|
||||
if (rules.type === 'points') {
|
||||
if (!rules.stations || !Array.isArray(rules.stations)) {
|
||||
logger.warn('Point-based award missing stations array');
|
||||
}
|
||||
return rules; // Return as-is for special handling
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
@@ -109,6 +118,11 @@ export async function calculateAwardProgress(userId, award) {
|
||||
hasFilters: !!rules.filters,
|
||||
});
|
||||
|
||||
// Handle point-based awards
|
||||
if (rules.type === 'points') {
|
||||
return calculatePointsAwardProgress(userId, rules);
|
||||
}
|
||||
|
||||
// Get all QSOs for user
|
||||
const allQSOs = await db
|
||||
.select()
|
||||
@@ -152,6 +166,160 @@ export async function calculateAwardProgress(userId, award) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate progress for point-based awards
|
||||
*/
|
||||
async function calculatePointsAwardProgress(userId, rules) {
|
||||
const { stations, target } = rules;
|
||||
|
||||
// Create a map of callsign -> points for quick lookup
|
||||
const stationPoints = new Map();
|
||||
for (const station of stations) {
|
||||
stationPoints.set(station.callsign.toUpperCase(), station.points);
|
||||
}
|
||||
|
||||
logger.debug('Point-based award stations', {
|
||||
totalStations: stations.length,
|
||||
maxPoints: stations.reduce((sum, s) => sum + s.points, 0),
|
||||
});
|
||||
|
||||
// Get all QSOs for user
|
||||
const allQSOs = await db
|
||||
.select()
|
||||
.from(qsos)
|
||||
.where(eq(qsos.userId, userId));
|
||||
|
||||
// Calculate points from confirmed QSOs with special stations
|
||||
const workedStations = new Set(); // Callsigns worked (any QSO)
|
||||
const confirmedStations = new Map(); // Callsign -> points from confirmed QSOs
|
||||
const stationDetails = []; // Array of station details
|
||||
|
||||
for (const qso of allQSOs) {
|
||||
const callsign = qso.callsign?.toUpperCase();
|
||||
if (!callsign) continue;
|
||||
|
||||
const points = stationPoints.get(callsign);
|
||||
if (!points) continue; // Not a special station
|
||||
|
||||
// Track worked stations
|
||||
if (!workedStations.has(callsign)) {
|
||||
workedStations.add(callsign);
|
||||
stationDetails.push({
|
||||
callsign,
|
||||
points,
|
||||
worked: true,
|
||||
confirmed: false,
|
||||
qsoDate: qso.qsoDate,
|
||||
band: qso.band,
|
||||
mode: qso.mode,
|
||||
});
|
||||
}
|
||||
|
||||
// Track confirmed stations (only confirmed QSOs count for points)
|
||||
if (qso.lotwQslRstatus === 'Y' && !confirmedStations.has(callsign)) {
|
||||
confirmedStations.set(callsign, points);
|
||||
|
||||
// Update the station detail to confirmed
|
||||
const detail = stationDetails.find((s) => s.callsign === callsign);
|
||||
if (detail) {
|
||||
detail.confirmed = true;
|
||||
detail.lotwQslRdate = qso.lotwQslRdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate total points (sum of confirmed station points)
|
||||
const totalPoints = Array.from(confirmedStations.values()).reduce((sum, points) => sum + points, 0);
|
||||
|
||||
logger.debug('Point-based award progress', {
|
||||
workedStations: workedStations.size,
|
||||
confirmedStations: confirmedStations.size,
|
||||
totalPoints,
|
||||
target,
|
||||
});
|
||||
|
||||
return {
|
||||
worked: workedStations.size,
|
||||
confirmed: confirmedStations.size,
|
||||
totalPoints,
|
||||
target: target || 0,
|
||||
percentage: target ? Math.min(100, Math.round((totalPoints / target) * 100)) : 0,
|
||||
workedEntities: Array.from(workedStations),
|
||||
confirmedEntities: Array.from(confirmedStations.keys()),
|
||||
stationDetails,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entity breakdown for point-based awards
|
||||
*/
|
||||
async function getPointsAwardEntityBreakdown(userId, rules) {
|
||||
const { stations, target } = rules;
|
||||
|
||||
// Create a map of callsign -> points for quick lookup
|
||||
const stationPoints = new Map();
|
||||
for (const station of stations) {
|
||||
stationPoints.set(station.callsign.toUpperCase(), station.points);
|
||||
}
|
||||
|
||||
// Get all QSOs for user
|
||||
const allQSOs = await db
|
||||
.select()
|
||||
.from(qsos)
|
||||
.where(eq(qsos.userId, userId));
|
||||
|
||||
// Build list of special stations with QSO info
|
||||
const stationMap = new Map(); // callsign -> station data
|
||||
|
||||
for (const qso of allQSOs) {
|
||||
const callsign = qso.callsign?.toUpperCase();
|
||||
if (!callsign) continue;
|
||||
|
||||
const points = stationPoints.get(callsign);
|
||||
if (!points) continue; // Not a special station
|
||||
|
||||
// Only add if not already in map
|
||||
if (!stationMap.has(callsign)) {
|
||||
stationMap.set(callsign, {
|
||||
entity: callsign,
|
||||
entityId: null,
|
||||
entityName: callsign,
|
||||
points,
|
||||
worked: true, // Has QSO
|
||||
confirmed: qso.lotwQslRstatus === 'Y',
|
||||
qsoDate: qso.qsoDate,
|
||||
band: qso.band,
|
||||
mode: qso.mode,
|
||||
callsign: qso.callsign,
|
||||
lotwQslRdate: qso.lotwQslRdate,
|
||||
});
|
||||
} else {
|
||||
// Update to confirmed if this QSO is confirmed
|
||||
const data = stationMap.get(callsign);
|
||||
if (!data.confirmed && qso.lotwQslRstatus === 'Y') {
|
||||
data.confirmed = true;
|
||||
data.lotwQslRdate = qso.lotwQslRdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const stations = Array.from(stationMap.values());
|
||||
const confirmedStations = stations.filter((s) => s.confirmed);
|
||||
const totalPoints = confirmedStations.reduce((sum, s) => sum + s.points, 0);
|
||||
|
||||
return {
|
||||
award: {
|
||||
id: 'special-stations',
|
||||
name: 'Special Stations Award',
|
||||
description: 'Contact special stations to earn points',
|
||||
},
|
||||
entities: stations,
|
||||
total: stations.length,
|
||||
confirmed: confirmedStations.length,
|
||||
totalPoints,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entity value from QSO based on entity type
|
||||
*/
|
||||
@@ -261,6 +429,11 @@ export async function getAwardEntityBreakdown(userId, awardId) {
|
||||
// Normalize rules to handle different formats
|
||||
rules = normalizeAwardRules(rules);
|
||||
|
||||
// Handle point-based awards
|
||||
if (rules.type === 'points') {
|
||||
return getPointsAwardEntityBreakdown(userId, rules);
|
||||
}
|
||||
|
||||
// Get all QSOs for user
|
||||
const allQSOs = await db
|
||||
.select()
|
||||
|
||||
Reference in New Issue
Block a user