Skip to content

Commit

Permalink
add label to journey transport
Browse files Browse the repository at this point in the history
  • Loading branch information
derklaro committed Dec 10, 2024
1 parent 2edd003 commit 890d6f2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public final class JourneyEventEntity {
@AttributeOverrides({
@AttributeOverride(name = "line", column = @Column(name = "transport_line")),
@AttributeOverride(name = "type", column = @Column(name = "transport_type")),
@AttributeOverride(name = "label", column = @Column(name = "transport_label")),
@AttributeOverride(name = "number", column = @Column(name = "transport_number")),
@AttributeOverride(name = "category", column = @Column(name = "transport_category")),
@AttributeOverride(name = "maxSpeed", column = @Column(name = "transport_max_speed")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public final class JourneyTransport {
*/
@Column
private String line;
/**
* Marketing name or product name of the transport.
*/
@Column
private String label;
/**
* The maximum speed that this transport is allowed to drive at the associated point.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ private void updateSubsequentJourneyEventTimes(@Nonnull JourneyEventEntity event
previousTransport.getNumber(),
previousTransport.getType(),
previousTransport.getLine(),
previousTransport.getLabel(),
maxSpeedAtCurrentPoint);

// create the jit arrival and departure event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ private void collectJourney(

// extract the line information from the display name of the train
var cleanedTrainName = WHITESPACE_PATTERN.matcher(run.getTrainDisplayName()).replaceAll("");
var trainNameParts = cleanedTrainName.split("-");
var trainLine = trainNameParts.length > 1 ? trainNameParts[1] : null;
var trainNameParts = List.of(cleanedTrainName.split("-"));
var trainLine = trainNameParts.stream()
.filter(part -> !part.startsWith("\""))
.findFirst()
.orElse(null);
var trainLabel = trainNameParts.stream()
.filter(part -> part.startsWith("\"") && part.endsWith("\""))
.findFirst()
.map(label -> label.substring(1, label.length() - 1))
.orElse(null);

// create events for all timetable entries
var inBorder = false; // keeps track if the journey is within the playable border
Expand Down Expand Up @@ -183,6 +191,7 @@ private void collectJourney(
previousEvent = this.registerJourneyEvent(
journeyId,
trainLine,
trainLabel,
server,
JourneyEventType.ARRIVAL,
previousEvent,
Expand All @@ -196,6 +205,7 @@ private void collectJourney(
previousEvent = this.registerJourneyEvent(
journeyId,
trainLine,
trainLabel,
server,
JourneyEventType.DEPARTURE,
previousEvent,
Expand All @@ -215,6 +225,7 @@ private void collectJourney(
private @Nullable JourneyEventEntity registerJourneyEvent(
@Nonnull UUID journeyId,
@Nullable String trainLine,
@Nullable String trainLabel,
@Nonnull SimRailServerDescriptor server,
@Nonnull JourneyEventType eventType,
@Nullable JourneyEventEntity previousEvent,
Expand All @@ -226,6 +237,7 @@ private void collectJourney(
var event = this.createJourneyEvent(
journeyId,
trainLine,
trainLabel,
server,
eventType,
previousTime,
Expand All @@ -243,6 +255,7 @@ private void collectJourney(
private @Nullable JourneyEventEntity createJourneyEvent(
@Nonnull UUID journeyId,
@Nullable String trainLine,
@Nullable String trainLabel,
@Nonnull SimRailServerDescriptor server,
@Nonnull JourneyEventType eventType,
@Nullable OffsetDateTime previousEventTime,
Expand Down Expand Up @@ -327,6 +340,7 @@ private void collectJourney(
transportEntity.setCategory(category);
transportEntity.setNumber(number);
transportEntity.setType(transportType);
transportEntity.setLabel(trainLabel);
transportEntity.setMaxSpeed(maxSpeed);
if (transportType == JourneyTransportType.REGIONAL_TRAIN
|| transportType == JourneyTransportType.REGIONAL_FAST_TRAIN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public final class JourneyTransportDtoConverter implements Function<JourneyTrans
transport.getCategory(),
transport.getNumber(),
transport.getLine(),
transport.getLabel(),
transport.getType(),
transport.getMaxSpeed());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public final class JourneyTransportSummaryDtoConverter
transport.getCategory(),
transport.getNumber(),
transport.getLine(),
transport.getLabel(),
transport.getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public record JourneyTransportDto(
@Nonnull String number,
@Schema(description = "The line of the transport, null in case no line is associated with the transport")
@Nullable String line,
@Schema(description = "The label of the transport, for example the marketing name or product name of the transport")
@Nullable String label,
@Schema(description = "The higher-level category of the transport")
@Nonnull JourneyTransportType type,
@Schema(description = "The maximum speed (in km/h) of the journey is allowed to drive at the associated point")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public record JourneyTransportSummaryDto(
@Nonnull String number,
@Schema(description = "The line of the transport, null in case no line is associated with the transport")
@Nullable String line,
@Schema(description = "The label of the transport, for example the marketing name or product name of the transport")
@Nullable String label,
@Schema(description = "The higher-level category of the transport")
@Nonnull JourneyTransportType type
) {
Expand Down

0 comments on commit 890d6f2

Please sign in to comment.