Search in sources :

Example 1 with ScheduleDeviationHistogram

use of org.onebusaway.transit_data_federation.services.realtime.ScheduleDeviationHistogram in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesBeanServiceImpl method getArrivalAndDepartureForStop.

@Override
public ArrivalAndDepartureBean getArrivalAndDepartureForStop(ArrivalAndDepartureQuery query) {
    long time = query.getTime();
    ArrivalAndDepartureInstance instance = _arrivalAndDepartureService.getArrivalAndDepartureForStop(query);
    if (instance == null) {
        return null;
    }
    ArrivalAndDepartureBean bean = getStopTimeInstanceAsBean(time, instance, new HashMap<AgencyAndId, StopBean>());
    applyBlockLocationToBean(instance, bean, time);
    applySituationsToBean(time, instance, bean);
    if (!this.useScheduleDeviationHistory) {
        return bean;
    }
    int step = 120;
    ScheduleDeviationHistogram histo = _realTimeHistoryService.getScheduleDeviationHistogramForArrivalAndDepartureInstance(instance, step);
    if (histo != null) {
        int[] sds = histo.getScheduleDeviations();
        double[] values = new double[sds.length];
        String[] labels = new String[sds.length];
        for (int i = 0; i < sds.length; i++) {
            int sd = sds[i];
            values[i] = sd;
            labels[i] = Integer.toString(sd / 60);
        }
        HistogramBean hb = new HistogramBean();
        hb.setValues(values);
        hb.setCounts(histo.getCounts());
        hb.setLabels(labels);
        bean.setScheduleDeviationHistogram(hb);
    }
    return bean;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ScheduleDeviationHistogram(org.onebusaway.transit_data_federation.services.realtime.ScheduleDeviationHistogram) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) StopBean(org.onebusaway.transit_data.model.StopBean) HistogramBean(org.onebusaway.transit_data.model.realtime.HistogramBean)

Example 2 with ScheduleDeviationHistogram

use of org.onebusaway.transit_data_federation.services.realtime.ScheduleDeviationHistogram in project onebusaway-application-modules by camsys.

the class RealTimeHistoryServiceImpl method createHistogramFromValues.

private ScheduleDeviationHistogram createHistogramFromValues(double[] values, int stepSizeInSeconds) {
    values = noNans(values);
    if (values.length == 0)
        return new ScheduleDeviationHistogram(new int[0], new int[0]);
    Range r = new Range();
    for (double v : values) r.addValue(v);
    if (r.getRange() == 0)
        return new ScheduleDeviationHistogram(new int[] { (int) values[0] }, new int[] { values.length });
    int halfStep = stepSizeInSeconds / 2;
    int from = (int) (Math.floor((r.getMin() - halfStep) / stepSizeInSeconds) * stepSizeInSeconds) + halfStep;
    int to = (int) (Math.ceil((r.getMax() + halfStep) / stepSizeInSeconds) * stepSizeInSeconds) - halfStep;
    int columns = (to - from) / stepSizeInSeconds;
    int[] scheduleDeviations = new int[columns];
    int[] counts = new int[columns];
    for (int i = 0; i < columns; i++) scheduleDeviations[i] = from + stepSizeInSeconds * i + halfStep;
    for (double value : values) {
        int index = (int) ((value - from) / stepSizeInSeconds);
        counts[index]++;
    }
    return new ScheduleDeviationHistogram(scheduleDeviations, counts);
}
Also used : ScheduleDeviationHistogram(org.onebusaway.transit_data_federation.services.realtime.ScheduleDeviationHistogram) Range(org.onebusaway.collections.Range)

Aggregations

ScheduleDeviationHistogram (org.onebusaway.transit_data_federation.services.realtime.ScheduleDeviationHistogram)2 Range (org.onebusaway.collections.Range)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 HistogramBean (org.onebusaway.transit_data.model.realtime.HistogramBean)1 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)1