Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: CI/CD

on:
- pull_request
- push

jobs:
build:
uses: HSLdevcom/transitdata-shared-workflows/.github/workflows/[email protected]
secrets:
DOCKER_USERNAME: ${{ secrets.TRANSITDATA_DOCKERHUB_USER }}
DOCKER_PASSWORD: ${{ secrets.TRANSITDATA_DOCKERHUB_TOKEN }}
85 changes: 0 additions & 85 deletions .github/workflows/test-and-build.yml

This file was deleted.

6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
FROM eclipse-temurin:11-alpine
#Install curl for health check
RUN apk add --no-cache curl
FROM hsldevcom/infodevops-docker-base-images:1.0.0-java-25

ADD target/transitdata-metro-ats-parser-jar-with-dependencies.jar /usr/app/transitdata-metro-ats-parser.jar
COPY start-application.sh /
RUN chmod +x /start-application.sh

CMD ["/start-application.sh"]
CMD ["/start-application.sh"]
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<common.version>2.0.7</common.version>
<spotlessMavenPlugin.version>2.43.0</spotlessMavenPlugin.version>
<googleJavaFormat.version>1.17.0</googleJavaFormat.version>
Expand Down Expand Up @@ -88,8 +88,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>11</source>
<target>11</target>
<source>25</source>
<target>25</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,34 @@ private Optional<Map<String, String>> getMetroJourneyData(final String metroKey)
}
}

/**
* Checks if the metro prediction is considered fairly reliable.
*
* We have learned that the Metro Mipro ATS API sends unreliable predictions for a vehicle journey for a few
* minutes before the departure from the first station. Those faulty predictions tend to predict an early departure
* from the first station. That almost never happens as the drivers will wait until the vehicle journey is planned
* to start.
*
* This method filters out predictions where the first station's departureTimeMeasured is missing (or invalid).
*
* @param estimate the MetroEstimate to validate
* @return true if the predictions can be considered fairly reliable or no predictions were given,
* false if the predictions cannot be considered fairly reliable
*/
private static boolean arePredictionsFairlyReliable(MetroEstimate estimate) {
return estimate.routeRows == null || estimate.routeRows.isEmpty()
|| estimate.routeRows.get(0).departureTimeMeasured != null;
}

public static Optional<MetroEstimate> parsePayload(final byte[] payload) {
try {
MetroEstimate metroEstimate = mapper.readValue(payload, MetroEstimate.class);
if (!arePredictionsFairlyReliable(metroEstimate)) {
log.debug(
"Dropped untrustworthy Mipro ATS predictions that were given before departure from first station. Payload: {}",
new String(payload));
return Optional.empty();
}
return Optional.of(metroEstimate);
} catch (Exception e) {
log.warn("Failed to parse payload {}.", new String(payload), e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package fi.hsl.transitdata.metroats;

import static org.junit.Assert.*;

import fi.hsl.common.files.FileUtils;
import fi.hsl.transitdata.metroats.models.MetroEstimate;
import fi.hsl.transitdata.metroats.models.MetroStopEstimate;
import org.junit.Test;

import java.io.InputStream;
import java.net.URL;
import java.util.Optional;

import static org.junit.Assert.*;
import org.junit.Test;

public class MetroEstimatesFactoryTest {

Expand All @@ -32,4 +31,40 @@ public void testDateTimeConversion() throws Exception {
assertEquals("2019-07-09T05:06:13.941Z", metroStopEstimate.departureTimeForecast);
assertEquals("2019-07-09T05:06:32.578Z", metroStopEstimate.departureTimeMeasured);
}

@Test
public void testParsePayloadWithNoMeasuredDepartureTimeForFirstStation() throws Exception {
// The API surprisingly uses "null" instead of null in JSON.
String json = """
{
"routeName": "M1",
"beginTime": "2023-01-01T12:01:02.345Z",
"routeRows": [
{
"station": "KIV",
"departureTimeMeasured": "null"
}
]
}""";
Optional<MetroEstimate> result = MetroEstimatesFactory.parsePayload(json.getBytes());
assertFalse("Should filter out messages without a measured departure time for first station",
result.isPresent());
}

@Test
public void testParsePayloadWithMeasuredDepartureTimeForFirstStation() throws Exception {
String json = """
{
"routeName": "M1",
"beginTime": "2023-01-01T12:01:02.345Z",
"routeRows": [
{
"station": "KIV",
"departureTimeMeasured": "2023-01-01T12:01:05.678Z"
}
]
}""";
Optional<MetroEstimate> result = MetroEstimatesFactory.parsePayload(json.getBytes());
assertTrue("Should accept messages with a measured departure time for first station", result.isPresent());
}
}