Skip to content

Commit

Permalink
Merge 3ac52f3 into 0711ef0
Browse files Browse the repository at this point in the history
  • Loading branch information
bdferris-v2 authored Apr 29, 2023
2 parents 0711ef0 + 3ac52f3 commit 4f9cd5f
Show file tree
Hide file tree
Showing 27 changed files with 157 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.mobilitydata.gtfsvalidator.notice;

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

import com.google.common.base.Strings;
import java.io.IOException;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;

/**
* This is related to Input and Output operations in the code.
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(severity = ERROR)
public class IOError extends SystemError {

private final String exception;

private final String message;

public IOError(IOException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class MixedCaseRecommendedFieldNotice extends ValidationNotice {
private final String fieldName;

private final String fieldValue;

private final int csvRowNumber;

public MixedCaseRecommendedFieldNotice(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package org.mobilitydata.gtfsvalidator.notice;

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

import com.google.common.base.Strings;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;

/**
* Describes a runtime exception during loading a table. This normally indicates a bug in validator
* code.
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(severity = ERROR)
public class RuntimeExceptionInLoaderError extends SystemError {

private final String filename;

private final String exception;

private final String message;

public RuntimeExceptionInLoaderError(String filename, RuntimeException exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package org.mobilitydata.gtfsvalidator.notice;

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

import com.google.common.base.Strings;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;

/**
* Describes a runtime exception during validation. This normally indicates a bug in validator code,
* e.g., in a custom validator class.
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(severity = ERROR)
public class RuntimeExceptionInValidatorError extends SystemError {

private final String validator;

private final String exception;

private final String message;

public RuntimeExceptionInValidatorError(String validatorClassName, RuntimeException exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.mobilitydata.gtfsvalidator.notice;

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

import com.google.common.base.Strings;
import java.util.concurrent.ExecutionException;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;

/**
* Describes an ExecutionException during multithreaded validation.
Expand All @@ -11,8 +14,11 @@
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(severity = ERROR)
public class ThreadExecutionError extends SystemError {

private final String exception;

private final String message;

public ThreadExecutionError(ExecutionException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.mobilitydata.gtfsvalidator.notice;

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

import com.google.common.base.Strings;
import java.net.URISyntaxException;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;

/**
* Indicates that a string could not be parsed as a URI reference.
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(severity = ERROR)
public class URISyntaxError extends SystemError {

private final String exception;

private final String message;

public URISyntaxError(URISyntaxException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
*/
package org.mobilitydata.gtfsvalidator.validator;

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

import java.time.ZoneId;
import java.util.Locale;
import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.FileRefs;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.UrlRef;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.notice.*;
import org.mobilitydata.gtfsvalidator.table.GtfsAgency;
import org.mobilitydata.gtfsvalidator.table.GtfsAgencySchema;
import org.mobilitydata.gtfsvalidator.table.GtfsAgencyTableContainer;

