Skip to content

Commit

Permalink
feat: added dummy notice to test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y committed May 22, 2024
1 parent aec84fa commit 8836969
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.mobilitydata.gtfsvalidator.validator;

import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR;
import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.WARNING;

import java.util.Random;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;

/** Validates that two fare media do not have the same name and type. */
@GtfsValidator
public class DummyValidator extends FileValidator {

private final Random random;

DummyValidator() {
this.random = new Random();
}

@Override
public void validate(NoticeContainer noticeContainer) {
// Flip coin to decide if we should add a warning or an error
// with 10% probability of adding a warning or an error
if (random.nextInt(10) == 0) {
if (random.nextBoolean()) {
noticeContainer.addValidationNotice(new DummyNoticeWarning());
} else {
noticeContainer.addValidationNotice(new DummyNoticeError());
}
}

// Wait between 0-10 seconds
try {
int delay =
random.nextInt(11) * 1000; // Random delay between 0 and 10000 milliseconds (0-10 seconds)
Thread.sleep(delay);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// Handle the interruption
}
}

@GtfsValidationNotice(severity = WARNING)
static class DummyNoticeWarning extends ValidationNotice {
private final int csvRowNumber1;

DummyNoticeWarning() {
this.csvRowNumber1 = 1;
}
}

@GtfsValidationNotice(severity = ERROR)
static class DummyNoticeError extends ValidationNotice {
private final int csvRowNumber1;

DummyNoticeError() {
this.csvRowNumber1 = 1;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.mobilitydata.gtfsvalidator.outputcomparator.io;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import org.mobilitydata.gtfsvalidator.model.ValidationReport;

public class ValidationPerformanceCollector {
Expand Down Expand Up @@ -68,10 +64,10 @@ private String formatMetrics(String metric, String datasetId, Double reference,
String arrow = difference > 0 ? "⬆️+" : "⬇️";
diff = String.format("%s%.2f", arrow, difference);
}
return String.format("| %s | %s | %.2f | %.2f | %s |\n", metric, datasetId, reference, latest, diff);
return String.format(
"| %s | %s | %.2f | %.2f | %s |\n", metric, datasetId, reference, latest, diff);
}


public String generateLogString() {
StringBuilder b = new StringBuilder();
b.append("### ⏱️ Performance Assessment\n")
Expand All @@ -89,8 +85,10 @@ public String generateLogString() {
List<String> warnings = new ArrayList<>();
List<Double> allReferenceTimes = new ArrayList<>();
List<Double> allLatestTimes = new ArrayList<>();
Set<String> allKeys = new HashSet<>(referenceTimes.keySet());
allKeys.addAll(latestTimes.keySet());

for (String groupId : referenceTimes.keySet()) {
for (String groupId : allKeys) {
List<Double> referenceTimes = this.referenceTimes.get(groupId);
List<Double> latestTimes = this.latestTimes.getOrDefault(groupId, Collections.emptyList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@

public class ValidationPerformanceCollectorTest {

@Test
public void generateLogString_test() {
ValidationPerformanceCollector collector = new ValidationPerformanceCollector();
@Test
public void generateLogString_test() {
ValidationPerformanceCollector collector = new ValidationPerformanceCollector();

// Adding some sample data
collector.addReferenceTime("feed-id-a", 12.0);
collector.addReferenceTime("feed-id-a", 14.0);
collector.addLatestTime("feed-id-a", 16.0);
collector.addLatestTime("feed-id-a", 18.0);
// Adding some sample data
collector.addReferenceTime("feed-id-a", 12.0);
collector.addReferenceTime("feed-id-a", 14.0);
collector.addLatestTime("feed-id-a", 16.0);
collector.addLatestTime("feed-id-a", 18.0);

collector.addReferenceTime("feed-id-b", 20.0);
collector.addLatestTime("feed-id-b", 22.0);
collector.addReferenceTime("feed-id-b", 20.0);
collector.addLatestTime("feed-id-b", 22.0);

// Generating the log string
String logString = collector.generateLogString();
String expectedLogString =
"### ⏱️ Performance Assessment\n" +
"\n" +
"<details>\n" +
"<summary><strong>📈 Validation Time</strong></summary>\n" +
"<p>Assess the performance in terms of seconds taken for the validation process.</p>\n" +
"\n" +
"| Time Metric | Dataset ID | Reference (s) | Latest (s) | Difference (s) |\n" +
"|-----------------------------|-------------------|----------------|----------------|----------------|\n" +
"| Average | -- | 15.33 | 18.67 | ⬆️+3.33 |\n" +
"| Median | -- | 14.00 | 18.00 | ⬆️+4.00 |\n" +
"| Standard Deviation | -- | 3.40 | 2.49 | ⬇️-0.90 |\n" +
"| Minimum in References Reports | feed-id-a | 12.00 | 16.00 | ⬆️+4.00 |\n" +
"| Maximum in Reference Reports | feed-id-b | 20.00 | 22.00 | ⬆️+2.00 |\n" +
"| Minimum in Latest Reports | feed-id-a | 12.00 | 16.00 | ⬆️+4.00 |\n" +
"| Maximum in Latest Reports | feed-id-b | 20.00 | 22.00 | ⬆️+2.00 |\n" +
"</details>\n\n";
// Assert that the generated log string matches the expected log string
assertThat(logString).isEqualTo(expectedLogString);
}
// Generating the log string
String logString = collector.generateLogString();
String expectedLogString =
"### ⏱️ Performance Assessment\n"
+ "\n"
+ "<details>\n"
+ "<summary><strong>📈 Validation Time</strong></summary>\n"
+ "<p>Assess the performance in terms of seconds taken for the validation process.</p>\n"
+ "\n"
+ "| Time Metric | Dataset ID | Reference (s) | Latest (s) | Difference (s) |\n"
+ "|-----------------------------|-------------------|----------------|----------------|----------------|\n"
+ "| Average | -- | 15.33 | 18.67 | ⬆️+3.33 |\n"
+ "| Median | -- | 14.00 | 18.00 | ⬆️+4.00 |\n"
+ "| Standard Deviation | -- | 3.40 | 2.49 | ⬇️-0.90 |\n"
+ "| Minimum in References Reports | feed-id-a | 12.00 | 16.00 | ⬆️+4.00 |\n"
+ "| Maximum in Reference Reports | feed-id-b | 20.00 | 22.00 | ⬆️+2.00 |\n"
+ "| Minimum in Latest Reports | feed-id-a | 12.00 | 16.00 | ⬆️+4.00 |\n"
+ "| Maximum in Latest Reports | feed-id-b | 20.00 | 22.00 | ⬆️+2.00 |\n"
+ "</details>\n\n";
// Assert that the generated log string matches the expected log string
assertThat(logString).isEqualTo(expectedLogString);
}
}

0 comments on commit 8836969

Please sign in to comment.