Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions model/data_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,34 @@ function initTeams( matches, events, rankingContext ) {
let teams = [];

function insertTeam( name, players, isForfeitMatch ) {
let matchingTeams = teams.filter(team => team.sharesRoster(players));

let team = teams.find( team => team.sharesRoster(players) );
if( team !== undefined ){
if ( team.isPendingUpdate === true ){
if ( matchingTeams.length > 0 ) {
// Utilise a consistent team assignment process, with team path determined at branch diverge, compared to which team was initiated first
// Select the team with the most recent match after the divergence
let team = matchingTeams.reduce(( oldest, team ) => {
let teamLastPlayed = team.teamMatches.length > 0
? Math.min(...team.teamMatches.map(m => m.match.matchStartTime))
: Infinity; // Handle teams with no matches

let oldestLastPlayed = oldest.teamMatches.length > 0
? Math.min(...oldest.teamMatches.map(m => m.match.matchStartTime))
: Infinity;

return teamLastPlayed < oldestLastPlayed ? team : oldest;
}, matchingTeams[0]);

if ( team.isPendingUpdate === true ) {
team.name = name;
team.players = players;
team.isPendingUpdate = isForfeitMatch;
}
return team;
}

return team; // Return the matching team that follows branch diverge logic
}

let rosterId = teams.length;
team = new Team( rosterId, name, players, isForfeitMatch );
let team = new Team( rosterId, name, players, isForfeitMatch );
teams.push( team );
return team;
}
Expand Down Expand Up @@ -264,4 +278,4 @@ class DataLoader
}
}

module.exports = DataLoader;
module.exports = DataLoader;