Search in sources :

Example 1 with T2

use of org.onebusaway.collections.tuple.T2 in project onebusaway-application-modules by camsys.

the class ScheduleAction method getTimesByFormatKey.

private <T> List<T2<String, List<T>>> getTimesByFormatKey(List<T> stopTimes, String format, IAdapter<T, Date> adapter) {
    SimpleDateFormat df = new SimpleDateFormat(format);
    df.setTimeZone(_timeZone);
    List<T2<String, List<T>>> tuples = new ArrayList<T2<String, List<T>>>();
    T2<String, List<T>> tuple = null;
    for (T bean : stopTimes) {
        Date date = adapter.adapt(bean);
        String key = df.format(date);
        if (tuple == null || !tuple.getFirst().equals(key)) {
            if (tuple != null && !tuple.getSecond().isEmpty())
                tuples.add(tuple);
            List<T> beans = new ArrayList<T>();
            tuple = Tuples.tuple(key, beans);
        }
        tuple.getSecond().add(bean);
    }
    if (tuple != null && !tuple.getSecond().isEmpty())
        tuples.add(tuple);
    return tuples;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) T2(org.onebusaway.collections.tuple.T2) Date(java.util.Date)

Example 2 with T2

use of org.onebusaway.collections.tuple.T2 in project onebusaway-application-modules by camsys.

the class UserReportingDaoImpl method getStopProblemReportSummaries.

@SuppressWarnings("unchecked")
@Override
public List<T2<AgencyAndId, Integer>> getStopProblemReportSummaries(String agencyId, long timeFrom, long timeTo, EProblemReportStatus status) {
    List<Object[]> records = null;
    if (status == null) {
        String[] names = { "agencyId", "timeFrom", "timeTo" };
        Object[] values = { agencyId, timeFrom, timeTo };
        records = _template.findByNamedQueryAndNamedParam("stopProblemReportSummaries", names, values);
    } else {
        String[] names = { "agencyId", "timeFrom", "timeTo", "status" };
        Object[] values = { agencyId, timeFrom, timeTo, status };
        records = _template.findByNamedQueryAndNamedParam("stopProblemReportSummariesWithStatus", names, values);
    }
    List<T2<AgencyAndId, Integer>> results = new ArrayList<T2<AgencyAndId, Integer>>(records.size());
    for (Object[] record : records) {
        AgencyAndId stopId = (AgencyAndId) record[0];
        Long count = (Long) record[1];
        results.add(Tuples.tuple(stopId, count.intValue()));
    }
    return results;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) T2(org.onebusaway.collections.tuple.T2)

Example 3 with T2

use of org.onebusaway.collections.tuple.T2 in project onebusaway-application-modules by camsys.

the class UserReportingServiceImpl method getTripProblemReportSummaries.

@Override
public ListBean<TripProblemReportSummaryBean> getTripProblemReportSummaries(TripProblemReportQueryBean query, ETripProblemGroupBy groupBy) {
    List<T2<Object, Integer>> records = _userReportingDao.getTripProblemReportSummaries(query, groupBy);
    List<TripProblemReportSummaryBean> beans = new ArrayList<TripProblemReportSummaryBean>(records.size());
    for (T2<Object, Integer> record : records) {
        TripProblemReportSummaryBean bean = new TripProblemReportSummaryBean();
        bean.setCount(record.getSecond());
        switch(groupBy) {
            case TRIP:
                {
                    AgencyAndId tripId = (AgencyAndId) record.getFirst();
                    bean.setTrip(_tripBeanService.getTripForId(tripId));
                    break;
                }
            case STATUS:
                {
                    EProblemReportStatus status = (EProblemReportStatus) record.getFirst();
                    bean.setStatus(status);
                    break;
                }
            case LABEL:
                {
                    String label = (String) record.getFirst();
                    bean.setLabel(label);
                    break;
                }
        }
        beans.add(bean);
    }
    return new ListBean<TripProblemReportSummaryBean>(beans, false);
}
Also used : TripProblemReportSummaryBean(org.onebusaway.transit_data.model.problems.TripProblemReportSummaryBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) EProblemReportStatus(org.onebusaway.transit_data.model.problems.EProblemReportStatus) ListBean(org.onebusaway.transit_data.model.ListBean) T2(org.onebusaway.collections.tuple.T2)

