Skip to content

Commit

Permalink
Add showNegativeScheduledArrivals option to data-sources.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
cagryInside committed Jan 6, 2016
1 parent 561d038 commit e1c810a
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
*/
package org.onebusaway.transit_data_federation.impl.beans;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import org.onebusaway.gtfs.model.AgencyAndId;
import org.onebusaway.transit_data.model.ArrivalAndDepartureBean;
import org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean;
Expand All @@ -33,6 +25,7 @@
import org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean;
import org.onebusaway.transit_data.model.trips.TripBean;
import org.onebusaway.transit_data.model.trips.TripStatusBean;
import org.onebusaway.transit_data_federation.impl.realtime.gtfs_realtime.GtfsRealtimeNegativeArrivals;
import org.onebusaway.transit_data_federation.model.TargetTime;
import org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative;
import org.onebusaway.transit_data_federation.services.AgencyAndIdLibrary;
Expand All @@ -57,11 +50,20 @@
import org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry;
import org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao;
import org.onebusaway.transit_data_federation.services.transit_graph.TripEntry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

@Component
@ManagedResource("org.onebusaway.transit_data_federation.impl.beans:name=ArrivalsAndDeparturesBeanServiceImpl")
public class ArrivalsAndDeparturesBeanServiceImpl implements
Expand All @@ -82,6 +84,8 @@ public class ArrivalsAndDeparturesBeanServiceImpl implements
private ServiceAlertsBeanService _serviceAlertsBeanService;

private RealTimeHistoryService _realTimeHistoryService;

private GtfsRealtimeNegativeArrivals _gtfsRealtimeNegativeArrivals;

