mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 09:00:36 +00:00
SH: Parse fares.
This commit is contained in:
parent
391fb06090
commit
e3337c202d
3 changed files with 44 additions and 10 deletions
|
@ -1272,24 +1272,20 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
for (int iFareSet = 0; iFareSet < fareSetList.length(); iFareSet++)
|
for (int iFareSet = 0; iFareSet < fareSetList.length(); iFareSet++)
|
||||||
{
|
{
|
||||||
final JSONObject fareSet = fareSetList.getJSONObject(iFareSet);
|
final JSONObject fareSet = fareSetList.getJSONObject(iFareSet);
|
||||||
final String network = fareSet.optString("name", null);
|
final String fareSetName = fareSet.optString("name", null);
|
||||||
if (network != null)
|
final String fareSetDescription = fareSet.optString("desc", null);
|
||||||
|
if (fareSetName != null || fareSetDescription != null)
|
||||||
{
|
{
|
||||||
final JSONArray fareList = fareSet.getJSONArray("fareL");
|
final JSONArray fareList = fareSet.getJSONArray("fareL");
|
||||||
for (int iFare = 0; iFare < fareList.length(); iFare++)
|
for (int iFare = 0; iFare < fareList.length(); iFare++)
|
||||||
{
|
{
|
||||||
final JSONObject jsonFare = fareList.getJSONObject(iFare);
|
final JSONObject jsonFare = fareList.getJSONObject(iFare);
|
||||||
final String name = jsonFare.getString("name");
|
final String name = jsonFare.getString("name");
|
||||||
if (name.endsWith("- Jahreskarte") || name.endsWith("- Monatskarte"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
final Currency currency = Currency.getInstance(jsonFare.getString("cur"));
|
final Currency currency = Currency.getInstance(jsonFare.getString("cur"));
|
||||||
final float price = jsonFare.getInt("prc") / 100f;
|
final float price = jsonFare.getInt("prc") / 100f;
|
||||||
|
final Fare fare = parseJsonTripFare(fareSetName, fareSetDescription, name, currency, price);
|
||||||
if (name.startsWith("Vollpreis - "))
|
if (fare != null)
|
||||||
fares.add(new Fare(network, Fare.Type.ADULT, currency, price, name.substring(12), null));
|
fares.add(fare);
|
||||||
else if (name.startsWith("Kind - "))
|
|
||||||
fares.add(new Fare(network, Fare.Type.CHILD, currency, price, name.substring(7), null));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1308,6 +1304,18 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
private String wrapJsonApiRequest(final String meth, final String req, final boolean formatted)
|
private String wrapJsonApiRequest(final String meth, final String req, final boolean formatted)
|
||||||
{
|
{
|
||||||
return "{" //
|
return "{" //
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package de.schildbach.pte;
|
package de.schildbach.pte;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Currency;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -29,6 +30,8 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
|
||||||
|
import de.schildbach.pte.dto.Fare;
|
||||||
|
import de.schildbach.pte.dto.Fare.Type;
|
||||||
import de.schildbach.pte.dto.Location;
|
import de.schildbach.pte.dto.Location;
|
||||||
import de.schildbach.pte.dto.LocationType;
|
import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyLocationsResult;
|
import de.schildbach.pte.dto.NearbyLocationsResult;
|
||||||
|
@ -131,6 +134,21 @@ public class ShProvider extends AbstractHafasProvider
|
||||||
later ? jsonContext.laterContext : jsonContext.earlierContext);
|
later ? jsonContext.laterContext : jsonContext.earlierContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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<String, Style>();
|
protected static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||||
|
|
||||||
static
|
static
|
||||||
|
|
|
@ -115,4 +115,12 @@ public class ShProviderLiveTest extends AbstractProviderLiveTest
|
||||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||||
print(laterResult);
|
print(laterResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tripKiel() throws Exception
|
||||||
|
{
|
||||||
|
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "3490015"), null, new Location(LocationType.STATION, "706923"),
|
||||||
|
new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue