Search in sources :

Example 1 with ServiceDateRange

use of org.onebusaway.admin.model.ServiceDateRange in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImplTest method testGetServiceDateRange.

@Test
public void testGetServiceDateRange() throws Exception {
    BundleValidationServiceImpl impl = new BundleValidationServiceImpl();
    // load zip file
    InputStream input = this.getClass().getResourceAsStream("google_transit_staten_island.zip");
    assertNotNull(input);
    List<ServiceDateRange> ranges = impl.getServiceDateRanges(input);
    assertNotNull(ranges);
    assertTrue(ranges.size() == 4);
    ServiceDateRange sdr0 = ranges.get(0);
    assertEquals("MTA NYCT", sdr0.getAgencyId());
    assertEquals(2012, sdr0.getStartDate().getYear());
    assertEquals(4, sdr0.getStartDate().getMonth());
    assertEquals(8, sdr0.getStartDate().getDay());
    assertEquals(2012, sdr0.getEndDate().getYear());
    assertEquals(7, sdr0.getEndDate().getMonth());
    assertEquals(7, sdr0.getEndDate().getDay());
}
Also used : ServiceDateRange(org.onebusaway.admin.model.ServiceDateRange) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) Test(org.junit.Test)

Example 2 with ServiceDateRange

use of org.onebusaway.admin.model.ServiceDateRange in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImplTest method testCommonServiceDateRangeAcrossGTFS.

@Test
public void testCommonServiceDateRangeAcrossGTFS() throws Exception {
    BundleValidationServiceImpl impl = new BundleValidationServiceImpl();
    // load zip file
    ArrayList<InputStream> inputs = new ArrayList<InputStream>();
    inputs.add(this.getClass().getResourceAsStream("google_transit_staten_island.zip"));
    inputs.add(this.getClass().getResourceAsStream("google_transit_manhattan.zip"));
    Map<String, List<ServiceDateRange>> map = impl.getServiceDateRangesAcrossAllGtfs(inputs);
    ServiceDateRange sdr0 = map.get("MTA NYCT").get(0);
    assertEquals(2012, sdr0.getStartDate().getYear());
    assertEquals(4, sdr0.getStartDate().getMonth());
    assertEquals(8, sdr0.getStartDate().getDay());
    assertEquals(2012, sdr0.getEndDate().getYear());
    assertEquals(7, sdr0.getEndDate().getMonth());
    assertEquals(7, sdr0.getEndDate().getDay());
}
Also used : ServiceDateRange(org.onebusaway.admin.model.ServiceDateRange) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 3 with ServiceDateRange

use of org.onebusaway.admin.model.ServiceDateRange in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImplTest method testCommonServiceDateRange.

@Test
public void testCommonServiceDateRange() throws Exception {
    BundleValidationServiceImpl impl = new BundleValidationServiceImpl();
    // load zip file
    InputStream input = this.getClass().getResourceAsStream("google_transit_staten_island.zip");
    assertNotNull(input);
    List<ServiceDateRange> ranges = impl.getServiceDateRanges(input);
    Map<String, List<ServiceDateRange>> map = impl.getServiceDateRangesByAgencyId(ranges);
    ServiceDateRange sdr0 = map.get("MTA NYCT").get(0);
    assertEquals("MTA NYCT", sdr0.getAgencyId());
    assertEquals(2012, sdr0.getStartDate().getYear());
    assertEquals(4, sdr0.getStartDate().getMonth());
    assertEquals(8, sdr0.getStartDate().getDay());
    assertEquals(2012, sdr0.getEndDate().getYear());
    assertEquals(7, sdr0.getEndDate().getMonth());
    assertEquals(7, sdr0.getEndDate().getDay());
}
Also used : ServiceDateRange(org.onebusaway.admin.model.ServiceDateRange) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with ServiceDateRange

use of org.onebusaway.admin.model.ServiceDateRange in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImpl method getServiceDateRangesByAgencyId.

@Override
public /**
 * collect all service date ranges in the list, and return
 * map of key=agencyId, value=ServiceDateRange
 */
Map<String, List<ServiceDateRange>> getServiceDateRangesByAgencyId(List<ServiceDateRange> ranges) {
    HashMap<String, List<ServiceDateRange>> map = new HashMap<String, List<ServiceDateRange>>();
    for (ServiceDateRange sd : ranges) {
        List<ServiceDateRange> list = map.get(sd.getAgencyId());
        if (list == null) {
            list = new ArrayList<ServiceDateRange>();
        }
        list.add(sd);
        map.put(sd.getAgencyId(), list);
    }
    return map;
}
Also used : ServiceDateRange(org.onebusaway.admin.model.ServiceDateRange) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ServiceDateRange

use of org.onebusaway.admin.model.ServiceDateRange in project onebusaway-application-modules by camsys.

the class BundleValidationServiceImpl method convertToServiceDateRange.

private List<ServiceDateRange> convertToServiceDateRange(String agencyId, String calendarFile) {
    String[] entries = calendarFile.split("\n");
    List<ServiceDateRange> ranges = new ArrayList<ServiceDateRange>();
    int line = 0;
    for (String entry : entries) {
        // skip header
        if (line != 0) {
            String[] columns = entry.split(",");
            if (columns.length > 9) {
                ranges.add(new ServiceDateRange(agencyId, parseDate(columns[8]), parseDate(columns[9])));
            }
        }
        line++;
    }
    return ranges;
}
Also used : ServiceDateRange(org.onebusaway.admin.model.ServiceDateRange) ArrayList(java.util.ArrayList)

Aggregations

ServiceDateRange (org.onebusaway.admin.model.ServiceDateRange)5 ArrayList (java.util.ArrayList)4 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 List (java.util.List)3 Test (org.junit.Test)3 BundleValidationServiceImpl (org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl)3 HashMap (java.util.HashMap)1