Example 4 with T2

use of org.onebusaway.collections.tuple.T2 in project onebusaway-application-modules by camsys.

the class UserReportingServiceImpl method getStopProblemReportSummaries.

@Override
public ListBean<StopProblemReportSummaryBean> getStopProblemReportSummaries(StopProblemReportQueryBean query) {
    List<T2<AgencyAndId, Integer>> records = _userReportingDao.getStopProblemReportSummaries(query.getAgencyId(), query.getTimeFrom(), query.getTimeTo(), query.getStatus());
    List<StopProblemReportSummaryBean> beans = new ArrayList<StopProblemReportSummaryBean>(records.size());
    for (T2<AgencyAndId, Integer> record : records) {
        AgencyAndId stopId = record.getFirst();
        Integer count = record.getSecond();
        StopProblemReportSummaryBean bean = new StopProblemReportSummaryBean();
        bean.setStop(_stopBeanService.getStopForId(stopId));
        bean.setStatus(query.getStatus());
        bean.setCount(count);
        beans.add(bean);
    }
    return new ListBean<StopProblemReportSummaryBean>(beans, false);
}
Also used : StopProblemReportSummaryBean(org.onebusaway.transit_data.model.problems.StopProblemReportSummaryBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) T2(org.onebusaway.collections.tuple.T2)

Example 5 with T2

use of org.onebusaway.collections.tuple.T2 in project onebusaway-application-modules by camsys.

the class UserReportingDaoImplTest method test.