@Autowired
public void setTransitGraphDao(TransitGraphDao transitGraphDao) {
Expand Down Expand Up @@ -126,6 +130,12 @@ public void setRealTimeHistoryService(
RealTimeHistoryService realTimeHistoryService) {
_realTimeHistoryService = realTimeHistoryService;;
}

@Autowired
public void setGtfsRealtimeNegativeArrivals(
GtfsRealtimeNegativeArrivals _gtfsRealtimeNegativeArrivals) {
this._gtfsRealtimeNegativeArrivals = _gtfsRealtimeNegativeArrivals;
}

private AtomicInteger _stopTimesTotal = new AtomicInteger();

Expand Down Expand Up @@ -159,7 +169,7 @@ public List<ArrivalAndDepartureBean> getArrivalsAndDeparturesByStopId(
AgencyAndId stopId, ArrivalsAndDeparturesQueryBean query) {

StopEntry stop = _transitGraphDao.getStopEntryForId(stopId, true);

long time = query.getTime();

int minutesBefore = Math.max(query.getMinutesBefore(),
Expand Down Expand Up @@ -195,11 +205,19 @@ public List<ArrivalAndDepartureBean> getArrivalsAndDeparturesByStopId(

if (!isArrivalAndDepartureInRange(instance, from, to))
continue;

ArrivalAndDepartureBean bean = getStopTimeInstanceAsBean(time, instance,
stopBeanCache);
applyBlockLocationToBean(instance, bean, time);

boolean isNegativeScheduledArrivalsEnabled = _gtfsRealtimeNegativeArrivals.getShowNegativeScheduledArrivalByAgencyId(
instance.getBlockTrip().getTrip().getId().getAgencyId());

if(!isNegativeScheduledArrivalsEnabled && bean.getNumberOfStopsAway() < 0 && bean.getPredictedArrivalTime() <= 0)
continue;

applySituationsToBean(time, instance, bean);

beans.add(bean);
}

Expand Down Expand Up @@ -405,7 +423,7 @@ private boolean isArrivalAndDepartureInRange(

return false;
}

private static class ArrivalAndDepartureComparator implements
Comparator<ArrivalAndDepartureBean> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (C) 2016 University of South Florida
*
* 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.transit_data_federation.impl.realtime.gtfs_realtime;

public interface GtfsRealtimeNegativeArrivals {

public Boolean getShowNegativeScheduledArrivalByAgencyId(String agencyId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright (C) 2016 University of South Florida
*
* 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.transit_data_federation.impl.realtime.gtfs_realtime;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.annotation.PostConstruct;

@Component
public class GtfsRealtimeNegativeArrivalsImpl implements
GtfsRealtimeNegativeArrivals, InitializingBean {

private Map<String, Boolean> agencyNegativeScheduledArrivalMap;

private Map<String,GtfsRealtimeSource> gtfsRealtimeSourceMap;

@Autowired
public void setGtfsRealtimeSourceMap(
Map<String, GtfsRealtimeSource> gtfsRealtimeSourceMap) {
this.gtfsRealtimeSourceMap = gtfsRealtimeSourceMap;
}

@Override
public void afterPropertiesSet() throws Exception {
init();
}

@SuppressWarnings("rawtypes")
@PostConstruct
public void init() {
Iterator it = gtfsRealtimeSourceMap.entrySet().iterator();
agencyNegativeScheduledArrivalMap = new HashMap<String, Boolean>();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
GtfsRealtimeSource grs = (GtfsRealtimeSource) pair.getValue();
for (String id : grs.getAgencyIds()) {
agencyNegativeScheduledArrivalMap.put(id, grs.getShowNegativeScheduledArrivals());
}
}
}

@Override
public Boolean getShowNegativeScheduledArrivalByAgencyId(String agencyId) {
return agencyNegativeScheduledArrivalMap.get(agencyId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@
*/
package org.onebusaway.transit_data_federation.impl.realtime.gtfs_realtime;

import org.onebusaway.gtfs.model.AgencyAndId;
import org.onebusaway.realtime.api.VehicleLocationListener;
import org.onebusaway.realtime.api.VehicleLocationRecord;
import org.onebusaway.transit_data_federation.services.AgencyService;
import org.onebusaway.transit_data_federation.services.blocks.BlockCalendarService;
import org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts;
import org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert;
import org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlertsService;
import org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao;

import com.google.protobuf.ExtensionRegistry;
import com.google.transit.realtime.GtfsRealtime.Alert;
import com.google.transit.realtime.GtfsRealtime.FeedEntity;
import com.google.transit.realtime.GtfsRealtime.FeedHeader;
import com.google.transit.realtime.GtfsRealtime.FeedMessage;
import com.google.transit.realtime.GtfsRealtimeConstants;
import com.google.transit.realtime.GtfsRealtimeOneBusAway;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
Expand All @@ -34,27 +56,6 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.onebusaway.gtfs.model.AgencyAndId;
import org.onebusaway.realtime.api.VehicleLocationListener;
import org.onebusaway.realtime.api.VehicleLocationRecord;
import org.onebusaway.transit_data_federation.services.AgencyService;
import org.onebusaway.transit_data_federation.services.blocks.BlockCalendarService;
import org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts;
import org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert;
import org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlertsService;
import org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.protobuf.ExtensionRegistry;
import com.google.transit.realtime.GtfsRealtime.Alert;
import com.google.transit.realtime.GtfsRealtime.FeedEntity;
import com.google.transit.realtime.GtfsRealtime.FeedHeader;
import com.google.transit.realtime.GtfsRealtime.FeedMessage;
import com.google.transit.realtime.GtfsRealtimeConstants;
import com.google.transit.realtime.GtfsRealtimeOneBusAway;

public class GtfsRealtimeSource {

private static final Logger _log = LoggerFactory.getLogger(GtfsRealtimeSource.class);
Expand Down Expand Up @@ -87,6 +88,8 @@ public class GtfsRealtimeSource {
private URL _alertsUrl;

private int _refreshInterval = 30;

private boolean _showNegativeScheduledArrivals = true;

private List<String> _agencyIds = new ArrayList<String>();

Expand All @@ -111,7 +114,7 @@ public class GtfsRealtimeSource {
private GtfsRealtimeTripLibrary _tripsLibrary;

private GtfsRealtimeAlertLibrary _alertLibrary;

@Autowired
public void setAgencyService(AgencyService agencyService) {
_agencyService = agencyService;
Expand Down Expand Up @@ -167,6 +170,18 @@ public void setAgencyId(String agencyId) {
public void setAgencyIds(List<String> agencyIds) {
_agencyIds.addAll(agencyIds);
}

public void setShowNegativeScheduledArrivals(boolean _showNegativeScheduledArrivals) {
this._showNegativeScheduledArrivals = _showNegativeScheduledArrivals;
}

public boolean getShowNegativeScheduledArrivals() {
return _showNegativeScheduledArrivals;
}

public List<String> getAgencyIds() {
return _agencyIds;
}

@PostConstruct
public void start() {
Expand Down

0 comments on commit e1c810a

Please sign in to comment.