From 8c3b17c3c2b147213a5cce789a32be6281d98709 Mon Sep 17 00:00:00 2001 From: Rob Stine Date: Tue, 2 Mar 2021 20:53:43 -0500 Subject: [PATCH] #2019 Update dwell time calculation to correctly track dwell times. Create dwell times even if they have a "negative" time (i.e. the "next" flight takes off before the first flight lands). Update loader to calculate UTC times at start of flight vo instead of as flights and booking details are created. Updated sort to sort on UTC time instead of local time. --- .../main/java/gov/gtas/model/DwellTime.java | 14 ++++++++-- .../gov/gtas/services/GtasLoaderImpl.java | 25 +++++++++++------- .../java/gov/gtas/services/LoaderUtils.java | 16 +++--------- .../java/gov/gtas/parsers/vo/FlightVo.java | 26 ++++++++++++++++++- 4 files changed, 56 insertions(+), 25 deletions(-) diff --git a/gtas-parent/gtas-commons/src/main/java/gov/gtas/model/DwellTime.java b/gtas-parent/gtas-commons/src/main/java/gov/gtas/model/DwellTime.java index d3511bdadd..367e501b06 100644 --- a/gtas-parent/gtas-commons/src/main/java/gov/gtas/model/DwellTime.java +++ b/gtas-parent/gtas-commons/src/main/java/gov/gtas/model/DwellTime.java @@ -17,10 +17,17 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.persistence.Transient; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Entity @Table(name = "dwell_time") public class DwellTime implements Serializable { + + @Transient + public static Logger logger = LoggerFactory.getLogger(DwellTime.class); private static final long serialVersionUID = 1L; @@ -35,11 +42,14 @@ public DwellTime(Date arrival, Date departure, String airport, Pnr pnr) { // java.lang.NullPointerException issue #307 code fix if (this.departureTime != null && this.arrivalTime != null) { long diff = this.departureTime.getTime() - this.arrivalTime.getTime(); - if (diff > 0) { + if (diff < 0) { + logger.warn("Arrival Time of incoming flight AFTER departure time of outgoing flight. Likely bad data!"); + } int minutes = (int) TimeUnit.MINUTES.convert(diff, TimeUnit.MILLISECONDS); DecimalFormat df = new DecimalFormat("#.##"); this.dwellTime = Double.valueOf(df.format((double) minutes / 60)); - } + } else { + logger.warn("Unable to calculate dwell time, etd or eta missing from arriving or departing flight!"); } } diff --git a/gtas-parent/gtas-loader/src/main/java/gov/gtas/services/GtasLoaderImpl.java b/gtas-parent/gtas-loader/src/main/java/gov/gtas/services/GtasLoaderImpl.java index 4846a67bd0..8984d81e47 100644 --- a/gtas-parent/gtas-loader/src/main/java/gov/gtas/services/GtasLoaderImpl.java +++ b/gtas-parent/gtas-loader/src/main/java/gov/gtas/services/GtasLoaderImpl.java @@ -379,7 +379,9 @@ public void calculateDwellTimes(Pnr pnr) { if (CollectionUtils.isEmpty(legs)) { return; } - + + //order flight legs from first to last to create dwell times. + legs.sort(Comparator.comparing(FlightLeg::getLegNumber)); for (int i = 0; i < legs.size(); i++) { if (i + 1 < legs.size()) { // If the 'next' leg actually exists // 4 different combinations of flights and booking details n^2, where n = 2. @@ -532,8 +534,18 @@ public Flight processFlightsAndBookingDetails(List flights, Set flights, Set flights) { - flights.sort(Comparator.comparing(FlightVo::getLocalEtdDate)); + flights.sort(Comparator.comparing(FlightVo::getUtcEtdDate)); } /** diff --git a/gtas-parent/gtas-parsers/src/main/java/gov/gtas/parsers/vo/FlightVo.java b/gtas-parent/gtas-parsers/src/main/java/gov/gtas/parsers/vo/FlightVo.java index 9b8947aacd..04baada5c3 100644 --- a/gtas-parent/gtas-parsers/src/main/java/gov/gtas/parsers/vo/FlightVo.java +++ b/gtas-parent/gtas-parsers/src/main/java/gov/gtas/parsers/vo/FlightVo.java @@ -33,11 +33,18 @@ public class FlightVo implements Validatable { // THIS IS NOT UTC TIME. LOCAL ETA DATE IS IN WHATEVER LOCAL TIME OF THE AIRPORT // WHERE FLIGHT IS DESTINED TO private Date localEtaDate; + + // UTC TIME CONVERSIONS HAPPEN IN LOADER *NOT* GTAS PARSER. + private Date utcEtdDate; + + // UTC TIME CONVERSIONS HAPPEN IN LOADER *NOT* GTAS PARSER. + private Date utcEtaDate; + private String marketingFlightNumber; private boolean isCodeShareFlight = false; private boolean isMarketingFlight = false; private String idTag; - + public void setUuid(UUID uuid) { this.uuid = uuid; } @@ -137,7 +144,24 @@ public boolean isValid() { public UUID getUuid() { return uuid; } + + public Date getUtcEtdDate() { + return utcEtdDate; + } + + public void setUtcEtdDate(Date utcEtdDate) { + this.utcEtdDate = utcEtdDate; + } + + public Date getUtcEtaDate() { + return utcEtaDate; + } + + public void setUtcEtaDate(Date utcEtaDate) { + this.utcEtaDate = utcEtaDate; + } + //TODO: CheckEqualityToBD public boolean equalsThisBD(BookingDetail bookingDetail) { return flightNumber != null && flightNumber.equals(bookingDetail.getFlightNumber()) && localEtdDate != null && DateUtils.stripTime(localEtdDate).equals(bookingDetail.getEtdDate()) && origin != null