Skip to content

Commit

Permalink
Replay naming
Browse files Browse the repository at this point in the history
See merge request main/Sumatra!1818

sumatra-commit: acb312b249acdb61174c276fd3ab026dabbe208f
  • Loading branch information
g3force authored and TIGERs GitLab committed Apr 18, 2024
1 parent fff8b4d commit b7ff342
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void before()
SumatraModel.getInstance().getModule(AutoRefModule.class).changeMode(EAutoRefMode.PASSIVE);

BerkeleyDb db = BerkeleyDb.withCustomLocation(Paths.get("../../" + BerkeleyDb.getDefaultBasePath(),
BerkeleyDb.getDefaultName() + "_" + name));
BerkeleyDb.getDefaultName("yellow", "blue") + "_" + name));
db.add(BerkeleyLogEvent.class, new BerkeleyAccessor<>(BerkeleyLogEvent.class, false));
db.add(BerkeleyShapeMapFrame.class, new BerkeleyAccessor<>(BerkeleyShapeMapFrame.class, true));
db.add(WorldFrameWrapper.class, new BerkeleyAccessor<>(WorldFrameWrapper.class, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ private String determineFolderName(final File file)


/**
* @param teamYellow name of yellow team
* @param teamBlue name of blue team
* @return a new empty unopened database at the default location
*/
public static BerkeleyDb withDefaultLocation()
public static BerkeleyDb withDefaultLocation(String teamYellow, String teamBlue)
{
return new BerkeleyDb(Paths.get(getDefaultBasePath(), getDefaultName()));
return new BerkeleyDb(Paths.get(getDefaultBasePath(), getDefaultName(teamYellow, teamBlue)));
}


Expand All @@ -109,13 +111,16 @@ public static BerkeleyDb withCustomLocation(final Path customLocation)


/**
* @param teamYellow name of yellow team
* @param teamBlue name of blue team
* @return the default name for a new database
*/
public static String getDefaultName()
public static String getDefaultName(String teamYellow, String teamBlue)
{
SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
dt.setTimeZone(TimeZone.getDefault());
return dt.format(new Date());
return dt.format(new Date()) + String.format("_%s-vs-%s", teamYellow.replace(" ", "_"),
teamBlue.replace(" ", "_"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class RecordManager extends AModule implements IRefereeObserver
private final List<IBerkeleyRecorderHook> hooks = new CopyOnWriteArrayList<>();
private long lastCommandCounter = -1;
private BerkeleyAsyncRecorder recorder = null;
private String teamYellow = "";
private String teamBlue = "";

@Configurable(defValue = "false", comment = "Automatically compress recordings after they were closed")
private static boolean compressOnClose = false;
Expand All @@ -55,7 +57,8 @@ protected Mutations getMutations()
Mutations mutations = new Mutations();
mutations.addRenamer(new Renamer("edu.tigers.sumatra.referee.gameevent.AttackerInDefenseArea", 0,
"edu.tigers.sumatra.referee.gameevent.AttackerTouchedBallInDefenseArea"));
mutations.addRenamer(new Renamer("edu.tigers.sumatra.ai.metis.offense.action.moves.OffensiveAction", 3, "edu.tigers.sumatra.ai.metis.offense.action.OffensiveAction"));
mutations.addRenamer(new Renamer("edu.tigers.sumatra.ai.metis.offense.action.moves.OffensiveAction", 3,
"edu.tigers.sumatra.ai.metis.offense.action.OffensiveAction"));

return mutations;
}
Expand Down Expand Up @@ -162,6 +165,11 @@ private boolean isNoGameStage(final SslGcRefereeMessage.Referee refMsg)
@Override
public void onNewRefereeMsg(final SslGcRefereeMessage.Referee refMsg)
{
if (refMsg != null && recorder == null)
{
teamYellow = refMsg.getYellow().getName();
teamBlue = refMsg.getBlue().getName();
}
if (autoRecord && SumatraModel.getInstance().isTournamentMode() && (refMsg != null)
&& refMsg.getCommandCounter() != lastCommandCounter)
{
Expand Down Expand Up @@ -243,13 +251,19 @@ public synchronized void toggleRecording()


protected void startRecording()
{
startRecording(teamYellow, teamBlue);
}


private void startRecording(String teamYellow, String teamBlue)
{
if (recorder != null)
{
log.warn("Start recording requested, but there is still an active recorder. Stopping it.");
recorder.stop();
}
recorder = new BerkeleyAsyncRecorder(newBerkeleyDb());
recorder = new BerkeleyAsyncRecorder(newBerkeleyDb(teamYellow, teamBlue));
recorder.getDb().getEnv().setCompressOnClose(compressOnClose);
onNewBerkeleyRecorder(recorder);
recorder.start();
Expand Down Expand Up @@ -290,11 +304,13 @@ public BerkeleyDb newBerkeleyDb(Path dbPath)
/**
* Create a new berkeley database with default accessors attached
*
* @param teamYellow yellow team name
* @param teamBlue blue team name
* @return a new empty database
*/
private BerkeleyDb newBerkeleyDb()
private BerkeleyDb newBerkeleyDb(String teamYellow, String teamBlue)
{
BerkeleyDb db = BerkeleyDb.withDefaultLocation();
BerkeleyDb db = BerkeleyDb.withDefaultLocation(teamYellow, teamBlue);
onNewBerkeleyDb(db);
return db;
}
Expand Down

0 comments on commit b7ff342

Please sign in to comment.