/**
Expand Down Expand Up @@ -143,6 +146,7 @@ static class InconsistentAgencyLangNotice extends ValidationNotice {
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(severity = ERROR, files = @FileRefs(GtfsAgencySchema.class))
static class InconsistentAgencyTimezoneNotice extends ValidationNotice {

// The row of the faulty record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.mobilitydata.gtfsvalidator.validator;

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

import java.time.LocalDate;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Optional;
import java.util.SortedSet;
import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.input.CurrentDateTime;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
Expand All @@ -47,9 +49,13 @@
public class DateTripsValidator extends FileValidator {

private final GtfsCalendarDateTableContainer calendarDateTable;

private final GtfsCalendarTableContainer calendarTable;

private final GtfsTripTableContainer tripContainer;

private final GtfsFrequencyTableContainer frequencyTable;

private final CurrentDateTime currentDateTime;

@Inject
Expand All @@ -68,20 +74,16 @@ public class DateTripsValidator extends FileValidator {

@Override
public void validate(NoticeContainer noticeContainer) {

LocalDate now = currentDateTime.getNow().toLocalDate();

final Map<String, SortedSet<LocalDate>> servicePeriodMap =
CalendarUtil.servicePeriodToServiceDatesMap(
CalendarUtil.buildServicePeriodMap(calendarTable, calendarDateTable));

NavigableMap<LocalDate, Integer> tripCounts =
TripCalendarUtil.countTripsForEachServiceDate(
servicePeriodMap, tripContainer, frequencyTable);
Optional<TripCalendarUtil.DateInterval> majorityServiceDates =
TripCalendarUtil.computeMajorityServiceCoverage(tripCounts);
LocalDate currentDatePlusSevenDays = now.plusDays(7);

if (!majorityServiceDates.isEmpty()) {
LocalDate serviceWindowStartDate = majorityServiceDates.get().startDate();
LocalDate serviceWindowEndDate = majorityServiceDates.get().endDate();
Expand All @@ -101,11 +103,15 @@ public void validate(NoticeContainer noticeContainer) {
*
* <p>Severity: {@code SeverityLevel.WARNING
*/
@GtfsValidationNotice(severity = WARNING)
static class TripCoverageNotActiveForNext7DaysNotice extends ValidationNotice {

// Current date (YYYYMMDD format)
private final GtfsDate currentDate;

// The start date of the majority service window.
private final GtfsDate serviceWindowStartDate;

// The end date of the majority service window.
private final GtfsDate serviceWindowEndDate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package org.mobilitydata.gtfsvalidator.validator;

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

import com.google.auto.value.AutoValue;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.FileRefs;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.notice.SeverityLevel;
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
import org.mobilitydata.gtfsvalidator.table.GtfsFareMedia;
import org.mobilitydata.gtfsvalidator.table.GtfsFareMediaSchema;
import org.mobilitydata.gtfsvalidator.table.GtfsFareMediaTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsFareMediaType;

Expand Down Expand Up @@ -39,6 +44,7 @@ public void validate(NoticeContainer noticeContainer) {
*
* <p>Severity: {@code SeverityLevel.WARNING}
*/
@GtfsValidationNotice(severity = WARNING, files = @FileRefs(GtfsFareMediaSchema.class))
static class DuplicateFareMediaNotice extends ValidationNotice {

// The row number of the first fare media.
Expand All @@ -65,6 +71,7 @@ static class DuplicateFareMediaNotice extends ValidationNotice {
/** A "primary key" type composed of fare media name + type. */
@AutoValue
abstract static class Key {

public abstract String name();

public abstract GtfsFareMediaType type();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.mobilitydata.gtfsvalidator.validator;

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

import java.time.LocalDate;
import java.util.Map;
import java.util.SortedSet;
import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.UrlRef;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.input.CurrentDateTime;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
Expand All @@ -30,8 +33,11 @@

@GtfsValidator
public class ExpiredCalendarValidator extends FileValidator {

private final GtfsCalendarTableContainer calendarTable;

private final GtfsCalendarDateTableContainer calendarDateTable;

private final CurrentDateTime currentDateTime;

@Inject
Expand All @@ -47,11 +53,9 @@ public class ExpiredCalendarValidator extends FileValidator {
@Override
public void validate(NoticeContainer noticeContainer) {
LocalDate now = currentDateTime.getNow().toLocalDate();

final Map<String, SortedSet<LocalDate>> servicePeriodMap =
CalendarUtil.servicePeriodToServiceDatesMap(
CalendarUtil.buildServicePeriodMap(calendarTable, calendarDateTable));

for (var serviceId : servicePeriodMap.keySet()) {
SortedSet<LocalDate> serviceDates = servicePeriodMap.get(serviceId);
LocalDate lastServiceDate = serviceDates.last();
Expand All @@ -62,9 +66,18 @@ public void validate(NoticeContainer noticeContainer) {
}
}

@GtfsValidationNotice(
severity = WARNING,
urls = {
@UrlRef(
label = "Dataset Publishing & General Practices",
url = "https://gtfs.org/schedule/best-practices/#dataset-publishing-general-practices")
})
static class ExpiredCalendarNotice extends ValidationNotice {

// The row of the faulty record.
private final int csvRowNumber;

// The service id of the faulty record.
private final String serviceId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static class FareTransferRuleDurationLimitWithoutTypeNotice extends ValidationNo
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(severity = ERROR, files = @FileRefs(GtfsFareTransferRuleSchema.class))
static class FareTransferRuleDurationLimitTypeWithoutDurationLimitNotice
extends ValidationNotice {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static class FareTransferRuleInvalidTransferCountNotice extends ValidationNotice
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(severity = ERROR, files = @FileRefs(GtfsFareTransferRuleSchema.class))
static class FareTransferRuleMissingTransferCountNotice extends ValidationNotice {

// The row of the faulty record.
Expand All @@ -84,6 +85,7 @@ static class FareTransferRuleMissingTransferCountNotice extends ValidationNotice
*
* <p>Severity: {@code SeverityLevel.ERROR}
*/
@GtfsValidationNotice(severity = ERROR, files = @FileRefs(GtfsFareTransferRuleSchema.class))
static class FareTransferRuleWithForbiddenTransferCountNotice extends ValidationNotice {

// The row of the faulty record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.time.LocalDate;
import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.UrlRef;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.input.CurrentDateTime;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
Expand Down Expand Up @@ -105,6 +106,13 @@ static class FeedExpirationDate7DaysNotice extends ValidationNotice {
}
}

@GtfsValidationNotice(
severity = WARNING,
urls = {
@UrlRef(
label = "General Publishing & General Practices",
url = "https://gtfs.org/best-practices/#dataset-publishing--general-practices")
})
static class FeedExpirationDate30DaysNotice extends ValidationNotice {

// The row number of the faulty record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.mobilitydata.gtfsvalidator.validator;

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

import java.util.List;
Expand Down Expand Up @@ -96,6 +97,7 @@ static class StopWithoutStopTimeNotice extends ValidationNotice {
/**
* Describes a location in {@code stops.txt} that is not a stop but has a stop time associated.
*/
@GtfsValidationNotice(severity = ERROR, files = @FileRefs(GtfsStopTimeSchema.class))
static class LocationWithUnexpectedStopTimeNotice extends ValidationNotice {

// The row number of the faulty record from `stops.txt`.
Expand Down
Loading

0 comments on commit 4f9cd5f

Please sign in to comment.