From ca6fc03171e6993a73abec8dc421930f5c90040f Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Sat, 7 Dec 2024 17:33:05 +0100 Subject: [PATCH] Remove camsys-apps.com repo and dependency on onebusaway-cloud-api --- onebusaway-gtfs-transformer/pom.xml | 14 -- .../factory/TransformFactory.java | 3 - .../impl/AnomalyCheckFutureTripCounts.java | 7 - .../impl/CheckForFutureService.java | 7 - .../impl/CheckForPlausibleStopTimes.java | 7 - .../impl/CompareToReferenceService.java | 5 - .../gtfs_transformer/impl/CountAndTest.java | 10 -- .../impl/CountAndTestBus.java | 28 +-- .../impl/CountAndTestSubway.java | 10 -- .../impl/ExtrapolateRidershipData.java | 10 -- .../impl/MTAEntrancesStrategy.java | 19 -- .../impl/MTAStationAccessibilityStrategy.java | 10 -- .../impl/UpdateStopIdById.java | 4 - .../impl/UpdateStopIdFromControlStrategy.java | 13 -- .../impl/UpdateStopIdsFromFile.java | 16 -- .../impl/UpdateStopTimesForTime.java | 9 +- .../gtfs_transformer/impl/ValidateGTFS.java | 7 - .../impl/VerifyFutureRouteService.java | 11 -- .../impl/VerifyReferenceService.java | 11 -- .../updates/VerifyBusService.java | 5 - .../updates/VerifyRouteService.java | 170 ------------------ 21 files changed, 4 insertions(+), 372 deletions(-) delete mode 100644 onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/updates/VerifyRouteService.java diff --git a/onebusaway-gtfs-transformer/pom.xml b/onebusaway-gtfs-transformer/pom.xml index 08c0c8183..f9e961218 100644 --- a/onebusaway-gtfs-transformer/pom.xml +++ b/onebusaway-gtfs-transformer/pom.xml @@ -18,10 +18,6 @@ Check central first to avoid a lot of not found warnings https://repo.maven.apache.org/maven2 - - releases-camsys-public-repo - https://repo.camsys-apps.com/releases/ - @@ -55,16 +51,6 @@ mockito-core test - - org.onebusaway - onebusaway-cloud-api - ${onebusaway.cloud.version} - - - org.onebusaway - onebusaway-cloud-noop - ${onebusaway.cloud.version} - javax.xml.bind jaxb-api diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/factory/TransformFactory.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/factory/TransformFactory.java index 3957b10e1..cecefdcf4 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/factory/TransformFactory.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/factory/TransformFactory.java @@ -255,9 +255,6 @@ else if (opType.equals("count_and_test_bus")) { else if (opType.equals("count_and_test_subway")) { handleTransformOperation(line, json, new CountAndTestSubway()); } - else if (opType.equals("verify_route_service")) { - handleTransformOperation(line, json, new VerifyRouteService()); - } else if (opType.equals("verify_bus_service")) { handleTransformOperation(line, json, new VerifyBusService()); } diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/AnomalyCheckFutureTripCounts.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/AnomalyCheckFutureTripCounts.java index bce30ecfe..9a044e1d7 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/AnomalyCheckFutureTripCounts.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/AnomalyCheckFutureTripCounts.java @@ -17,8 +17,6 @@ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.csv_entities.CSVLibrary; import org.onebusaway.csv_entities.CSVListener; import org.onebusaway.csv_entities.schema.annotations.CsvField; @@ -110,8 +108,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao){ } - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); - String[] days = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday","Holiday"}; @@ -145,9 +141,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao){ _log.info(dateDay + " has " + tripCount + " trips, and we are ignoring this possible anomoly"); } else { _log.info(dateDay + " has " + tripCount + " trips, this may indicate a problem."); - if (!silentMode) { - es.publishMessage(CloudContextService.getTopic(), dateDay.toString() + " has " + tripCount + " trips, this may indicate a problem."); - } } } dayCounter ++; diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CheckForFutureService.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CheckForFutureService.java index 23c8883e9..eb2c13cb6 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CheckForFutureService.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CheckForFutureService.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.csv_entities.schema.annotations.CsvField; import org.onebusaway.gtfs.model.*; import org.onebusaway.gtfs.model.calendar.ServiceDate; @@ -59,7 +57,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { Date dayAfterNext = helper.removeTime(helper.addDays(new Date(), 3)); String feed = CloudContextService.getLikelyFeedName(dao); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); String agency = dao.getAllAgencies().iterator().next().getId(); String agencyName = dao.getAllAgencies().iterator().next().getName(); @@ -69,10 +66,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { tripsDayAfterNext = hasServiceForDate(dao, dayAfterNext); _log.info("Feed for metrics: {}, agency id: {}", feed, agencyName); - es.publishMetric(CloudContextService.getNamespace(), "TripsToday", "feed", feed, tripsToday); - es.publishMetric(CloudContextService.getNamespace(), "TripsTomorrow", "feed", feed, tripsTomorrow); - es.publishMetric(CloudContextService.getNamespace(), "TripsIn2Days", "feed", feed, tripsNextDay); - es.publishMetric(CloudContextService.getNamespace(), "TripsIn3Days", "feed", feed, tripsDayAfterNext); _log.info("TripsToday: {}, feed: {}, namespace: {}", tripsToday, feed, CloudContextService.getNamespace()); _log.info("TripsTomorrow: {}, feed: {}, namespace: {}", tripsTomorrow, feed, CloudContextService.getNamespace()); diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CheckForPlausibleStopTimes.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CheckForPlausibleStopTimes.java index 2ae8e1368..3d6822616 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CheckForPlausibleStopTimes.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CheckForPlausibleStopTimes.java @@ -15,11 +15,8 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.gtfs.model.*; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; -import org.onebusaway.gtfs_transformer.services.CloudContextService; import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy; import org.onebusaway.gtfs_transformer.services.TransformContext; import org.slf4j.Logger; @@ -41,8 +38,6 @@ public String getName() { @Override public void run(TransformContext context, GtfsMutableRelationalDao dao) { - String feed = CloudContextService.getLikelyFeedName(dao); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); Set stopsWarn = new HashSet(); @@ -101,14 +96,12 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { stopsWarn.size() + ".\n Here are the trips and stops: " + collectedWarnString.substring(2); _log.info(collectedWarnString); } - es.publishMetric(CloudContextService.getNamespace(), "TripsWith1-3HrTransitTime", "feed", feed, stopsWarn.size()); if (stopsRemove.size() > 0) { collectedRemoveString = "Total number of trips with transit times of greater than three hours: " + stopsRemove.size() + ".\n These trips are being removed. \nTrips being removed: " + collectedRemoveString.substring(2); _log.info(collectedRemoveString); } - es.publishMetric(CloudContextService.getNamespace(), "TripsWithRemovedForTransitTime", "feed", feed, stopsRemove.size()); for (Trip trip: stopsRemove){ removeEntityLibrary.removeTrip(dao, trip); } diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CompareToReferenceService.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CompareToReferenceService.java index 3fa11c8d5..447e8580a 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CompareToReferenceService.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CompareToReferenceService.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.csv_entities.schema.annotations.CsvField; import org.onebusaway.gtfs.model.*; import org.onebusaway.gtfs.model.calendar.ServiceDate; @@ -64,7 +62,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao gtfsDao) { defaultAgencyId = CloudContextService.getLikelyFeedName(gtfsDao); String summaryTopic = CloudContextService.getTopic() + "-atis-summary"; String detailTopic = CloudContextService.getTopic() + "-atis-detail"; - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); String summaryHeader = "depot,unmatched_gtfs_trips,unmatched_reference_trips\n"; String detailHeader = "depot,unmatched_gtfs_trip_ds,unmatched_reference_trip_ids\n"; @@ -126,8 +123,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao gtfsDao) { String time = lpad(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + lpad(cal.get(Calendar.MINUTE),2 ); String baseurl = s3BasePath + "/" + year + "/" + month + "/" + day + "/" + time + "-"; - es.putFile(baseurl + "summary.csv", summaryFilename); - es.putFile(baseurl + "detail.csv", detailFilename); _log.error("{} Unmatched Summary", getName()); diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTest.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTest.java index bce8e3796..753f3668f 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTest.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTest.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.gtfs.model.*; import org.onebusaway.gtfs.model.calendar.ServiceDate; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; @@ -154,7 +152,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { dao.getAllTrips().size(), curSerTrips, dao.getAllStops().size(), dao.getAllStopTimes().size(), countSt, countNoSt, countNoHs); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); String feed = CloudContextService.getLikelyFeedName(dao); HashSet ids = new HashSet(); @@ -162,7 +159,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { //check for duplicate stop ids. if (ids.contains(stop.getId().getId())) { _log.error("Duplicate stop ids! Agency {} stop id {}", agency, stop.getId().getId()); - es.publishMultiDimensionalMetric(CloudContextService.getNamespace(),"DuplicateStopIds", new String[]{"feed","stopId"}, new String[] {feed,stop.getId().toString()},1); throw new IllegalStateException( "There are duplicate stop ids!"); } @@ -172,11 +168,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { } - es.publishMetric(CloudContextService.getNamespace(),"TripsInServiceToday","feed", feed,curSerTrips); - es.publishMetric(CloudContextService.getNamespace(),"TripsInServiceTomorrow","feed", feed,tomSerTrips); - - - if (curSerTrips + tomSerTrips < 1) { throw new IllegalStateException( "There is no current service!!"); @@ -185,7 +176,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { if (countNoHs > 0) { _log.error("There are trips with no headsign"); } - es.publishMetric(CloudContextService.getNamespace(), "TripsWithoutHeadsigns", "feed", feed, countNoHs); } private Date removeTime(Date date) { diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTestBus.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTestBus.java index 9d01316cd..3f0c18fa6 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTestBus.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTestBus.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.gtfs.impl.calendar.CalendarServiceDataFactoryImpl; import org.onebusaway.gtfs.model.*; import org.onebusaway.gtfs.model.calendar.ServiceDate; @@ -241,43 +239,23 @@ else if (refTrip.getId().getId().contains("H9")) { } _log.info("ATIS Stops: {}, Reference: {}, ATIS match to reference: {}", dao.getAllStops().size(), reference.getAllStops().size(), matches); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); String feed = CloudContextService.getLikelyFeedName(dao); - es.publishMetric(CloudContextService.getNamespace(), "ATISBusTripsThisWeek", "feed",feed, atisTripsThisWeek); - es.publishMetric(CloudContextService.getNamespace(), "refBusTripsThisWeek", "feed",feed, refTripsThisWeek); - es.publishMetric(CloudContextService.getNamespace(), "matchingBusTripsThisWeek", "feed",feed, matchingTripsThisWeek); - es.publishMetric(CloudContextService.getNamespace(), "SdonBusTripsThisWeek","feed",feed, refTripsThisWeekWithSdon); - es.publishMetric(CloudContextService.getNamespace(), "A9BusTripsThisWeek", "feed",feed, refTripsThisWeekWoutSdonWithA9); - es.publishMetric(CloudContextService.getNamespace(), "B9BusTripsThisWeek", "feed",feed, refTripsThisWeekWoutSdonWithB9); - es.publishMetric(CloudContextService.getNamespace(), "D9BusTripsThisWeek", "feed",feed, refTripsThisWeekWoutSdonWithD9); - es.publishMetric(CloudContextService.getNamespace(), "E9BusTripsThisWeek", "feed",feed, refTripsThisWeekWoutSdonWithE9); - es.publishMetric(CloudContextService.getNamespace(), "H9BusTripsWitThisWeek", "feed",feed, refTripsThisWeekWoutSdonWithH9); - es.publishMetric(CloudContextService.getNamespace(), "OtherTripsWithoutMatchThisWeek", "feed",feed, leftOverNoMatchThisWeek); - if (curSerTrips < 1) { throw new IllegalStateException( "There is no current service!!"); } - es.publishMetric(CloudContextService.getNamespace(),"BusTripsInServiceToday","feed", feed,curSerTrips); if (countNoHs > 0) { _log.error("There are trips with no headsign"); } - es.publishMetric(CloudContextService.getNamespace(), "TripsWithoutHeadsigns", "feed", feed, countNoHs); HashSet ids = new HashSet(); for (Stop stop : dao.getAllStops()) { //check for duplicate stop ids. - if (ids.contains(stop.getId().getId())) { - if (ids.contains(stop.getId().getId())) { - _log.error("Duplicate stop ids! Agency {} stop id {}", agency, stop.getId().getId()); - es.publishMultiDimensionalMetric(CloudContextService.getLikelyFeedName(dao),"DuplicateStopIds", new String[]{"feed","stopId"}, new String[] {feed,stop.getId().toString()},1); - } - } - else { - ids.add(stop.getId().getId()); - } + if (!ids.contains(stop.getId().getId())) { + ids.add(stop.getId().getId()); + } } } diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTestSubway.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTestSubway.java index 67f5f7e83..18592d2fd 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTestSubway.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/CountAndTestSubway.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.gtfs.model.*; import org.onebusaway.gtfs.model.calendar.ServiceDate; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; @@ -129,24 +127,16 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { } _log.info("ATIS Stops: {}, Reference: {}, ATIS match to reference: {}", dao.getAllStops().size(), reference.getAllStops().size(), matches); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); - String feed = CloudContextService.getLikelyFeedName(dao); - - es.publishMetric(CloudContextService.getNamespace(),"SubwayTripsInServiceToday","feed", feed,curSerTrips); if (countNoHs > 0) { _log.error("There are trips with no headsign"); } - es.publishMetric(CloudContextService.getNamespace(), "TripsWithoutHeadsigns", "feed", feed, countNoHs); HashSet ids = new HashSet(); for (Stop stop : dao.getAllStops()) { //check for duplicate stop ids. if (ids.contains(stop.getId().getId())) { _log.error("Duplicate stop ids! Agency {} stop id {}", agency, stop.getId().getId()); - es.publishMultiDimensionalMetric(CloudContextService.getNamespace(),"DuplicateStopIds", new String[]{"feed","stopId"}, new String[] {feed,stop.getId().toString()},1); - throw new IllegalStateException( - "There are duplicate stop ids!"); } else { ids.add(stop.getId().getId()); diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/ExtrapolateRidershipData.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/ExtrapolateRidershipData.java index f399edbab..9453c3ab4 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/ExtrapolateRidershipData.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/ExtrapolateRidershipData.java @@ -16,8 +16,6 @@ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.gtfs.model.*; import org.onebusaway.gtfs.serialization.mappings.StopTimeFieldMappingFactory; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; @@ -63,14 +61,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { File controlFile = new File((String) context.getParameter("controlFile")); String feed = CloudContextService.getLikelyFeedName(dao); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); - if(!controlFile.exists()) { - es.publishMultiDimensionalMetric(CloudContextService.getNamespace(),"MissingControlFiles", - new String[]{"feed","controlFileName"}, - new String[]{feed,controlFile.getName()},1); - throw new IllegalStateException( - "Control file does not exist: " + controlFile.getName()); - } AgencyAndId agencyAndId = dao.getAllTrips().iterator().next().getId(); List controlLines = new InputLibrary().readList((String) context.getParameter("controlFile")); diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/MTAEntrancesStrategy.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/MTAEntrancesStrategy.java index e2eebf49d..1b1799c2c 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/MTAEntrancesStrategy.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/MTAEntrancesStrategy.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.csv_entities.schema.annotations.CsvField; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.gtfs.model.FeedInfo; @@ -142,29 +140,12 @@ public String getName() { @Override public void run(TransformContext context, GtfsMutableRelationalDao dao) { - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); Collection feedInfos = dao.getAllFeedInfos(); String feed = null; if(feedInfos.size() > 0) feed = feedInfos.iterator().next().getPublisherName(); - File entrancesFile = new File(entrancesCsv); - if(!entrancesFile.exists()) { - es.publishMultiDimensionalMetric(getNamespace(),"MissingControlFiles", - new String[]{"feed","controlFileName"}, - new String[]{feed,entrancesCsv},1); - throw new IllegalStateException( - "Entrances file does not exist: " + entrancesFile.getName()); - } - if (elevatorsCsv != null) { File elevatorsFile = new File(elevatorsCsv); - if(!elevatorsFile.exists()) { - es.publishMultiDimensionalMetric(getNamespace(),"MissingControlFiles", - new String[]{"feed","controlFileName"}, - new String[]{feed,elevatorsCsv},1); - throw new IllegalStateException( - "Elevators file does not exist: " + elevatorsFile.getName()); - } } _log.info("elevatorCsv={}, entrancesCsv={}, accessibleComplexFile={}", elevatorsCsv, entrancesCsv, accessibleComplexFile); diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/MTAStationAccessibilityStrategy.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/MTAStationAccessibilityStrategy.java index 5b813ec2a..b6364b432 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/MTAStationAccessibilityStrategy.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/MTAStationAccessibilityStrategy.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.csv_entities.schema.annotations.CsvField; import org.onebusaway.gtfs.model.FeedInfo; import org.onebusaway.gtfs.model.Stop; @@ -55,7 +53,6 @@ public String getName() { @Override public void run(TransformContext context, GtfsMutableRelationalDao dao) { - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); Collection feedInfos = dao.getAllFeedInfos(); // name the feed for logging/reference @@ -69,13 +66,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { } File stationsFile = new File(stationsCsv); - if (!stationsFile.exists()) { - es.publishMultiDimensionalMetric(getNamespace(), "MissingControlFiles", - new String[]{"feed", "controlFileName"}, - new String[]{feed, stationsCsv}, 1); - throw new IllegalStateException( - "Entrances file does not exist: " + stationsFile.getName()); - } // see MTAStationAccessibilityStrategyTest for discussion of how this works List stations = getStations(); diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdById.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdById.java index 65e54e9d4..641092b5b 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdById.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdById.java @@ -16,8 +16,6 @@ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.gtfs.model.Stop; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; @@ -53,7 +51,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { ArrayList stopsToDelete = new ArrayList<>(); ArrayList existingStops = new ArrayList<>(); String feed = CloudContextService.getLikelyFeedName(dao); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); String agency = dao.getAllAgencies().iterator().next().getId(); String name = dao.getAllAgencies().iterator().next().getName(); @@ -73,7 +70,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { } } } - es.publishMetric(CloudContextService.getNamespace(), "DuplicateStopCount", "feed", feed, stopsToDelete.size()); for (Stop stop : stopsToDelete) { removeEntityLibrary.removeStop(dao, stop); } diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdFromControlStrategy.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdFromControlStrategy.java index 004bd7160..fdee99e38 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdFromControlStrategy.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdFromControlStrategy.java @@ -15,14 +15,11 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.csv_entities.schema.annotations.CsvField; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.gtfs.model.Stop; import org.onebusaway.gtfs.model.StopTime; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; -import org.onebusaway.gtfs_transformer.services.CloudContextService; import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy; import org.onebusaway.gtfs_transformer.services.TransformContext; import org.slf4j.Logger; @@ -59,16 +56,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { File controlFile = new File((String)context.getParameter("controlFile")); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); - String feed = CloudContextService.getLikelyFeedName(dao); - if(!controlFile.exists()) { - es.publishMultiDimensionalMetric(CloudContextService.getNamespace(),"MissingControlFiles", - new String[]{"feed","controlFileName"}, - new String[]{feed,controlFile.getName()},1); - throw new IllegalStateException( - "Control file does not exist: " + controlFile.getName()); - } - List controlLines = new InputLibrary().readList((String) context.getParameter("controlFile")); int matched = 0; int unmatched = 0; diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdsFromFile.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdsFromFile.java index 8513ee9fb..c552e6593 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdsFromFile.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopIdsFromFile.java @@ -15,18 +15,14 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.gtfs.model.Stop; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; -import org.onebusaway.gtfs_transformer.services.CloudContextService; import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy; import org.onebusaway.gtfs_transformer.services.TransformContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; import java.util.List; //based on the control file, we are changing from the "new" id to the "old" id @@ -47,18 +43,6 @@ public String getName() { @Override public void run(TransformContext context, GtfsMutableRelationalDao dao) { - File controlFile = new File((String)context.getParameter("controlFile")); - - String feed=dao.getAllFeedInfos().iterator().next().getPublisherName(); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); - if(!controlFile.exists()) { - es.publishMultiDimensionalMetric(CloudContextService.getNamespace(), "MissingControlFiles", - new String[] {"feed","controlFileName"}, - new String[] {feed,controlFile.getName()},1); - throw new IllegalStateException( - "Control file does not exist: " + controlFile.getName()); - } - List controlLines = new InputLibrary().readList((String) context.getParameter("controlFile")); int matched = 0; int unmatched = 0; diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopTimesForTime.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopTimesForTime.java index bd7c21bfa..f23e806c3 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopTimesForTime.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/UpdateStopTimesForTime.java @@ -16,17 +16,14 @@ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; +import java.util.ArrayList; import org.onebusaway.gtfs.model.StopTime; import org.onebusaway.gtfs.model.Trip; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; -import org.onebusaway.gtfs_transformer.services.CloudContextService; import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy; import org.onebusaway.gtfs_transformer.services.TransformContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; public class UpdateStopTimesForTime implements GtfsTransformStrategy { @@ -72,10 +69,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { } _log.info("Decreasing times: {}, TripsToRemove: {}", negativeTimes, tripsToRemove.size()); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); - String feed = CloudContextService.getLikelyFeedName(dao); - es.publishMetric(CloudContextService.getNamespace(), "TripsWithDecreasingStopTimes", "feed", feed, tripsToRemove.size()); - StringBuffer illegalTripList = new StringBuffer(); for (Trip trip : tripsToRemove) { illegalTripList.append(trip.getId().toString()).append(" "); diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/ValidateGTFS.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/ValidateGTFS.java index f84e5dc2f..371c8e57c 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/ValidateGTFS.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/ValidateGTFS.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.gtfs.model.*; import org.onebusaway.gtfs.model.calendar.ServiceDate; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; @@ -143,7 +141,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { dao.getAllTrips().size(), curSerTrips, dao.getAllStops().size(), dao.getAllStopTimes().size(), countSt, countNoSt, countNoHs); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); String feed = CloudContextService.getLikelyFeedName(dao); HashSet ids = new HashSet(); @@ -168,9 +165,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { } } - es.publishMetric(CloudContextService.getNamespace(),"TripsWithServiceToday","feed", feed,curSerTrips); - es.publishMetric(CloudContextService.getNamespace(),"TripsWithServiceTomorrow","feed", feed,tomSerTrips); - if (curSerTrips + tomSerTrips < 1) { throw new IllegalStateException( "There is no current service!!"); @@ -179,7 +173,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { if (countNoHs > 0) { _log.error("There are trips with no headsign"); } - es.publishMetric(CloudContextService.getNamespace(), "TripsWithoutHeadsigns", "feed", feed, countNoHs); } private Date removeTime(Date date) { diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyFutureRouteService.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyFutureRouteService.java index e9c29ead7..d78229ac7 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyFutureRouteService.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyFutureRouteService.java @@ -16,8 +16,6 @@ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.csv_entities.CSVLibrary; import org.onebusaway.csv_entities.CSVListener; import org.onebusaway.csv_entities.schema.annotations.CsvField; @@ -84,7 +82,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore(); CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference); String feed = CloudContextService.getLikelyFeedName(dao); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); String agencyName = dao.getAllAgencies().iterator().next().getName(); int[] tripsToday; @@ -104,14 +101,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { _log.info("Feed for metrics: {}, agency name: {}", feed, agencyName); _log.info("Active routes {}: {}, {}: {}, {}: {}, {}: {}", today, tripsToday[ACTIVE_ROUTES], tomorrow, tripsTomorrow[ACTIVE_ROUTES], nextDay, tripsNextDay[ACTIVE_ROUTES], dayAfterNext, tripsDayAfterNext[ACTIVE_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsToday", "feed", feed, tripsToday[ACTIVE_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RoutesNoTripsInAtisButInRefToday", "feed", feed, tripsToday[ALARMING_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsTomorrow", "feed", feed, tripsTomorrow[ACTIVE_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RoutesNoTripsInAtisButInRefTomorrow", "feed", feed, tripsTomorrow[ALARMING_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsIn2Days", "feed", feed, tripsNextDay[ACTIVE_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RoutesNoTripsInAtisButInRefIn2Days", "feed", feed, tripsNextDay[ALARMING_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsIn3Days", "feed", feed, tripsDayAfterNext[ACTIVE_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RoutesNoTripsInAtisButInRefIn3Days", "feed", feed, tripsDayAfterNext[ALARMING_ROUTES]); } private int[] hasRouteServiceForDate(GtfsMutableRelationalDao dao, GtfsMutableRelationalDao reference, diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyReferenceService.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyReferenceService.java index 6a1d6f28c..c56b46535 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyReferenceService.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyReferenceService.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.impl; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.csv_entities.CSVLibrary; import org.onebusaway.csv_entities.CSVListener; import org.onebusaway.csv_entities.schema.annotations.CsvField; @@ -56,7 +54,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore(); CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference); String feed = CloudContextService.getLikelyFeedName(reference); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); Collection problemRoutes; ProblemRouteListener listener = new ProblemRouteListener(); @@ -94,14 +91,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { _log.info("Feed for metrics: {}", feed); _log.info("Active routes {}: {}, {}: {}, {}: {}, {}: {}", today, tripsToday, tomorrow, tripsTomorrow, nextDay, tripsNextDay, dayAfterNext, tripsDayAfterNext); - es.publishMetric(CloudContextService.getNamespace(), "RefRoutesContainingTripsToday", "feed", feed, tripsTomorrow[ACTIVE_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RefRoutesMissingTripsFromRefButInAtisToday", "feed", feed, tripsTomorrow[ALARMING_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RefRoutesContainingTripsTomorrow", "feed", feed, tripsTomorrow[ACTIVE_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RefRoutesMissingTripsFromRefButInAtisTomorrow", "feed", feed, tripsTomorrow[ALARMING_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RefRoutesContainingTripsIn2Days", "feed", feed, tripsNextDay[ACTIVE_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RefRoutesMissingTripsFromRefButInAtisIn2Days", "feed", feed, tripsNextDay[ALARMING_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RefRoutesContainingTripsIn3Days", "feed", feed, tripsDayAfterNext[ACTIVE_ROUTES]); - es.publishMetric(CloudContextService.getNamespace(), "RefRoutesMissingTripsFromRefButInAtisIn3Days", "feed", feed, tripsDayAfterNext[ALARMING_ROUTES]); } int[] hasRouteServiceForDate(GtfsMutableRelationalDao dao, GtfsMutableRelationalDao reference, diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/updates/VerifyBusService.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/updates/VerifyBusService.java index b27d61502..e9732b886 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/updates/VerifyBusService.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/updates/VerifyBusService.java @@ -15,8 +15,6 @@ */ package org.onebusaway.gtfs_transformer.updates; -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; import org.onebusaway.gtfs.impl.calendar.CalendarServiceDataFactoryImpl; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.gtfs.model.Route; @@ -48,7 +46,6 @@ public String getName() { @Override public void run(TransformContext context, GtfsMutableRelationalDao dao) { GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore(); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); String feed = CloudContextService.getLikelyFeedName(dao); CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference); @@ -93,8 +90,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) { } } } - es.publishMetric(CloudContextService.getNamespace(), "RoutesMissingTripsFromAtisButInRefToday", "feed", feed, alarmingRoutes); - es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsToday", "feed", feed, curSerRoute); } private Date constructDate(ServiceDate date) { diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/updates/VerifyRouteService.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/updates/VerifyRouteService.java deleted file mode 100644 index edc2825a9..000000000 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/updates/VerifyRouteService.java +++ /dev/null @@ -1,170 +0,0 @@ -/** - * Copyright (C) 2018 Cambridge Systematics, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onebusaway.gtfs_transformer.updates; - -import org.onebusaway.cloud.api.ExternalServices; -import org.onebusaway.cloud.api.ExternalServicesBridgeFactory; -import org.onebusaway.gtfs.impl.calendar.CalendarServiceDataFactoryImpl; -import org.onebusaway.gtfs.model.*; -import org.onebusaway.gtfs.model.calendar.ServiceDate; -import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; -import org.onebusaway.gtfs.services.calendar.CalendarService; -import org.onebusaway.gtfs_transformer.services.CloudContextService; -import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy; -import org.onebusaway.gtfs_transformer.services.TransformContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.*; - -/* checks number of routes on input GTFS and checks to see if there is service on the route - * sends metrics for number of active routes each day - * sends metrics for number of trips on each active route - * logs if a route has no service - * */ - -public class VerifyRouteService implements GtfsTransformStrategy { - - private final Logger _log = LoggerFactory.getLogger(VerifyRouteService.class); - - @Override - public String getName() { - return this.getClass().getSimpleName(); - } - - @Override - public void run(TransformContext context, GtfsMutableRelationalDao dao) { - String feed = CloudContextService.getLikelyFeedName(dao); - ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices(); - - Date today = removeTime(new Date()); - Date tomorrow = removeTime(addDays(new Date(), 1)); - Date nextDay = removeTime(addDays(new Date(), 2)); - Date dayAfterNext = removeTime(addDays(new Date(), 3)); - - int numRoutesToday = hasRouteServiceForDate(dao, today, es); - if (!isWeekend(today)) { - es.publishMetric(CloudContextService.getNamespace(), "WeekdayActiveSubwayRoutesToday", "feed", feed, numRoutesToday); - } - int numRoutesTommorrow = hasRouteServiceForDate(dao, tomorrow, es); - if (!isWeekend(tomorrow)) { - es.publishMetric(CloudContextService.getNamespace(), "WeekdayActiveSubwayRoutesTomorrow", "feed", feed, numRoutesTommorrow); - } - int numRoutesIn2Days = hasRouteServiceForDate(dao, nextDay, es); - if (!isWeekend(nextDay)) { - es.publishMetric(CloudContextService.getNamespace(), "WeekdayActiveSubwayRoutesIn2Days", "feed", feed, numRoutesIn2Days); - } - int numRoutesIn3Days = hasRouteServiceForDate(dao, dayAfterNext, es); - if (!isWeekend(dayAfterNext)) { - es.publishMetric(CloudContextService.getNamespace(), "WeekdayActiveSubwayRoutesIn3Days", "feed", feed, numRoutesIn3Days); - } - - _log.info("Feed for metrics: {}", feed); - _log.info("Active routes: {}: {}; {}: {}; {}: {}; {}: {}", - formatDate(today), numRoutesToday, formatDate(tomorrow), numRoutesTommorrow, formatDate(nextDay), numRoutesIn2Days, formatDate(dayAfterNext), numRoutesIn3Days); - es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsToday", "feed", feed, numRoutesToday); - es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsTomorrow", "feed", feed, numRoutesTommorrow); - es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsIn2Days", "feed", feed, numRoutesIn2Days); - es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsIn3Days", "feed", feed, numRoutesIn3Days); - - if (numRoutesToday < 3) { - throw new IllegalStateException( - "Route service missing in agency: " + dao.getAllAgencies().iterator().next()); - } - } - - private int hasRouteServiceForDate(GtfsMutableRelationalDao dao, Date testDate, ExternalServices es) { - int numTripsOnDate = 0; - int activeRoutes = 0; - - //check for route specific current service - for (Route route : dao.getAllRoutes()) { - numTripsOnDate = 0; - triploop: - for (Trip trip : dao.getTripsForRoute(route)) { - for (ServiceCalendarDate calDate : dao.getCalendarDatesForServiceId(trip.getServiceId())) { - Date date = constructDate(calDate.getDate()); - if (calDate.getExceptionType() == 1 && date.equals(testDate)) { - numTripsOnDate++; - } - } - } - if (numTripsOnDate == 0) { - _log.info("No service for {} on {}", route.getId().getId(), testDate); - } - else { - activeRoutes++; - _log.info("Route: {} {} Number of trips: {}", route.getId().getId(), formatDate(testDate), numTripsOnDate); - //this metric is published each time any route is Active (has trips on given day) - String metricName = "TripsOnRoute" + route.getId().getId(); - es.publishMetric(CloudContextService.getNamespace(), metricName, "day", formatDate(testDate), numTripsOnDate); - } - } - return activeRoutes; - } - - private boolean isWeekend(Date date) { - Calendar cal = new GregorianCalendar(); - cal.setTime(date); - int day = cal.get(Calendar.DAY_OF_WEEK); - if (day == Calendar.SUNDAY || day == Calendar.SATURDAY) { - return true; - } - return false; - } - - private Date constructDate(ServiceDate date) { - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, date.getYear()); - calendar.set(Calendar.MONTH, date.getMonth()-1); - calendar.set(Calendar.DATE, date.getDay()); - Date date1 = calendar.getTime(); - date1 = removeTime(date1); - return date1; - } - - private Date removeTime(Date date) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - date = calendar.getTime(); - return date; - } - - private Date addDays(Date date, int daysToAdd) { - Calendar cal = Calendar.getInstance(); - cal.setTime(date); - cal.add(Calendar.DATE, daysToAdd); - return cal.getTime(); - } - - private String formatDate(Date date) { - SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd yyyy"); - return dateFormat.format(date); - } - - private ServiceDate createServiceDate(Date date) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - return new ServiceDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) +1, calendar.get(Calendar.DAY_OF_MONTH)); - } -}