Documentation
¶
Overview ¶
Package coster calculates journey fares from GTFS Fares v2 data.
It follows the adopted specification, including effective fare legs from fare_leg_join_rules.txt, rule_priority, timeframes, and chained transfers. By default it reads the spec strictly: extensions outside the adopted spec, such as transfer_only, filter_fare_product_id and the draft fare product duration fields, and readings beyond the spec text apply only when a Coster flag enables them. It is based on an earlier internal implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a copier extension that collects a Coster from the entities that a copy writes.
func (*Builder) AfterWrite ¶
AfterWrite collects an entity from a copy, keyed by the ID that the writer returned.
type Coster ¶
type Coster struct {
// UseTransferOnly honors the proposed transfer_only extension: a fare leg rule with
// transfer_only=1 prices a fare leg only when a transfer reaches the leg.
UseTransferOnly bool
// UseFilterFareProductID honors the proposed filter_fare_product_id extension: a transfer
// rule with a filter applies only to riders who hold the filter's fare product.
UseFilterFareProductID bool
// UseFareProductDurations honors the draft fare product duration fields: a product row
// with a duration is a pass, which never prices a trip.
UseFareProductDurations bool
// UseEmptyFieldsPerLegGroup scopes empty-field matching in fare_leg_rules.txt to each leg
// group: an empty network or area field excludes only the values that rules in its leg
// group list, not every value in the file. It has no effect with rule_priority.
UseEmptyFieldsPerLegGroup bool
// UseSameMediumTransfers applies a transfer rule only when the fare legs it joins use the
// same fare medium, as when a transfer credit lives on the card that paid for the earlier
// leg. The spec doesn't restrict the fare media of the legs a transfer joins.
UseSameMediumTransfers bool
// contains filtered or unexported fields
}
Coster calculates fares for journeys on one feed.
type FareLeg ¶
type FareLeg struct {
LegIndexes []int // journey legs joined into this fare leg
LegRule *gtfs.FareLegRule
Product *gtfs.FareProduct // the row of the leg rule's product that the rider buys
TransferRule *gtfs.FareTransferRule // rule for the transfer into this fare leg, if any
TransferProduct *gtfs.FareProduct // the transfer rule's product, if it names one
Amount decimal.Decimal
// FareMediaID is the fare medium used to pay. A fare leg whose product names no medium
// takes the previous fare leg's medium when a transfer joins them, and is empty when that
// medium is unknown.
FareMediaID string
// HeldProductIDs lists products the rider holds, such as passes, that may cover this
// fare leg. Amount is still the full fare.
HeldProductIDs []string
}
FareLeg is one effective fare leg of a fare and the amount it adds to the fare.
type Journey ¶
type Journey struct {
Legs []Leg
// RiderCategoryIDs lists the categories that apply to the rider, by rider_category_id.
// When empty, the feed's default rider categories apply.
RiderCategoryIDs []string
// FareProductIDs lists products the rider already holds, such as passes. Each fare leg
// lists the held products that may cover the leg, and the leg still costs its full fare.
FareProductIDs []string
// FareMediaIDs lists the fare media available to the rider.
// When empty, every fare medium in the feed is a candidate.
FareMediaIDs []string
}
Journey is a rider's transit legs, in travel order.
type Leg ¶
type Leg struct {
RouteID string
FromStopID string
ToStopID string
DepartureTime time.Time
ArrivalTime time.Time
}
Leg is one transit leg of a journey. Its route and stop IDs, and the journey's fare media IDs, use the same IDs as the Coster's source: each entity's own ID from New, or the writer's IDs from a Builder.