mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 22:38:49 +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);
|
legs.add(leg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final List<Fare> fares;
|
||||||
final JSONObject trfRes = outCon.optJSONObject("trfRes");
|
final JSONObject trfRes = outCon.optJSONObject("trfRes");
|
||||||
final List<Fare> fares = new LinkedList<>();
|
final JSONArray ovwTrfRefList = outCon.optJSONArray("ovwTrfRefL");
|
||||||
if (trfRes != null) {
|
if (trfRes != null && ovwTrfRefList != null) {
|
||||||
|
fares = new LinkedList<>();
|
||||||
final JSONArray fareSetList = trfRes.getJSONArray("fareSetL");
|
final JSONArray fareSetList = trfRes.getJSONArray("fareSetL");
|
||||||
for (int iFareSet = 0; iFareSet < fareSetList.length(); iFareSet++) {
|
for (int i = 0; i < ovwTrfRefList.length(); i++) {
|
||||||
final JSONObject fareSet = fareSetList.getJSONObject(iFareSet);
|
final JSONObject ovwTrfRef = ovwTrfRefList.getJSONObject(i);
|
||||||
final String fareSetName = fareSet.optString("name", null);
|
final String type = ovwTrfRef.getString("type");
|
||||||
final String fareSetDescription = fareSet.optString("desc", null);
|
final int fareSetX = ovwTrfRef.getInt("fareSetX");
|
||||||
if (fareSetName != null || fareSetDescription != null) {
|
final int fareX = ovwTrfRef.getInt("fareX");
|
||||||
final JSONArray fareList = fareSet.getJSONArray("fareL");
|
final JSONObject jsonFareSet = fareSetList.getJSONObject(fareSetX);
|
||||||
for (int iFare = 0; iFare < fareList.length(); iFare++) {
|
final JSONObject jsonFare = jsonFareSet.getJSONArray("fareL").getJSONObject(fareX);
|
||||||
final JSONObject jsonFare = fareList.getJSONObject(iFare);
|
final String fareName = jsonFare.getString("name");
|
||||||
final String name = jsonFare.getString("name");
|
final Fare fare;
|
||||||
final JSONArray ticketList = jsonFare.optJSONArray("ticketL");
|
if (type.equals("T")) { // ticket
|
||||||
if (ticketList != null) {
|
final int ticketX = ovwTrfRef.getInt("ticketX");
|
||||||
for (int iTicket = 0; iTicket < ticketList.length(); iTicket++) {
|
final JSONObject jsonTicket = jsonFare.getJSONArray("ticketL").getJSONObject(ticketX);
|
||||||
final JSONObject jsonTicket = ticketList.getJSONObject(iTicket);
|
|
||||||
final String ticketName = jsonTicket.getString("name");
|
final String ticketName = jsonTicket.getString("name");
|
||||||
final Currency currency = Currency.getInstance(jsonTicket.getString("cur"));
|
final Currency currency = Currency.getInstance(jsonTicket.getString("cur"));
|
||||||
final float price = jsonTicket.getInt("prc") / 100f;
|
final float price = jsonTicket.getInt("prc") / 100f;
|
||||||
final Fare fare = parseJsonTripFare(name, fareSetDescription, ticketName,
|
fare = new Fare(normalizeFareName(fareName) + '\n' + ticketName,
|
||||||
currency, price);
|
normalizeFareType(ticketName), currency, price, null, null);
|
||||||
if (fare != 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);
|
fares.add(fare);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final Currency currency = Currency.getInstance(jsonFare.getString("cur"));
|
fares = null;
|
||||||
final float price = jsonFare.getInt("prc") / 100f;
|
|
||||||
final Fare fare = parseJsonTripFare(fareSetName, fareSetDescription, name, currency,
|
|
||||||
price);
|
|
||||||
if (fare != null)
|
|
||||||
fares.add(fare);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Trip trip = new Trip(null, tripFrom, tripTo, legs, fares, null, 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,
|
protected Fare.Type normalizeFareType(final String fareName) {
|
||||||
final String name, final Currency currency, final float price) {
|
final String fareNameLc = fareName.toLowerCase(Locale.US);
|
||||||
if (name.endsWith("- Jahreskarte") || name.endsWith("- Monatskarte"))
|
if (fareNameLc.contains("erwachsene") || fareNameLc.contains("adult"))
|
||||||
return null;
|
return Fare.Type.ADULT;
|
||||||
if (name.startsWith("Vollpreis - "))
|
if (fareNameLc.contains("kind") || fareNameLc.contains("child") || fareNameLc.contains("kids"))
|
||||||
return new Fare(fareSetName, Fare.Type.ADULT, currency, price, name.substring(12), null);
|
return Fare.Type.CHILD;
|
||||||
if (name.startsWith("Kind - "))
|
if (fareNameLc.contains("ermäßigung"))
|
||||||
return new Fare(fareSetName, Fare.Type.CHILD, currency, price, name.substring(7), null);
|
return Fare.Type.CHILD;
|
||||||
return null;
|
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) {
|
private String wrapJsonApiRequest(final String meth, final String req, final boolean formatted) {
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package de.schildbach.pte;
|
package de.schildbach.pte;
|
||||||
|
|
||||||
import java.util.Currency;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -27,7 +26,6 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import de.schildbach.pte.dto.Fare;
|
|
||||||
import de.schildbach.pte.dto.Line;
|
import de.schildbach.pte.dto.Line;
|
||||||
import de.schildbach.pte.dto.Line.Attr;
|
import de.schildbach.pte.dto.Line.Attr;
|
||||||
import de.schildbach.pte.dto.Point;
|
import de.schildbach.pte.dto.Point;
|
||||||
|
@ -108,6 +106,11 @@ public final class BvgProvider extends AbstractHafasClientInterfaceProvider {
|
||||||
return super.splitStationName(address);
|
return super.splitStationName(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String normalizeFareName(final String fareName) {
|
||||||
|
return fareName.replaceAll("Tarifgebiet ", "");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Line newLine(final String id, final String operator, final Product product, final @Nullable String name,
|
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) {
|
final @Nullable String shortName, final @Nullable String number, final Style style) {
|
||||||
|
@ -141,22 +144,6 @@ public final class BvgProvider extends AbstractHafasClientInterfaceProvider {
|
||||||
return line;
|
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<>();
|
private static final Map<String, Style> STYLES = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
@ -17,15 +17,10 @@
|
||||||
|
|
||||||
package de.schildbach.pte;
|
package de.schildbach.pte;
|
||||||
|
|
||||||
import java.util.Currency;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
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.Product;
|
||||||
import de.schildbach.pte.dto.Style;
|
import de.schildbach.pte.dto.Style;
|
||||||
|
|
||||||
|
@ -79,20 +74,6 @@ public class ShProvider extends AbstractHafasClientInterfaceProvider {
|
||||||
return super.splitStationName(address);
|
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<>();
|
protected static final Map<String, Style> STYLES = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
@ -98,6 +98,11 @@ public class VbbProvider extends AbstractHafasClientInterfaceProvider {
|
||||||
return super.splitStationName(address);
|
return super.splitStationName(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String normalizeFareName(final String fareName) {
|
||||||
|
return fareName.replaceAll("Tarifgebiet ", "");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Product> defaultProducts() {
|
public Set<Product> defaultProducts() {
|
||||||
return ALL_EXCEPT_HIGHSPEED_AND_ONDEMAND;
|
return ALL_EXCEPT_HIGHSPEED_AND_ONDEMAND;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package de.schildbach.pte;
|
package de.schildbach.pte;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -26,6 +27,7 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import de.schildbach.pte.dto.Fare;
|
||||||
import de.schildbach.pte.dto.Line;
|
import de.schildbach.pte.dto.Line;
|
||||||
import de.schildbach.pte.dto.Line.Attr;
|
import de.schildbach.pte.dto.Line.Attr;
|
||||||
import de.schildbach.pte.dto.Product;
|
import de.schildbach.pte.dto.Product;
|
||||||
|
@ -84,6 +86,20 @@ public class VbnProvider extends AbstractHafasClientInterfaceProvider {
|
||||||
return super.splitAddress(address);
|
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
|
@Override
|
||||||
public Set<Product> defaultProducts() {
|
public Set<Product> defaultProducts() {
|
||||||
return Product.ALL;
|
return Product.ALL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue