Search in sources :

Example 1 with AgencyAndIdInstance

use of org.onebusaway.gtfs.model.AgencyAndIdInstance in project onebusaway-application-modules by camsys.

the class BlockLocationHistoryTask method loadRecords.

private Map<AgencyAndId, BlockLocationArchiveRecordMap> loadRecords(List<BlockLocationArchiveRecord> records) {
    Map<AgencyAndId, BlockLocationArchiveRecordMap> recordsByTrip = new FactoryMap<AgencyAndId, BlockLocationArchiveRecordMap>(new BlockLocationArchiveRecordMap());
    for (BlockLocationArchiveRecord record : records) {
        AgencyAndId tripId = record.getTripId();
        AgencyAndIdInstance instance = new AgencyAndIdInstance(tripId, record.getServiceDate());
        recordsByTrip.get(record.getTripId()).get(instance).add(record);
    }
    return recordsByTrip;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) AgencyAndIdInstance(org.onebusaway.gtfs.model.AgencyAndIdInstance) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockLocationArchiveRecord(org.onebusaway.transit_data_federation.impl.realtime.history.BlockLocationArchiveRecord)

Example 2 with AgencyAndIdInstance

use of org.onebusaway.gtfs.model.AgencyAndIdInstance in project onebusaway-application-modules by camsys.

the class BlockLocationHistoryServiceImpl method getHistoryForTripId.

@Override
public Map<AgencyAndIdInstance, List<BlockLocationArchiveRecord>> getHistoryForTripId(AgencyAndId tripId) {
    TripEntry trip = _transitGraphDao.getTripEntryForId(tripId);
    if (trip == null)
        return null;
    BlockEntry block = trip.getBlock();
    List<File> files = getFilesForBlockId(block.getId());
    CsvEntityReader reader = new CsvEntityReader();
    reader.setTokenizerStrategy(new DelimiterTokenizerStrategy("\t"));
    EntityHandlerImpl handler = new EntityHandlerImpl(tripId);
    reader.addEntityHandler(handler);
    try {
        for (File file : files) {
            InputStream in = openFileForInput(file);
            reader.readEntities(BlockLocationArchiveRecord.class, in);
            in.close();
        }
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
    Map<AgencyAndIdInstance, List<BlockLocationArchiveRecord>> recordsByInstance = handler.getRecordsByInstance();
    for (List<BlockLocationArchiveRecord> records : recordsByInstance.values()) Collections.sort(records, new DistanceAlongBlockComparator());
    return recordsByInstance;
}
Also used : AgencyAndIdInstance(org.onebusaway.gtfs.model.AgencyAndIdInstance) GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) IOException(java.io.IOException) DelimiterTokenizerStrategy(org.onebusaway.csv_entities.DelimiterTokenizerStrategy) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ArrayList(java.util.ArrayList) List(java.util.List) CsvEntityReader(org.onebusaway.csv_entities.CsvEntityReader) File(java.io.File)

Example 3 with AgencyAndIdInstance

use of org.onebusaway.gtfs.model.AgencyAndIdInstance in project onebusaway-application-modules by camsys.

the class BlockLocationHistoryForTripController method index.

@RequestMapping()
public ModelAndView index(@RequestParam() String tripId) {
    AgencyAndId id = AgencyAndIdLibrary.convertFromString(tripId);
    Map<AgencyAndIdInstance, List<BlockLocationArchiveRecord>> histories = _service.getHistoryForTripId(id);
    ModelAndView mv = new ModelAndView("block-location-history-for-trip.jspx");
    mv.addObject("histories", histories);
    return mv;
}
Also used : AgencyAndIdInstance(org.onebusaway.gtfs.model.AgencyAndIdInstance) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AgencyAndIdInstance (org.onebusaway.gtfs.model.AgencyAndIdInstance)3 List (java.util.List)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 FactoryMap (org.onebusaway.collections.FactoryMap)1 CsvEntityReader (org.onebusaway.csv_entities.CsvEntityReader)1 DelimiterTokenizerStrategy (org.onebusaway.csv_entities.DelimiterTokenizerStrategy)1 BlockLocationArchiveRecord (org.onebusaway.transit_data_federation.impl.realtime.history.BlockLocationArchiveRecord)1 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)1 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1