Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeZone parameter to hsl and parkapi vehicle parking updaters #4427

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/sandbox/VehicleParking.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- Create initial sandbox implementation (January
2022, https://github.com/opentripplanner/OpenTripPlanner/pull/3796)
- Add timeZone parameter to hsl and parkapi updaters (September 2022, https://github.com/opentripplanner/OpenTripPlanner/pull/4427)

## Documentation

Expand Down Expand Up @@ -37,6 +38,7 @@ All updaters have the following parameters in common:
"type": "vehicle-parking",
"sourceType": "hsl-park",
"feedId": "hslpark",
"timeZone": "Europe/Helsinki",
"facilitiesFrequencySec": 3600,
"facilitiesUrl": "https://p.hsl.fi/api/v1/facilities.json?limit=-1",
"utilizationsFrequencySec": 600,
Expand All @@ -45,6 +47,8 @@ All updaters have the following parameters in common:
```

- `sourceType`: needs to be `"hsl-park"`
- `timeZone`: must be configured to parse opening hours.
The value can be given either as a zone id, or an UTC offset.
- `facilitiesUrl`: URL that contains the basic information for the parks
- `facilitiesFrequencySec`: how often should the basic information for parks be refetched. Should be
more than `utilizationsFrequencySec` and if it's <= 0, parks are only fetched once. Default `600`.
Expand Down Expand Up @@ -80,6 +84,7 @@ All updaters have the following parameters in common:
"type": "vehicle-parking",
"sourceType": "park-api",
"feedId": "parkapi",
"timeZone": "Europe/Berlin",
"frequencySec": 600,
"url": "https://foo.bar",
"headers": {"Cache-Control": "max-age=604800"},
Expand All @@ -89,6 +94,8 @@ All updaters have the following parameters in common:

- `sourceType`: needs to be `"park-api"` if car parks are fetched, `"bicycle-park-api"` if bicycle
parks.
- `timeZone`: must be configured to parse opening hours.
The value can be given either as a zone id, or an UTC offset.
- `url`: URL that contains the park data in KML format
- `frequencySec`: how often park data is refetched. Default `60`.
- `headers`: Use these headers for requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class HslParkUpdaterTest {
void parseParks() {
var facilitiesUrl = "file:src/ext-test/resources/vehicleparking/hslpark/facilities.json";
var utilizationsUrl = "file:src/ext-test/resources/vehicleparking/hslpark/utilizations.json";
var timeZone = ZoneId.of("Europe/Helsinki");

var parameters = new HslParkUpdaterParameters(
"",
Expand All @@ -28,18 +29,15 @@ void parseParks() {
"hslpark",
null,
30,
utilizationsUrl
utilizationsUrl,
timeZone
);
var openingHoursCalendarService = new OpeningHoursCalendarService(
new Deduplicator(),
LocalDate.of(2022, Month.JANUARY, 1),
LocalDate.of(2023, Month.JANUARY, 1)
);
var updater = new HslParkUpdater(
parameters,
openingHoursCalendarService,
ZoneId.of("Europe/Helsinki")
);
var updater = new HslParkUpdater(parameters, openingHoursCalendarService);

assertTrue(updater.update());
var parkingLots = updater.getUpdates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@ public class ParkAPIUpdaterTest {
@Test
void parseCars() {
var url = "file:src/ext-test/resources/vehicleparking/parkapi/parkapi-reutlingen.json";

var parameters = new ParkAPIUpdaterParameters("", url, "park-api", 30, null, List.of(), null);
var timeZone = ZoneId.of("Europe/Berlin");
var parameters = new ParkAPIUpdaterParameters(
"",
url,
"park-api",
30,
null,
List.of(),
null,
timeZone
);
var openingHoursCalendarService = new OpeningHoursCalendarService(
new Deduplicator(),
LocalDate.of(2022, Month.JANUARY, 1),
LocalDate.of(2023, Month.JANUARY, 1)
);
var updater = new CarParkAPIUpdater(
parameters,
openingHoursCalendarService,
ZoneId.of("Europe/Berlin")
);
var updater = new CarParkAPIUpdater(parameters, openingHoursCalendarService);

assertTrue(updater.update());
var parkingLots = updater.getUpdates();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.opentripplanner.ext.vehicleparking.hslpark;

import java.time.ZoneId;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -33,12 +32,15 @@ public class HslParkUpdater implements DataSource<VehicleParking> {

public HslParkUpdater(
HslParkUpdaterParameters parameters,
OpeningHoursCalendarService openingHoursCalendarService,
ZoneId zoneId
OpeningHoursCalendarService openingHoursCalendarService
) {
String feedId = parameters.getFeedId();
vehicleParkingMapper =
new HslParkToVehicleParkingMapper(feedId, openingHoursCalendarService, zoneId);
new HslParkToVehicleParkingMapper(
feedId,
openingHoursCalendarService,
parameters.getTimeZone()
);
parkPatchMapper = new HslParkUtilizationToPatchMapper(feedId);
facilitiesDownloader =
new JsonDataListDownloader<>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.ext.vehicleparking.hslpark;

import java.time.ZoneId;
import org.opentripplanner.updater.DataSourceType;
import org.opentripplanner.updater.vehicle_parking.VehicleParkingUpdaterParameters;

Expand All @@ -13,6 +14,7 @@ public class HslParkUpdaterParameters extends VehicleParkingUpdaterParameters {
private final String facilitiesUrl;
private final String feedId;
private final String utilizationsUrl;
private final ZoneId timeZone;

public HslParkUpdaterParameters(
String configRef,
Expand All @@ -21,13 +23,15 @@ public HslParkUpdaterParameters(
String feedId,
DataSourceType sourceType,
int utilizationsFrequencySec,
String utilizationsUrl
String utilizationsUrl,
ZoneId timeZone
) {
super(configRef, utilizationsFrequencySec, sourceType);
this.facilitiesFrequencySec = facilitiesFrequencySec;
this.facilitiesUrl = facilitiesUrl;
this.feedId = feedId;
this.utilizationsUrl = utilizationsUrl;
this.timeZone = timeZone;
}

public int getFacilitiesFrequencySec() {
Expand All @@ -45,4 +49,8 @@ public String getFacilitiesUrl() {
public String getUtilizationsUrl() {
return utilizationsUrl;
}

public ZoneId getTimeZone() {
return timeZone;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.opentripplanner.ext.vehicleparking.parkapi;

import com.fasterxml.jackson.databind.JsonNode;
import java.time.ZoneId;
import org.opentripplanner.model.calendar.openinghours.OpeningHoursCalendarService;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces;

Expand All @@ -13,10 +12,9 @@ public class BicycleParkAPIUpdater extends ParkAPIUpdater {

public BicycleParkAPIUpdater(
ParkAPIUpdaterParameters parameters,
OpeningHoursCalendarService openingHoursCalendarService,
ZoneId zoneId
OpeningHoursCalendarService openingHoursCalendarService
) {
super(parameters, openingHoursCalendarService, zoneId);
super(parameters, openingHoursCalendarService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.opentripplanner.ext.vehicleparking.parkapi;

import com.fasterxml.jackson.databind.JsonNode;
import java.time.ZoneId;
import org.opentripplanner.model.calendar.openinghours.OpeningHoursCalendarService;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces;

Expand All @@ -13,10 +12,9 @@ public class CarParkAPIUpdater extends ParkAPIUpdater {

public CarParkAPIUpdater(
ParkAPIUpdaterParameters parameters,
OpeningHoursCalendarService openingHoursCalendarService,
ZoneId zoneId
OpeningHoursCalendarService openingHoursCalendarService
) {
super(parameters, openingHoursCalendarService, zoneId);
super(parameters, openingHoursCalendarService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import ch.poole.openinghoursparser.OpeningHoursParseException;
import com.fasterxml.jackson.databind.JsonNode;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -39,13 +38,13 @@ abstract class ParkAPIUpdater extends GenericJsonDataSource<VehicleParking> {

public ParkAPIUpdater(
ParkAPIUpdaterParameters parameters,
OpeningHoursCalendarService openingHoursCalendarService,
ZoneId zoneId
OpeningHoursCalendarService openingHoursCalendarService
) {
super(parameters.getUrl(), JSON_PARSE_PATH, parameters.getHttpHeaders());
this.feedId = parameters.getFeedId();
this.staticTags = parameters.getTags();
this.osmOpeningHoursParser = new OSMOpeningHoursParser(openingHoursCalendarService, zoneId);
this.osmOpeningHoursParser =
new OSMOpeningHoursParser(openingHoursCalendarService, parameters.getTimeZone());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.ext.vehicleparking.parkapi;

import java.time.ZoneId;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand All @@ -17,6 +18,7 @@ public class ParkAPIUpdaterParameters extends VehicleParkingUpdaterParameters {
private final String feedId;
private final Map<String, String> httpHeaders;
private final List<String> tags;
private final ZoneId timeZone;

public ParkAPIUpdaterParameters(
String configRef,
Expand All @@ -25,13 +27,15 @@ public ParkAPIUpdaterParameters(
int frequencySec,
@Nonnull Map<String, String> httpHeaders,
List<String> tags,
DataSourceType sourceType
DataSourceType sourceType,
ZoneId timeZone
) {
super(configRef, frequencySec, sourceType);
this.url = url;
this.feedId = feedId;
this.httpHeaders = httpHeaders;
this.tags = tags;
this.timeZone = timeZone;
}

public String getFeedId() {
Expand All @@ -49,4 +53,8 @@ public Map<String, String> getHttpHeaders() {
public Collection<String> getTags() {
return tags;
}

public ZoneId getTimeZone() {
return timeZone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class VehicleParkingUpdaterConfig {
public static VehicleParkingUpdaterParameters create(String updaterRef, NodeAdapter c) {
var sourceType = mapStringToSourceType(c.asText("sourceType"));
var feedId = c.asText("feedId", null);
var timeZone = c.asZoneId("timeZone", null);
switch (sourceType) {
case HSL_PARK:
return new HslParkUpdaterParameters(
Expand All @@ -35,7 +36,8 @@ public static VehicleParkingUpdaterParameters create(String updaterRef, NodeAdap
feedId,
sourceType,
c.asInt("utilizationsFrequencySec", 600),
c.asText("utilizationsUrl", null)
c.asText("utilizationsUrl", null),
timeZone
);
case KML:
return new KmlUpdaterParameters(
Expand All @@ -56,7 +58,8 @@ public static VehicleParkingUpdaterParameters create(String updaterRef, NodeAdap
c.asInt("frequencySec", 60),
c.asMap("headers", NodeAdapter::asText),
new ArrayList<>(c.asTextSet("tags", Set.of())),
sourceType
sourceType,
timeZone
);
default:
throw new OtpAppException("The updater source type is unhandled: " + sourceType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.opentripplanner.updater.configure;

import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import org.opentripplanner.ext.siri.SiriTimetableSnapshotSource;
Expand Down Expand Up @@ -123,7 +122,6 @@ private List<GraphUpdater> fetchVehicleRentalServicesFromOnlineDirectory(
*/
private List<GraphUpdater> createUpdatersFromConfig() {
OpeningHoursCalendarService openingHoursCalendarService = graph.getOpeningHoursCalendarService();
ZoneId zoneId = transitModel.getTimeZone();

List<GraphUpdater> updaters = new ArrayList<>();

Expand Down Expand Up @@ -180,11 +178,7 @@ private List<GraphUpdater> createUpdatersFromConfig() {
);
}
for (var configItem : updatersParameters.getVehicleParkingUpdaterParameters()) {
var source = VehicleParkingDataSourceFactory.create(
configItem,
openingHoursCalendarService,
zoneId
);
var source = VehicleParkingDataSourceFactory.create(configItem, openingHoursCalendarService);
updaters.add(
new VehicleParkingUpdater(
configItem,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.opentripplanner.updater.vehicle_parking;

import java.time.ZoneId;
import org.opentripplanner.ext.vehicleparking.hslpark.HslParkUpdater;
import org.opentripplanner.ext.vehicleparking.hslpark.HslParkUpdaterParameters;
import org.opentripplanner.ext.vehicleparking.kml.KmlBikeParkDataSource;
Expand All @@ -21,29 +20,25 @@ private VehicleParkingDataSourceFactory() {}

public static DataSource<VehicleParking> create(
VehicleParkingUpdaterParameters parameters,
OpeningHoursCalendarService openingHoursCalendarService,
ZoneId zoneId
OpeningHoursCalendarService openingHoursCalendarService
) {
switch (parameters.getSourceType()) {
case HSL_PARK:
return new HslParkUpdater(
(HslParkUpdaterParameters) parameters,
openingHoursCalendarService,
zoneId
openingHoursCalendarService
);
case KML:
return new KmlBikeParkDataSource((KmlUpdaterParameters) parameters);
case PARK_API:
return new CarParkAPIUpdater(
(ParkAPIUpdaterParameters) parameters,
openingHoursCalendarService,
zoneId
openingHoursCalendarService
);
case BICYCLE_PARK_API:
return new BicycleParkAPIUpdater(
(ParkAPIUpdaterParameters) parameters,
openingHoursCalendarService,
zoneId
openingHoursCalendarService
);
}
throw new IllegalArgumentException(
Expand Down