Skip to content

Commit

Permalink
Merge branch 'dev' into 233-add-remove-today
Browse files Browse the repository at this point in the history
  • Loading branch information
tisseo-deploy authored May 3, 2024
2 parents 6be06b3 + 6c1a0c2 commit 9b137c5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@

import org.onebusaway.csv_entities.schema.annotations.CsvField;
import org.onebusaway.gtfs.model.ServiceCalendar;
import org.onebusaway.gtfs.model.ServiceCalendarDate;
import org.onebusaway.gtfs.services.GtfsMutableRelationalDao;
import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy;
import org.onebusaway.gtfs_transformer.services.TransformContext;
import org.onebusaway.gtfs_transformer.util.CalendarFunctions;

import java.util.HashSet;
import java.util.Set;

/**
* Remove calendar dates that are past.
*
Expand Down Expand Up @@ -64,5 +68,16 @@ public void run(TransformContext transformContext, GtfsMutableRelationalDao gtfs
for (ServiceCalendar serviceCalendar : serviceCalendarsToRemove) {
removeEntityLibrary.removeCalendar(gtfsMutableRelationalDao, serviceCalendar.getServiceId());
}

Set<ServiceCalendarDate> serviceCalendarDatesToRemove = new HashSet<ServiceCalendarDate>();
for (ServiceCalendarDate calendarDate : gtfsMutableRelationalDao.getAllCalendarDates()) {
if (calendarDate.getDate().getAsDate().before(today)) {
serviceCalendarDatesToRemove.add(calendarDate);
}
}
for (ServiceCalendarDate serviceCalendarDate : serviceCalendarDatesToRemove) {
// here we can't delete the trips as the serviceid may be active elsewhere
removeEntityLibrary.removeServiceCalendarDate(gtfsMutableRelationalDao, serviceCalendarDate);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.onebusaway.gtfs_transformer.impl;

import org.onebusaway.csv_entities.schema.annotations.CsvField;
import org.onebusaway.gtfs.model.ServiceCalendar;
import org.onebusaway.gtfs.model.ServiceCalendarDate;
import org.onebusaway.gtfs.services.GtfsMutableRelationalDao;
Expand All @@ -35,6 +36,31 @@
public class TruncateNewCalendarStatements implements GtfsTransformStrategy {

private final Logger _log = LoggerFactory.getLogger(TruncateNewCalendarStatements.class);

/*
* add two arguments used in the truncated transformation strategy
* calendarField --> calendar_field (json config file)
* Calendar.YEAR = 1
* Calendar.MONTH = 2
* Calendar.DAY_OF_MONTH = 5
* Calendar.DAY_OF_YEAR = 6
* calendarAmount --> calendar_amount (json config file)
*/
@CsvField(optional = true)
private int calendarField = Calendar.MONTH;

@CsvField(optional = true)
private int calendarAmount = 1;


public void setCalendarField(int calendarField) {
this.calendarField = calendarField;
}

public void setCalendarAmount(int calendarAmount) {
this.calendarAmount = calendarAmount;
}

@Override
public String getName() {
return this.getClass().getSimpleName();
Expand All @@ -43,9 +69,8 @@ public String getName() {
@Override
public void run(TransformContext transformContext, GtfsMutableRelationalDao gtfsMutableRelationalDao) {
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
// TODO make this an argument -- default to one month from now
Calendar c = Calendar.getInstance();
c.roll(Calendar.MONTH, 1);
c.add(calendarField, calendarAmount);
java.util.Date oneMonthFromNow = c.getTime();
Set<ServiceCalendar> serviceCalendarsToRemove = new HashSet<ServiceCalendar>();
for (ServiceCalendar calendar: gtfsMutableRelationalDao.getAllCalendars()) {
Expand Down

0 comments on commit 9b137c5

Please sign in to comment.