mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-01 00:30:46 +00:00
addressing old JAM comment https://jam4.sapjam.com/feed/item/dORLcyW40KB8lB8vd5PZpo;
Score corrections are since ages keyed by the competitor ID, not by the competitor name anymore. Removed the corresponding migration code.
This commit is contained in:
1 parent
cc5ec15cde
commit
0d9fe33fd3
5 files changed
+156
-376
No files matched your search
+27
-93
@@ -35,7 +35,6 @@ import com.mongodb.util.JSON;
|
||||
import com.sap.sailing.domain.abstractlog.AbstractLogEventAuthor;
|
||||
import com.sap.sailing.domain.abstractlog.impl.LogEventAuthorImpl;
|
||||
import com.sap.sailing.domain.abstractlog.race.CompetitorResults;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogFixedMarkPassingEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLog;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogCourseAreaChangedEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogCourseDesignChangedEvent;
|
||||
@@ -44,6 +43,7 @@ import com.sap.sailing.domain.abstractlog.race.RaceLogEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogEventRestoreFactory;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogFinishPositioningConfirmedEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogFinishPositioningListChangedEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogFixedMarkPassingEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogFlagEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogGateLineOpeningTimeEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogPassChangeEvent;
|
||||
@@ -53,9 +53,9 @@ import com.sap.sailing.domain.abstractlog.race.RaceLogRaceStatusEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogRevokeEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogStartProcedureChangedEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogStartTimeEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogSuppressedMarkPassingsEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogWindFixEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.SimpleRaceLogIdentifier;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogSuppressedMarkPassingsEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.impl.CompetitorResultsImpl;
|
||||
import com.sap.sailing.domain.abstractlog.race.impl.RaceLogImpl;
|
||||
import com.sap.sailing.domain.abstractlog.race.impl.SimpleRaceLogIdentifierImpl;
|
||||
@@ -141,7 +141,6 @@ import com.sap.sailing.domain.common.racelog.RaceLogRaceStatus;
|
||||
import com.sap.sailing.domain.common.racelog.RacingProcedureType;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.TransformationException;
|
||||
import com.sap.sailing.domain.leaderboard.DelayedLeaderboardCorrections;
|
||||
import com.sap.sailing.domain.leaderboard.DelayedLeaderboardCorrections.LeaderboardCorrectionsResolvedListener;
|
||||
import com.sap.sailing.domain.leaderboard.EventResolver;
|
||||
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
@@ -315,7 +314,6 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
.add(FieldNames.WIND.name() + "." + FieldNames.TIME_AS_MILLIS.name(), 1).get(),
|
||||
new BasicDBObjectBuilder().add("unique", true).add("dropDups", true).get());
|
||||
} catch (MongoException exception) {
|
||||
|
||||
if (exception.getCode() == 10092) {
|
||||
logger.warning(String.format(
|
||||
"Setting the unique index on the %s collection failed because you have too many duplicates. "
|
||||
@@ -408,19 +406,9 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
if (result != null) {
|
||||
final Leaderboard finalResult = result;
|
||||
finalResult.setDisplayName((String) dbLeaderboard.get(FieldNames.LEADERBOARD_DISPLAY_NAME.name()));
|
||||
|
||||
DelayedLeaderboardCorrections loadedLeaderboardCorrections = new DelayedLeaderboardCorrectionsImpl(result, baseDomainFactory);
|
||||
final boolean[] needsMigration = new boolean[1];
|
||||
loadedLeaderboardCorrections.addLeaderboardCorrectionsResolvedListener(new LeaderboardCorrectionsResolvedListener() {
|
||||
@Override
|
||||
public void correctionsResolved(DelayedLeaderboardCorrections delayedLeaderboardCorrections) {
|
||||
if (needsMigration[0]) {
|
||||
new MongoObjectFactoryImpl(database).storeLeaderboard(finalResult);
|
||||
}
|
||||
}
|
||||
});
|
||||
needsMigration[0] = loadLeaderboardCorrections(dbLeaderboard, loadedLeaderboardCorrections, result.getScoreCorrection()) || needsMigration[0];
|
||||
needsMigration[0] = loadSuppressedCompetitors(dbLeaderboard, loadedLeaderboardCorrections) || needsMigration[0];
|
||||
loadLeaderboardCorrections(dbLeaderboard, loadedLeaderboardCorrections, result.getScoreCorrection());
|
||||
loadSuppressedCompetitors(dbLeaderboard, loadedLeaderboardCorrections);
|
||||
loadColumnFactors(dbLeaderboard, result);
|
||||
// add the leaderboard to the registry
|
||||
if (leaderboardRegistry != null) {
|
||||
@@ -449,25 +437,13 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean loadSuppressedCompetitors(DBObject dbLeaderboard,
|
||||
DelayedLeaderboardCorrections loadedLeaderboardCorrections) {
|
||||
final boolean needsMigration;
|
||||
BasicDBList dbSuppressedCompetitorNames = (BasicDBList) dbLeaderboard.get(FieldNames.LEADERBOARD_SUPPRESSED_COMPETITORS.name());
|
||||
if (dbSuppressedCompetitorNames != null) {
|
||||
needsMigration = true;
|
||||
for (Object escapedCompetitorName : dbSuppressedCompetitorNames) {
|
||||
loadedLeaderboardCorrections.suppressCompetitorByName(MongoUtils.unescapeDollarAndDot((String) escapedCompetitorName));
|
||||
}
|
||||
} else {
|
||||
needsMigration = false;
|
||||
}
|
||||
private void loadSuppressedCompetitors(DBObject dbLeaderboard, DelayedLeaderboardCorrections loadedLeaderboardCorrections) {
|
||||
BasicDBList dbSuppressedCompetitorIDs = (BasicDBList) dbLeaderboard.get(FieldNames.LEADERBOARD_SUPPRESSED_COMPETITOR_IDS.name());
|
||||
if (dbSuppressedCompetitorIDs != null) {
|
||||
for (Object competitorId : dbSuppressedCompetitorIDs) {
|
||||
loadedLeaderboardCorrections.suppressCompetitorById((Serializable) competitorId);
|
||||
loadedLeaderboardCorrections.suppressCompetitorByID((Serializable) competitorId);
|
||||
}
|
||||
}
|
||||
return needsMigration;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -576,19 +552,8 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
return scoringScheme;
|
||||
}
|
||||
|
||||
private boolean loadLeaderboardCorrections(DBObject dbLeaderboard, DelayedLeaderboardCorrections correctionsToUpdate,
|
||||
private void loadLeaderboardCorrections(DBObject dbLeaderboard, DelayedLeaderboardCorrections correctionsToUpdate,
|
||||
SettableScoreCorrection scoreCorrectionToUpdate) {
|
||||
boolean needsMigration = false;
|
||||
DBObject carriedPoints = (DBObject) dbLeaderboard.get(FieldNames.LEADERBOARD_CARRIED_POINTS.name());
|
||||
if (carriedPoints != null) {
|
||||
needsMigration = true;
|
||||
for (String escapedCompetitorName : carriedPoints.keySet()) {
|
||||
Double carriedPointsForCompetitor = ((Number) carriedPoints.get(escapedCompetitorName)).doubleValue();
|
||||
if (carriedPointsForCompetitor != null) {
|
||||
correctionsToUpdate.setCarriedPointsByName(MongoUtils.unescapeDollarAndDot(escapedCompetitorName), carriedPointsForCompetitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
BasicDBList carriedPointsById = (BasicDBList) dbLeaderboard.get(FieldNames.LEADERBOARD_CARRIED_POINTS_BY_ID.name());
|
||||
if (carriedPointsById != null) {
|
||||
for (Object o : carriedPointsById) {
|
||||
@@ -618,44 +583,22 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
DBObject dbScoreCorrectionForRace = (DBObject) dbScoreCorrection.get(escapedRaceColumnName);
|
||||
final RaceColumn raceColumn = correctionsToUpdate.getLeaderboard().getRaceColumnByName(MongoUtils.unescapeDollarAndDot(escapedRaceColumnName));
|
||||
if (raceColumn != null) {
|
||||
if (dbScoreCorrectionForRace instanceof BasicDBList) {
|
||||
for (Object o : (BasicDBList) dbScoreCorrectionForRace) {
|
||||
DBObject dbScoreCorrectionForCompetitorInRace = (DBObject) o;
|
||||
Serializable competitorId = (Serializable) dbScoreCorrectionForCompetitorInRace
|
||||
.get(FieldNames.COMPETITOR_ID.name());
|
||||
if (dbScoreCorrectionForCompetitorInRace
|
||||
.containsField(FieldNames.LEADERBOARD_SCORE_CORRECTION_MAX_POINTS_REASON.name())) {
|
||||
correctionsToUpdate.setMaxPointsReasonByID(competitorId, raceColumn, MaxPointsReason
|
||||
.valueOf((String) dbScoreCorrectionForCompetitorInRace
|
||||
.get(FieldNames.LEADERBOARD_SCORE_CORRECTION_MAX_POINTS_REASON.name())));
|
||||
}
|
||||
if (dbScoreCorrectionForCompetitorInRace.containsField(FieldNames.LEADERBOARD_CORRECTED_SCORE
|
||||
.name())) {
|
||||
final Double leaderboardCorrectedScore = ((Number) dbScoreCorrectionForCompetitorInRace
|
||||
.get(FieldNames.LEADERBOARD_CORRECTED_SCORE.name())).doubleValue();
|
||||
correctionsToUpdate.correctScoreByID(competitorId, raceColumn,
|
||||
(Double) leaderboardCorrectedScore);
|
||||
}
|
||||
for (Object o : (BasicDBList) dbScoreCorrectionForRace) {
|
||||
DBObject dbScoreCorrectionForCompetitorInRace = (DBObject) o;
|
||||
Serializable competitorId = (Serializable) dbScoreCorrectionForCompetitorInRace
|
||||
.get(FieldNames.COMPETITOR_ID.name());
|
||||
if (dbScoreCorrectionForCompetitorInRace
|
||||
.containsField(FieldNames.LEADERBOARD_SCORE_CORRECTION_MAX_POINTS_REASON.name())) {
|
||||
correctionsToUpdate.setMaxPointsReasonByID(competitorId, raceColumn, MaxPointsReason
|
||||
.valueOf((String) dbScoreCorrectionForCompetitorInRace
|
||||
.get(FieldNames.LEADERBOARD_SCORE_CORRECTION_MAX_POINTS_REASON.name())));
|
||||
}
|
||||
} else {
|
||||
needsMigration = true;
|
||||
for (String competitorName : dbScoreCorrectionForRace.keySet()) {
|
||||
DBObject dbScoreCorrectionForCompetitorInRace = (DBObject) dbScoreCorrectionForRace
|
||||
.get(competitorName);
|
||||
if (dbScoreCorrectionForCompetitorInRace
|
||||
.containsField(FieldNames.LEADERBOARD_SCORE_CORRECTION_MAX_POINTS_REASON.name())) {
|
||||
correctionsToUpdate.setMaxPointsReasonByName(MongoUtils
|
||||
.unescapeDollarAndDot(competitorName), raceColumn, MaxPointsReason
|
||||
.valueOf((String) dbScoreCorrectionForCompetitorInRace
|
||||
.get(FieldNames.LEADERBOARD_SCORE_CORRECTION_MAX_POINTS_REASON.name())));
|
||||
}
|
||||
if (dbScoreCorrectionForCompetitorInRace.containsField(FieldNames.LEADERBOARD_CORRECTED_SCORE
|
||||
.name())) {
|
||||
final Double leaderboardCorrectedScore = ((Number) dbScoreCorrectionForCompetitorInRace
|
||||
.get(FieldNames.LEADERBOARD_CORRECTED_SCORE.name())).doubleValue();
|
||||
correctionsToUpdate.correctScoreByName(MongoUtils.unescapeDollarAndDot(competitorName),
|
||||
raceColumn, (Double) leaderboardCorrectedScore);
|
||||
}
|
||||
if (dbScoreCorrectionForCompetitorInRace.containsField(FieldNames.LEADERBOARD_CORRECTED_SCORE
|
||||
.name())) {
|
||||
final Double leaderboardCorrectedScore = ((Number) dbScoreCorrectionForCompetitorInRace
|
||||
.get(FieldNames.LEADERBOARD_CORRECTED_SCORE.name())).doubleValue();
|
||||
correctionsToUpdate.correctScoreByID(competitorId, raceColumn,
|
||||
(Double) leaderboardCorrectedScore);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -667,22 +610,13 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
// deprecated style: a DBObject whose keys are the escaped competitor names
|
||||
// new style: a BasicDBList whose entries are DBObjects with COMPETITOR_ID and COMPETITOR_DISPLAY_NAME fields
|
||||
if (competitorDisplayNames != null) {
|
||||
if (competitorDisplayNames instanceof BasicDBList) {
|
||||
for (Object o : (BasicDBList) competitorDisplayNames) {
|
||||
DBObject competitorDisplayName = (DBObject) o;
|
||||
final Serializable competitorId = (Serializable) competitorDisplayName.get(FieldNames.COMPETITOR_ID.name());
|
||||
final String displayName = (String) competitorDisplayName.get(FieldNames.COMPETITOR_DISPLAY_NAME.name());
|
||||
correctionsToUpdate.setDisplayNameByID(competitorId, displayName);
|
||||
}
|
||||
} else {
|
||||
needsMigration = true;
|
||||
for (String escapedCompetitorName : competitorDisplayNames.keySet()) {
|
||||
correctionsToUpdate.setDisplayNameByName(MongoUtils.unescapeDollarAndDot(escapedCompetitorName),
|
||||
(String) competitorDisplayNames.get(escapedCompetitorName));
|
||||
}
|
||||
for (Object o : (BasicDBList) competitorDisplayNames) {
|
||||
DBObject competitorDisplayName = (DBObject) o;
|
||||
final Serializable competitorId = (Serializable) competitorDisplayName.get(FieldNames.COMPETITOR_ID.name());
|
||||
final String displayName = (String) competitorDisplayName.get(FieldNames.COMPETITOR_DISPLAY_NAME.name());
|
||||
correctionsToUpdate.setDisplayNameByID(competitorId, displayName);
|
||||
}
|
||||
}
|
||||
return needsMigration;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user