mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-21 03:30:12 +00:00
Next implementation step, added RaceLogStore parameter to
RacingEventService, updated all callees
This commit is contained in:
1 parent
75959bd0df
commit
a8dafe6a63
9 files changed
+108
-91
No files matched your search
+15
-5
@@ -1,6 +1,7 @@
|
||||
package com.sap.sailing.domain.persistence.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -73,6 +74,8 @@ import com.sap.sailing.domain.leaderboard.impl.ResultDiscardingRuleImpl;
|
||||
import com.sap.sailing.domain.leaderboard.impl.ScoreCorrectionImpl;
|
||||
import com.sap.sailing.domain.leaderboard.meta.LeaderboardGroupMetaLeaderboard;
|
||||
import com.sap.sailing.domain.persistence.DomainObjectFactory;
|
||||
import com.sap.sailing.domain.persistence.MongoFactory;
|
||||
import com.sap.sailing.domain.persistence.MongoRaceLogStoreFactory;
|
||||
import com.sap.sailing.domain.racelog.Flags;
|
||||
import com.sap.sailing.domain.racelog.RaceColumnIdentifier;
|
||||
import com.sap.sailing.domain.racelog.RaceLog;
|
||||
@@ -358,11 +361,18 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
if (fleets.isEmpty()) {
|
||||
fleets.add(result.getFleet(null));
|
||||
}
|
||||
RaceColumn raceColumn = result.addRaceColumn((String) dbRaceColumn.get(FieldNames.LEADERBOARD_COLUMN_NAME.name()),
|
||||
(Boolean) dbRaceColumn.get(FieldNames.LEADERBOARD_IS_MEDAL_RACE_COLUMN.name()), fleets.toArray(new Fleet[0]));
|
||||
for (Map.Entry<String, RaceIdentifier> e : raceIdentifiers.entrySet()) {
|
||||
raceColumn.setRaceIdentifier(fleetsByName.get(e.getKey()), e.getValue());
|
||||
}
|
||||
try {
|
||||
RaceColumn raceColumn = result.addRaceColumn((String) dbRaceColumn.get(FieldNames.LEADERBOARD_COLUMN_NAME.name()),
|
||||
(Boolean) dbRaceColumn.get(FieldNames.LEADERBOARD_IS_MEDAL_RACE_COLUMN.name()),
|
||||
MongoRaceLogStoreFactory.INSTANCE.getMongoRaceLogStore(MongoFactory.INSTANCE.getDefaultMongoObjectFactory(), this)
|
||||
,fleets.toArray(new Fleet[0]));
|
||||
for (Map.Entry<String, RaceIdentifier> e : raceIdentifiers.entrySet()) {
|
||||
raceColumn.setRaceIdentifier(fleetsByName.get(e.getKey()), e.getValue());
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+4
-3
@@ -31,6 +31,7 @@ import com.sap.sailing.domain.leaderboard.impl.FlexibleLeaderboardImpl;
|
||||
import com.sap.sailing.domain.leaderboard.impl.LowPoint;
|
||||
import com.sap.sailing.domain.leaderboard.impl.ResultDiscardingRuleImpl;
|
||||
import com.sap.sailing.domain.leaderboard.impl.ScoreCorrectionImpl;
|
||||
import com.sap.sailing.domain.racelog.impl.EmptyRaceLogStore;
|
||||
import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRank;
|
||||
import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRankAndManyCompetitors;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
@@ -95,7 +96,7 @@ public class LeaderboardOfflineTest extends AbstractLeaderboardTest {
|
||||
Fleet defaultFleet = leaderboard.getFleet(null);
|
||||
final String columnName = "abc";
|
||||
setupRaces(1, 0);
|
||||
leaderboard.addRaceColumn(columnName, /* medalRace */ true);
|
||||
leaderboard.addRaceColumn(columnName, /* medalRace */ true, EmptyRaceLogStore.INSTANCE);
|
||||
leaderboard.addRace(testRaces.iterator().next(), columnName, /* medalRace */ false, defaultFleet);
|
||||
assertTrue(leaderboard.getRaceColumnByName(columnName).isMedalRace());
|
||||
}
|
||||
@@ -181,7 +182,7 @@ public class LeaderboardOfflineTest extends AbstractLeaderboardTest {
|
||||
Fleet defaultFleet = leaderboard.getFleet(null);
|
||||
RaceColumn r1 = leaderboard.addRace(testRace, "R1", /* medalRace */ false, defaultFleet);
|
||||
raceColumnsInLeaderboard.put(testRace, r1);
|
||||
RaceColumn r2 = leaderboard.addRaceColumn("R2", /* medalRace */ false, defaultFleet);
|
||||
RaceColumn r2 = leaderboard.addRaceColumn("R2", /* medalRace */ false, EmptyRaceLogStore.INSTANCE, defaultFleet);
|
||||
scoreCorrection.setMaxPointsReason(competitor, r2, MaxPointsReason.DND); // non-discardable disqualification
|
||||
// assert that max points were given before discarding...
|
||||
assertEquals(4.0, leaderboard.getEntry(competitor, r2, MillisecondsTimePoint.now()).getNetPoints(), 0.000000001);
|
||||
@@ -243,7 +244,7 @@ public class LeaderboardOfflineTest extends AbstractLeaderboardTest {
|
||||
// add a few race columns not yet connected to a tracked race
|
||||
for (int j=0; j<numberOfUntrackedRaces; j++) {
|
||||
i++;
|
||||
leaderboard.addRaceColumn("Test Race "+i, /* medalRace */ addOneMedalRace && j == numberOfUntrackedRaces-1);
|
||||
leaderboard.addRaceColumn("Test Race "+i, /* medalRace */ addOneMedalRace && j == numberOfUntrackedRaces-1, EmptyRaceLogStore.INSTANCE);
|
||||
}
|
||||
if (carry != null) {
|
||||
leaderboard.setCarriedPoints(competitor, carry);
|
||||
|
||||
+75
-74
@@ -1,74 +1,75 @@
|
||||
package com.sap.sailing.domain.leaderboard;
|
||||
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.base.Series;
|
||||
import com.sap.sailing.domain.common.Renamable;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
|
||||
/**
|
||||
* A leaderboard that allows its clients to flexibly modify the race columns arranged in this leaderboard without the
|
||||
* need to adhere to the constraints of a {@link Regatta} with its {@link Series} and {@link Fleet}s.
|
||||
* <p>
|
||||
*
|
||||
* A leaderboard can be renamed. If a leaderboard is managed in a structure that keys leaderboards by name, that
|
||||
* structure's rules have to be obeyed to ensure the structure's consistency. For example,
|
||||
* <code>RacingEventService</code> has a <code>renameLeaderboard</code> method that ensures the internal structure's
|
||||
* consistency and invokes this method.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
*/
|
||||
public interface FlexibleLeaderboard extends Leaderboard, Renamable {
|
||||
/**
|
||||
* Moves the column with the name <code>name</code> up.
|
||||
* @param name The name of the column to move.
|
||||
*/
|
||||
void moveRaceColumnUp(String name);
|
||||
|
||||
/**
|
||||
* Moves the column with the name <code>name</code> down.
|
||||
* @param name The name of the column to move.
|
||||
*/
|
||||
void moveRaceColumnDown(String name);
|
||||
|
||||
/**
|
||||
* Adds a new {@link RaceColumn} that has no {@link TrackedRace} associated yet to this leaderboard.
|
||||
*
|
||||
* @param name
|
||||
* the name for the new race column such that none of the columns in {@link #getRaceColumns()}
|
||||
* has that name yet; otherwise, an message will be logged, no race column will be added and
|
||||
* the existing column will be returned for robustness reasons
|
||||
* @param medalRace
|
||||
* tells if the column to add represents a medal race which has double score and cannot be discarded
|
||||
* @param fleets
|
||||
* the fleets to add to the {@link RaceColumn} created. If no fleets are specified, a single default
|
||||
* fleet will be assigned to the race column created.
|
||||
*
|
||||
* @return the race column in the leaderboard used to represent the tracked <code>race</code>
|
||||
*/
|
||||
RaceColumn addRaceColumn(String name, boolean medalRace, Fleet... fleets);
|
||||
|
||||
/**
|
||||
* Adds a tracked race to this leaderboard. If a {@link RaceColumn} with name <code>columnName</code> already exists
|
||||
* in this leaderboard, <code>race</code> is {@link RaceColumn#setTrackedRace(Fleet, TrackedRace) set as its tracked
|
||||
* race} and <code>medalRace</code> is ignored. Otherwise, a new {@link RaceColumn} column, with <code>race</code>
|
||||
* as its tracked race, is created and added to this leaderboard.
|
||||
*
|
||||
* @param medalRace
|
||||
* tells if the column to add represents a medal race which has double score and cannot be discarded;
|
||||
* ignored if the column named <code>columnName</code> already exists
|
||||
*
|
||||
* @param fleets
|
||||
* the fleets to add to the {@link RaceColumn} created. If no fleets are specified, a single default
|
||||
* fleet will be assigned to the race column created.
|
||||
*
|
||||
* @return the race column in the leaderboard used to represent the tracked <code>race</code>
|
||||
*/
|
||||
RaceColumn addRace(TrackedRace race, String columnName, boolean medalRace, Fleet fleet);
|
||||
|
||||
void removeRaceColumn(String columnName);
|
||||
|
||||
void updateIsMedalRace(String raceName, boolean isMedalRace);
|
||||
}
|
||||
package com.sap.sailing.domain.leaderboard;
|
||||
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.base.Series;
|
||||
import com.sap.sailing.domain.common.Renamable;
|
||||
import com.sap.sailing.domain.racelog.RaceLogStore;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
|
||||
/**
|
||||
* A leaderboard that allows its clients to flexibly modify the race columns arranged in this leaderboard without the
|
||||
* need to adhere to the constraints of a {@link Regatta} with its {@link Series} and {@link Fleet}s.
|
||||
* <p>
|
||||
*
|
||||
* A leaderboard can be renamed. If a leaderboard is managed in a structure that keys leaderboards by name, that
|
||||
* structure's rules have to be obeyed to ensure the structure's consistency. For example,
|
||||
* <code>RacingEventService</code> has a <code>renameLeaderboard</code> method that ensures the internal structure's
|
||||
* consistency and invokes this method.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
*/
|
||||
public interface FlexibleLeaderboard extends Leaderboard, Renamable {
|
||||
/**
|
||||
* Moves the column with the name <code>name</code> up.
|
||||
* @param name The name of the column to move.
|
||||
*/
|
||||
void moveRaceColumnUp(String name);
|
||||
|
||||
/**
|
||||
* Moves the column with the name <code>name</code> down.
|
||||
* @param name The name of the column to move.
|
||||
*/
|
||||
void moveRaceColumnDown(String name);
|
||||
|
||||
/**
|
||||
* Adds a new {@link RaceColumn} that has no {@link TrackedRace} associated yet to this leaderboard.
|
||||
*
|
||||
* @param name
|
||||
* the name for the new race column such that none of the columns in {@link #getRaceColumns()}
|
||||
* has that name yet; otherwise, an message will be logged, no race column will be added and
|
||||
* the existing column will be returned for robustness reasons
|
||||
* @param medalRace
|
||||
* tells if the column to add represents a medal race which has double score and cannot be discarded
|
||||
* @param fleets
|
||||
* the fleets to add to the {@link RaceColumn} created. If no fleets are specified, a single default
|
||||
* fleet will be assigned to the race column created.
|
||||
*
|
||||
* @return the race column in the leaderboard used to represent the tracked <code>race</code>
|
||||
*/
|
||||
RaceColumn addRaceColumn(String name, boolean medalRace, RaceLogStore raceLogStore, Fleet... fleets);
|
||||
|
||||
/**
|
||||
* Adds a tracked race to this leaderboard. If a {@link RaceColumn} with name <code>columnName</code> already exists
|
||||
* in this leaderboard, <code>race</code> is {@link RaceColumn#setTrackedRace(Fleet, TrackedRace) set as its tracked
|
||||
* race} and <code>medalRace</code> is ignored. Otherwise, a new {@link RaceColumn} column, with <code>race</code>
|
||||
* as its tracked race, is created and added to this leaderboard.
|
||||
*
|
||||
* @param medalRace
|
||||
* tells if the column to add represents a medal race which has double score and cannot be discarded;
|
||||
* ignored if the column named <code>columnName</code> already exists
|
||||
*
|
||||
* @param fleets
|
||||
* the fleets to add to the {@link RaceColumn} created. If no fleets are specified, a single default
|
||||
* fleet will be assigned to the race column created.
|
||||
*
|
||||
* @return the race column in the leaderboard used to represent the tracked <code>race</code>
|
||||
*/
|
||||
RaceColumn addRace(TrackedRace race, String columnName, boolean medalRace, Fleet fleet);
|
||||
|
||||
void removeRaceColumn(String columnName);
|
||||
|
||||
void updateIsMedalRace(String raceName, boolean isMedalRace);
|
||||
}
|
||||
+2
-1
@@ -16,6 +16,7 @@ import com.sap.sailing.domain.leaderboard.FlexibleRaceColumn;
|
||||
import com.sap.sailing.domain.leaderboard.ScoringScheme;
|
||||
import com.sap.sailing.domain.leaderboard.SettableScoreCorrection;
|
||||
import com.sap.sailing.domain.leaderboard.ThresholdBasedResultDiscardingRule;
|
||||
import com.sap.sailing.domain.racelog.RaceLogStore;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
|
||||
/**
|
||||
@@ -64,7 +65,7 @@ public class FlexibleLeaderboardImpl extends AbstractLeaderboardImpl implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceColumn addRaceColumn(String name, boolean medalRace, Fleet... fleets) {
|
||||
public RaceColumn addRaceColumn(String name, boolean medalRace, RaceLogStore raceLogStore, Fleet... fleets) {
|
||||
FlexibleRaceColumn column = getRaceColumnByName(name);
|
||||
if (column != null) {
|
||||
final String msg = "Trying to create race column with duplicate name "+name+" in leaderboard +"+getName();
|
||||
|
||||
+2
-1
@@ -46,6 +46,7 @@ import com.sap.sailing.domain.persistence.DomainObjectFactory;
|
||||
import com.sap.sailing.domain.persistence.MongoObjectFactory;
|
||||
import com.sap.sailing.domain.persistence.impl.DomainObjectFactoryImpl;
|
||||
import com.sap.sailing.domain.persistence.impl.MongoObjectFactoryImpl;
|
||||
import com.sap.sailing.domain.racelog.impl.EmptyRaceLogStore;
|
||||
import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRankAndManyCompetitors;
|
||||
import com.sap.sailing.mongodb.MongoDBService;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
@@ -423,7 +424,7 @@ public class TestStoringAndRetrievingLeaderboardGroups extends AbstractMongoDBTe
|
||||
|
||||
final FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardName, new ScoreCorrectionImpl(), new ResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces), new LowPoint(), null);
|
||||
final Fleet fleet = leaderboard.getFleet(null);
|
||||
final RaceColumn race = leaderboard.addRaceColumn(columnName, false, fleet);
|
||||
final RaceColumn race = leaderboard.addRaceColumn(columnName, false, EmptyRaceLogStore.INSTANCE, fleet);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup group = new LeaderboardGroupImpl(groupName, groupDescription, false, leaderboards);
|
||||
|
||||
+4
-3
@@ -34,6 +34,7 @@ import com.sap.sailing.domain.leaderboard.impl.ResultDiscardingRuleImpl;
|
||||
import com.sap.sailing.domain.leaderboard.impl.ScoreCorrectionImpl;
|
||||
import com.sap.sailing.domain.persistence.impl.DomainObjectFactoryImpl;
|
||||
import com.sap.sailing.domain.persistence.impl.MongoObjectFactoryImpl;
|
||||
import com.sap.sailing.domain.racelog.impl.EmptyRaceLogStore;
|
||||
import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRank;
|
||||
import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRankAndManyCompetitors;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
@@ -49,10 +50,10 @@ public class TestStoringAndRetrievingLeaderboards extends AbstractMongoDBTest {
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
FlexibleLeaderboardImpl leaderboard = new FlexibleLeaderboardImpl(leaderboardName, new ScoreCorrectionImpl(),
|
||||
new ResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces), new LowPoint(), null);
|
||||
leaderboard.addRaceColumn("R1", /* medalRace */ false);
|
||||
RaceColumn r2 = leaderboard.addRaceColumn("R2", /* medalRace */ false);
|
||||
leaderboard.addRaceColumn("R1", /* medalRace */ false, EmptyRaceLogStore.INSTANCE);
|
||||
RaceColumn r2 = leaderboard.addRaceColumn("R2", /* medalRace */ false, EmptyRaceLogStore.INSTANCE);
|
||||
r2.setFactor(1.5);
|
||||
RaceColumn r3 = leaderboard.addRaceColumn("R3", /* medalRace */ false);
|
||||
RaceColumn r3 = leaderboard.addRaceColumn("R3", /* medalRace */ false, EmptyRaceLogStore.INSTANCE);
|
||||
r3.setFactor(2.5);
|
||||
new MongoObjectFactoryImpl(db).storeLeaderboard(leaderboard);
|
||||
Leaderboard loadedLeaderboard = new DomainObjectFactoryImpl(db).loadLeaderboard(leaderboardName, /* regattaRegistry */ null);
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
|
||||
import com.sap.sailing.domain.leaderboard.LeaderboardRegistry;
|
||||
import com.sap.sailing.domain.leaderboard.RegattaLeaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.ScoringScheme;
|
||||
import com.sap.sailing.domain.racelog.RaceLogStore;
|
||||
import com.sap.sailing.domain.swisstimingadapter.SwissTimingFactory;
|
||||
import com.sap.sailing.domain.tracking.RaceListener;
|
||||
import com.sap.sailing.domain.tracking.RaceTracker;
|
||||
@@ -252,7 +253,7 @@ public interface RacingEventService extends TrackedRegattaRegistry, RegattaFetch
|
||||
*/
|
||||
void renameLeaderboard(String oldName, String newName);
|
||||
|
||||
RaceColumn addColumnToLeaderboard(String columnName, String leaderboardName, boolean medalRace);
|
||||
RaceColumn addColumnToLeaderboard(String columnName, String leaderboardName, boolean medalRace, RaceLogStore raceLogStore);
|
||||
|
||||
void moveLeaderboardColumnUp(String leaderboardName, String columnName);
|
||||
|
||||
|
||||
+3
-2
@@ -72,6 +72,7 @@ import com.sap.sailing.domain.persistence.DomainObjectFactory;
|
||||
import com.sap.sailing.domain.persistence.MongoFactory;
|
||||
import com.sap.sailing.domain.persistence.MongoObjectFactory;
|
||||
import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
import com.sap.sailing.domain.racelog.RaceLogStore;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Race;
|
||||
import com.sap.sailing.domain.swisstimingadapter.SailMasterConnector;
|
||||
import com.sap.sailing.domain.swisstimingadapter.SailMasterMessage;
|
||||
@@ -355,12 +356,12 @@ public class RacingEventServiceImpl implements RacingEventService, RegattaListen
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceColumn addColumnToLeaderboard(String columnName, String leaderboardName, boolean medalRace) {
|
||||
public RaceColumn addColumnToLeaderboard(String columnName, String leaderboardName, boolean medalRace, RaceLogStore raceLogStore) {
|
||||
Leaderboard leaderboard = getLeaderboardByName(leaderboardName);
|
||||
if (leaderboard != null) {
|
||||
if (leaderboard instanceof FlexibleLeaderboard) {
|
||||
// uses the default fleet as the single fleet for the new column
|
||||
RaceColumn result = ((FlexibleLeaderboard) leaderboard).addRaceColumn(columnName, medalRace,
|
||||
RaceColumn result = ((FlexibleLeaderboard) leaderboard).addRaceColumn(columnName, medalRace, raceLogStore,
|
||||
leaderboard.getFleet(null));
|
||||
updateStoredLeaderboard((FlexibleLeaderboard) leaderboard);
|
||||
return result;
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class AddColumnToLeaderboard extends AbstractLeaderboardColumnOperation<R
|
||||
|
||||
@Override
|
||||
public RaceColumn internalApplyTo(RacingEventService toState) {
|
||||
return toState.addColumnToLeaderboard(getColumnName(), getLeaderboardName(), medalRace);
|
||||
return toState.addColumnToLeaderboard(getColumnName(), getLeaderboardName(), medalRace, raceLogStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user