mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 06:08:52 +00:00
AbstractHafasClientInterfaceProvider: In jsonTripSearch() parse only fares listed in 'ovwTrfRefL'.
This commit is contained in:
parent
176bce0790
commit
e307648053
5 changed files with 81 additions and 78 deletions
|
@ -727,42 +727,42 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
|
|||
legs.add(leg);
|
||||
}
|
||||
|
||||
final List<Fare> fares;
|
||||
final JSONObject trfRes = outCon.optJSONObject("trfRes");
|
||||
final List<Fare> fares = new LinkedList<>();
|
||||
if (trfRes != null) {
|
||||
final JSONArray ovwTrfRefList = outCon.optJSONArray("ovwTrfRefL");
|
||||
if (trfRes != null && ovwTrfRefList != null) {
|
||||
fares = new LinkedList<>();
|
||||
final JSONArray fareSetList = trfRes.getJSONArray("fareSetL");
|
||||
for (int iFareSet = 0; iFareSet < fareSetList.length(); iFareSet++) {
|
||||
final JSONObject fareSet = fareSetList.getJSONObject(iFareSet);
|
||||
final String fareSetName = fareSet.optString("name", null);
|
||||
final String fareSetDescription = fareSet.optString("desc", null);
|
||||
if (fareSetName != null || fareSetDescription != null) {
|
||||
final JSONArray fareList = fareSet.getJSONArray("fareL");
|
||||
for (int iFare = 0; iFare < fareList.length(); iFare++) {
|
||||
final JSONObject jsonFare = fareList.getJSONObject(iFare);
|
||||
final String name = jsonFare.getString("name");
|
||||
final JSONArray ticketList = jsonFare.optJSONArray("ticketL");
|
||||
if (ticketList != null) {
|
||||
for (int iTicket = 0; iTicket < ticketList.length(); iTicket++) {
|
||||
final JSONObject jsonTicket = ticketList.getJSONObject(iTicket);
|
||||
for (int i = 0; i < ovwTrfRefList.length(); i++) {
|
||||
final JSONObject ovwTrfRef = ovwTrfRefList.getJSONObject(i);
|
||||
final String type = ovwTrfRef.getString("type");
|
||||
final int fareSetX = ovwTrfRef.getInt("fareSetX");
|
||||
final int fareX = ovwTrfRef.getInt("fareX");
|
||||
final JSONObject jsonFareSet = fareSetList.getJSONObject(fareSetX);
|
||||
final JSONObject jsonFare = jsonFareSet.getJSONArray("fareL").getJSONObject(fareX);
|
||||
final String fareName = jsonFare.getString("name");
|
||||
final Fare fare;
|
||||
if (type.equals("T")) { // ticket
|
||||
final int ticketX = ovwTrfRef.getInt("ticketX");
|
||||
final JSONObject jsonTicket = jsonFare.getJSONArray("ticketL").getJSONObject(ticketX);
|
||||
final String ticketName = jsonTicket.getString("name");
|
||||
final Currency currency = Currency.getInstance(jsonTicket.getString("cur"));
|
||||
final float price = jsonTicket.getInt("prc") / 100f;
|
||||
final Fare fare = parseJsonTripFare(name, fareSetDescription, ticketName,
|
||||
currency, price);
|
||||
if (fare != null)
|
||||
fare = new Fare(normalizeFareName(fareName) + '\n' + ticketName,
|
||||
normalizeFareType(ticketName), currency, price, null, null);
|
||||
} else if (type.equals("F")) { // fare
|
||||
final Currency currency = Currency.getInstance(jsonFare.getString("cur"));
|
||||
final float price = jsonFare.getInt("prc") / 100f;
|
||||
fare = new Fare(normalizeFareName(fareName), normalizeFareType(fareName), currency, price,
|
||||
null, null);
|
||||
} else {
|
||||
throw new IllegalArgumentException("cannot handle type: " + type);
|
||||
}
|
||||
if (!hideFare(fare))
|
||||
fares.add(fare);
|
||||
}
|
||||
} else {
|
||||
final Currency currency = Currency.getInstance(jsonFare.getString("cur"));
|
||||
final float price = jsonFare.getInt("prc") / 100f;
|
||||
final Fare fare = parseJsonTripFare(fareSetName, fareSetDescription, name, currency,
|
||||
price);
|
||||
if (fare != null)
|
||||
fares.add(fare);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fares = null;
|
||||
}
|
||||
|
||||
final Trip trip = new Trip(null, tripFrom, tripTo, legs, fares, null, null);
|
||||
|
@ -777,15 +777,29 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
|
|||
}
|
||||
}
|
||||
|
||||
protected Fare parseJsonTripFare(final @Nullable String fareSetName, final @Nullable String fareSetDescription,
|
||||
final String name, final Currency currency, final float price) {
|
||||
if (name.endsWith("- Jahreskarte") || name.endsWith("- Monatskarte"))
|
||||
return null;
|
||||
if (name.startsWith("Vollpreis - "))
|
||||
return new Fare(fareSetName, Fare.Type.ADULT, currency, price, name.substring(12), null);
|
||||
if (name.startsWith("Kind - "))
|
||||
return new Fare(fareSetName, Fare.Type.CHILD, currency, price, name.substring(7), null);
|
||||
return null;
|
||||
protected Fare.Type normalizeFareType(final String fareName) {
|
||||
final String fareNameLc = fareName.toLowerCase(Locale.US);
|
||||
if (fareNameLc.contains("erwachsene") || fareNameLc.contains("adult"))
|
||||
return Fare.Type.ADULT;
|
||||
if (fareNameLc.contains("kind") || fareNameLc.contains("child") || fareNameLc.contains("kids"))
|
||||
return Fare.Type.CHILD;
|
||||
if (fareNameLc.contains("ermäßigung"))
|
||||
return Fare.Type.CHILD;
|
||||
if (fareNameLc.contains("schüler") || fareNameLc.contains("azubi"))
|
||||
return Fare.Type.STUDENT;
|
||||
if (fareNameLc.contains("fahrrad"))
|
||||
return Fare.Type.BIKE;
|
||||
if (fareNameLc.contains("senior"))
|
||||
return Fare.Type.SENIOR;
|
||||
return Fare.Type.ADULT;
|
||||
}
|
||||
|
||||
protected String normalizeFareName(final String fareName) {
|
||||
return fareName;
|
||||
}
|
||||
|
||||
protected boolean hideFare(final Fare fare) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private String wrapJsonApiRequest(final String meth, final String req, final boolean formatted) {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package de.schildbach.pte;
|
||||
|
||||
import java.util.Currency;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -27,7 +26,6 @@ import javax.annotation.Nullable;
|
|||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import de.schildbach.pte.dto.Fare;
|
||||
import de.schildbach.pte.dto.Line;
|
||||
import de.schildbach.pte.dto.Line.Attr;
|
||||
import de.schildbach.pte.dto.Point;
|
||||
|
@ -108,6 +106,11 @@ public final class BvgProvider extends AbstractHafasClientInterfaceProvider {
|
|||
return super.splitStationName(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String normalizeFareName(final String fareName) {
|
||||
return fareName.replaceAll("Tarifgebiet ", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line newLine(final String id, final String operator, final Product product, final @Nullable String name,
|
||||
final @Nullable String shortName, final @Nullable String number, final Style style) {
|
||||
|
@ -141,22 +144,6 @@ public final class BvgProvider extends AbstractHafasClientInterfaceProvider {
|
|||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Fare parseJsonTripFare(String fareSetName, final String fareSetDescription, final String name,
|
||||
final Currency currency, final float price) {
|
||||
if (!fareSetName.startsWith("Berlin Tarifgebiet ") || !fareSetName.endsWith(" Einzelfahrausweis"))
|
||||
return null;
|
||||
fareSetName = "Berlin " + fareSetName.substring(19, fareSetName.length() - 19);
|
||||
|
||||
if (name.equals("Regeltarif"))
|
||||
return new Fare(fareSetName, Fare.Type.ADULT, currency, price, name, null);
|
||||
if (name.equals("Ermäßigungstarif"))
|
||||
return new Fare(fareSetName, Fare.Type.CHILD, currency, price, name, null);
|
||||
if (name.equals("Fahrrad"))
|
||||
return new Fare(fareSetName, Fare.Type.BIKE, currency, price, name, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final Map<String, Style> STYLES = new HashMap<>();
|
||||
|
||||
static {
|
||||
|
|
|
@ -17,15 +17,10 @@
|
|||
|
||||
package de.schildbach.pte;
|
||||
|
||||
import java.util.Currency;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.schildbach.pte.dto.Fare;
|
||||
import de.schildbach.pte.dto.Fare.Type;
|
||||
import de.schildbach.pte.dto.Product;
|
||||
import de.schildbach.pte.dto.Style;
|
||||
|
||||
|
@ -79,20 +74,6 @@ public class ShProvider extends AbstractHafasClientInterfaceProvider {
|
|||
return super.splitStationName(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Fare parseJsonTripFare(final @Nullable String fareSetName, final @Nullable String fareSetDescription,
|
||||
String name, final Currency currency, final float price) {
|
||||
if (!"Normalpreis".equals(fareSetDescription) || !name.startsWith("Einzelfahrkarte "))
|
||||
return null;
|
||||
name = name.substring(16);
|
||||
if (name.startsWith("Übergang"))
|
||||
return null;
|
||||
if (name.startsWith("Kind "))
|
||||
return new Fare("SH-Tarif", Type.CHILD, currency, price, name.substring(5), null);
|
||||
else
|
||||
return new Fare("SH-Tarif", Type.ADULT, currency, price, name, null);
|
||||
}
|
||||
|
||||
protected static final Map<String, Style> STYLES = new HashMap<>();
|
||||
|
||||
static {
|
||||
|
|
|
@ -98,6 +98,11 @@ public class VbbProvider extends AbstractHafasClientInterfaceProvider {
|
|||
return super.splitStationName(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String normalizeFareName(final String fareName) {
|
||||
return fareName.replaceAll("Tarifgebiet ", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts() {
|
||||
return ALL_EXCEPT_HIGHSPEED_AND_ONDEMAND;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package de.schildbach.pte;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -26,6 +27,7 @@ import javax.annotation.Nullable;
|
|||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import de.schildbach.pte.dto.Fare;
|
||||
import de.schildbach.pte.dto.Line;
|
||||
import de.schildbach.pte.dto.Line.Attr;
|
||||
import de.schildbach.pte.dto.Product;
|
||||
|
@ -84,6 +86,20 @@ public class VbnProvider extends AbstractHafasClientInterfaceProvider {
|
|||
return super.splitAddress(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hideFare(Fare fare) {
|
||||
final String fareNameLc = fare.network.toLowerCase(Locale.US);
|
||||
if (fareNameLc.contains("2 adults"))
|
||||
return true;
|
||||
if (fareNameLc.contains("3 adults"))
|
||||
return true;
|
||||
if (fareNameLc.contains("4 adults"))
|
||||
return true;
|
||||
if (fareNameLc.contains("5 adults"))
|
||||
return true;
|
||||
return super.hideFare(fare);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue