Skip to content

Commit

Permalink
Update transformations to clean up metrics, log statements and consol…
Browse files Browse the repository at this point in the history
…idate service checks so that one file can check both current and future service.
  • Loading branch information
Heidebritta committed Aug 6, 2021
1 parent 0f3ba62 commit 7bc7a9e
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
import java.util.Calendar;
import java.util.Date;

/* Checks the numbers of Trips with service today and next four days
* Metrics are logged and published to AWS
* can be used for Bus or Subway
*/
public class CheckForFutureService implements GtfsTransformStrategy {

private final Logger _log = LoggerFactory.getLogger(CheckForFutureService.class);
Expand All @@ -41,9 +45,11 @@ public String getName() {
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {

int tripsToday = 0;
int tripsTomorrow = 0;
int tripsNextDay = 0;
int tripsDayAfterNext = 0;
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));
Expand All @@ -53,15 +59,25 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) {
String agency = dao.getAllAgencies().iterator().next().getId();
String agencyName = dao.getAllAgencies().iterator().next().getName();

tripsToday = hasServiceForDate(dao, today);
tripsTomorrow = hasServiceForDate(dao, tomorrow);
tripsNextDay = hasServiceForDate(dao, nextDay);
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());
_log.info("TripsIn2Days: {}, feed: {}, namespace: {}", tripsNextDay, feed, CloudContextService.getNamespace());
_log.info("TripsIn3Days: {}, feed: {}, namespace: {}", tripsDayAfterNext, feed, CloudContextService.getNamespace());

if (tripsToday == 0) {
_log.error("Agency {} {} is missing service for today {}", agency, agencyName, tomorrow);
}
if (tripsTomorrow == 0) {
_log.error("Agency {} {} is missing service for tomorrow {}", agency, agencyName, tomorrow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
import java.util.*;
import java.util.Set;

/* Checks the numbers of Routes running on two input GTFS files and compares them.
* Used for comparing ATIS to Reference GTFS and reporting differences of ATIS routes that are missing service
* Looks at Routes running today through next 3 days
*/
public class VerifyFutureRouteService implements GtfsTransformStrategy {

private final Logger _log = LoggerFactory.getLogger(VerifyFutureRouteService.class);
Expand Down Expand Up @@ -81,27 +85,33 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) {
CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference);
String feed = CloudContextService.getLikelyFeedName(dao);
ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
String agencyName = dao.getAllAgencies().iterator().next().getName();

int[] tripsToday;
int[] tripsTomorrow;
int[] tripsNextDay;
int[] tripsDayAfterNext;
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));

tripsToday = hasRouteServiceForDate(dao, reference, refCalendarService, today, problemRoutes);
tripsTomorrow = hasRouteServiceForDate(dao, reference, refCalendarService, tomorrow, problemRoutes);
tripsNextDay = hasRouteServiceForDate(dao, reference, refCalendarService, nextDay, problemRoutes);
tripsDayAfterNext = hasRouteServiceForDate(dao, reference, refCalendarService, dayAfterNext, problemRoutes);

_log.info("Active routes {}: {}, {}: {}, {}: {}",
tomorrow, tripsTomorrow, nextDay, tripsNextDay, dayAfterNext, tripsDayAfterNext);
_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(), "RoutesMissingTripsFromAtisButInRefTomorrow", "feed", feed, tripsTomorrow[ALARMING_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(), "RoutesMissingTripsFromAtisButInRefIn2Days", "feed", feed, tripsNextDay[ALARMING_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(), "RoutesMissingTripsFromAtisButInRefIn3Days", "feed", feed, tripsDayAfterNext[ALARMING_ROUTES]);

es.publishMetric(CloudContextService.getNamespace(), "RoutesNoTripsInAtisButInRefIn3Days", "feed", feed, tripsDayAfterNext[ALARMING_ROUTES]);
}

private int[] hasRouteServiceForDate(GtfsMutableRelationalDao dao, GtfsMutableRelationalDao reference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
import java.io.InputStream;
import java.util.*;

/* Check reference service against ATIS service and if there is service in ATIS
that isn't in reference send a notification
/* Checks the numbers of Routes running on two input GTFS files and compares them.
* Used for comparing ATIS to Reference GTFS and reporting differences of Reference routes that are missing service
* Looks at Routes running today through next 3 days
*/
public class VerifyReferenceService implements GtfsTransformStrategy {
private final int ACTIVE_ROUTES = 0;
Expand All @@ -54,7 +55,7 @@ public String getName() {
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference);
String feed = CloudContextService.getLikelyFeedName(dao);
String feed = CloudContextService.getLikelyFeedName(reference);
ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();

Collection<String> problemRoutes;
Expand All @@ -76,7 +77,6 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) {
}



int[] tripsToday;
int[] tripsTomorrow;
int[] tripsNextDay;
Expand All @@ -91,16 +91,17 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) {
tripsNextDay = hasRouteServiceForDate(dao, reference, refCalendarService, nextDay, problemRoutes);
tripsDayAfterNext = hasRouteServiceForDate(dao, reference, refCalendarService, dayAfterNext, problemRoutes);

_log.info("Feed for metrics: {}", feed);
_log.info("Active routes {}: {}, {}: {}, {}: {}, {}: {}",
today, tripsToday, tomorrow, tripsTomorrow, nextDay, tripsNextDay, dayAfterNext, tripsDayAfterNext);
es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsToday", "feed", feed, tripsTomorrow[ACTIVE_ROUTES]);
es.publishMetric(CloudContextService.getNamespace(), "RoutesMissingTripsFromRefButInAtisToday", "feed", feed, tripsTomorrow[ALARMING_ROUTES]);
es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsTomorrow", "feed", feed, tripsTomorrow[ACTIVE_ROUTES]);
es.publishMetric(CloudContextService.getNamespace(), "RoutesMissingTripsFromRefButInAtisTomorrow", "feed", feed, tripsTomorrow[ALARMING_ROUTES]);
es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsIn2Days", "feed", feed, tripsNextDay[ACTIVE_ROUTES]);
es.publishMetric(CloudContextService.getNamespace(), "RoutesMissingTripsFromRefButInAtisIn2Days", "feed", feed, tripsNextDay[ALARMING_ROUTES]);
es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsIn3Days", "feed", feed, tripsDayAfterNext[ACTIVE_ROUTES]);
es.publishMetric(CloudContextService.getNamespace(), "RoutesMissingTripsFromRefButInAtisIn3Days", "feed", feed, tripsDayAfterNext[ALARMING_ROUTES]);
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,
Expand Down
Loading

0 comments on commit 7bc7a9e

Please sign in to comment.