@Test
public void test() {
    TripProblemReportRecord r1 = new TripProblemReportRecord();
    r1.setLabel("label-1");
    r1.setStatus(EProblemReportStatus.NEW);
    r1.setTime(1000);
    r1.setTripId(new AgencyAndId("1", "trip-1"));
    _dao.saveOrUpdate(r1);
    TripProblemReportRecord r2 = new TripProblemReportRecord();
    r2.setLabel("label-2");
    r2.setStatus(EProblemReportStatus.NEW);
    r2.setTime(2000);
    r2.setTripId(new AgencyAndId("1", "trip-1"));
    _dao.saveOrUpdate(r2);
    TripProblemReportRecord r3 = new TripProblemReportRecord();
    r3.setLabel("label-2");
    r3.setStatus(EProblemReportStatus.VERIFIED);
    r3.setTime(3000);
    r3.setTripId(new AgencyAndId("2", "trip-1"));
    _dao.saveOrUpdate(r3);
    List<T2<Object, Integer>> summaries = _dao.getTripProblemReportSummaries(query(null, null, 0, 0, null, null), ETripProblemGroupBy.TRIP);
    assertEquals(2, summaries.size());
    assertEquals(Tuples.tuple(new AgencyAndId("1", "trip-1"), 2), summaries.get(0));
    assertEquals(Tuples.tuple(new AgencyAndId("2", "trip-1"), 1), summaries.get(1));
    summaries = _dao.getTripProblemReportSummaries(query(null, "1_trip-1", 0, 0, null, null), ETripProblemGroupBy.LABEL);
    assertEquals(2, summaries.size());
    assertEquals(Tuples.tuple("label-1", 1), summaries.get(0));
    assertEquals(Tuples.tuple("label-2", 1), summaries.get(1));
    summaries = _dao.getTripProblemReportSummaries(query(null, null, 1500, 2500, null, null), ETripProblemGroupBy.TRIP);
    assertEquals(1, summaries.size());
    assertEquals(Tuples.tuple(new AgencyAndId("1", "trip-1"), 1), summaries.get(0));
    summaries = _dao.getTripProblemReportSummaries(query(null, null, 0, 0, EProblemReportStatus.NEW, null), ETripProblemGroupBy.TRIP);
    assertEquals(1, summaries.size());
    assertEquals(Tuples.tuple(new AgencyAndId("1", "trip-1"), 2), summaries.get(0));
    summaries = _dao.getTripProblemReportSummaries(query(null, null, 0, 0, null, "label-2"), ETripProblemGroupBy.TRIP);
    assertEquals(2, summaries.size());
    assertEquals(Tuples.tuple(new AgencyAndId("1", "trip-1"), 1), summaries.get(0));
    assertEquals(Tuples.tuple(new AgencyAndId("2", "trip-1"), 1), summaries.get(1));
    summaries = _dao.getTripProblemReportSummaries(query(null, null, 0, 0, null, null), ETripProblemGroupBy.STATUS);
    assertEquals(2, summaries.size());
    assertEquals(Tuples.tuple(EProblemReportStatus.NEW, 2), summaries.get(0));
    assertEquals(Tuples.tuple(EProblemReportStatus.VERIFIED, 1), summaries.get(1));
    summaries = _dao.getTripProblemReportSummaries(query(null, null, 0, 0, null, null), ETripProblemGroupBy.LABEL);
    assertEquals(2, summaries.size());
    assertEquals(Tuples.tuple("label-1", 1), summaries.get(0));
    assertEquals(Tuples.tuple("label-2", 2), summaries.get(1));
    /**
     * getTripProblemReports(...)
     */
    List<TripProblemReportRecord> records = _dao.getTripProblemReports(query("1", null, 0, 0, null, null));
    assertEquals(2, records.size());
    records = _dao.getTripProblemReports(query("2", null, 0, 0, null, null));
    assertEquals(1, records.size());
    records = _dao.getTripProblemReports(query(null, "1_trip-1", 0, 0, null, null));
    assertEquals(2, records.size());
    records = _dao.getTripProblemReports(query(null, null, 1500, 2500, null, null));
    assertEquals(1, records.size());
    records = _dao.getTripProblemReports(query(null, null, 1500, 0, null, null));
    assertEquals(2, records.size());
    records = _dao.getTripProblemReports(query(null, null, 0, 0, EProblemReportStatus.NEW, null));
    assertEquals(2, records.size());
    records = _dao.getTripProblemReports(query(null, null, 0, 0, EProblemReportStatus.VERIFIED, null));
    assertEquals(1, records.size());
    records = _dao.getTripProblemReports(query(null, null, 0, 0, EProblemReportStatus.ACCEPTED, null));
    assertEquals(0, records.size());
    records = _dao.getTripProblemReports(query(null, null, 0, 0, null, "label-1"));
    assertEquals(1, records.size());
    records = _dao.getTripProblemReports(query(null, null, 0, 0, null, "label-2"));
    assertEquals(2, records.size());
    records = _dao.getTripProblemReports(query(null, null, 0, 0, null, "label-?"));
    assertEquals(0, records.size());
    records = _dao.getTripProblemReports(query("1", null, 0, 0, null, "label-2"));
    assertEquals(1, records.size());
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) T2(org.onebusaway.collections.tuple.T2) Test(org.junit.Test)

Aggregations

T2 (org.onebusaway.collections.tuple.T2)5 ArrayList (java.util.ArrayList)4 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 ListBean (org.onebusaway.transit_data.model.ListBean)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1 Test (org.junit.Test)1 EProblemReportStatus (org.onebusaway.transit_data.model.problems.EProblemReportStatus)1 StopProblemReportSummaryBean (org.onebusaway.transit_data.model.problems.StopProblemReportSummaryBean)1 TripProblemReportSummaryBean (org.onebusaway.transit_data.model.problems.TripProblemReportSummaryBean)1