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

feat(fares-v2): add support for editing feeds with fares v2 data #1025

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
101 changes: 101 additions & 0 deletions gtfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1017,3 +1017,104 @@
required: false
- name: added_service
required: false

# Fares v2

- id: fareproduct
name: fare_products.txt
helpContent: Used to describe the range of fares available for purchase by riders or taken into account when computing the total fare for journeys with multiple legs, such as transfer costs.
fields:
- name: fare_product_id
required: true
inputType: GTFS_ID
- name: fare_product_name
required: false
inputType: TEXT
- name: fare_media_id
required: false
inputType: TEXT # FARE-TODO: Needs to reference an actual fare media id. need custom type
- name: amount
inputType: NUMBER
required: true
- name: currency
required: true
inputType: TEXT # FARE-TODO: Dropdownx
- id: faremedia
name: fare_media.txt
helpContent: To describe the different fare media that can be employed to use fare products. Fare media are physical or virtual holders used for the representation and/or validation of a fare product.
fields:
- name: fare_media_id
required: true
inputType: GTFS_ID
- name: fare_media_name
inputType: TEXT
- name: fare_media_type
required: true
inputType: DROPDOWN
# FARE-TODO: Some help content?
options:
- value: '0'
- value: '1'
- value: '2'
- value: '3'
- value: '4'
- id: faretransferrule
name: fare_transfer_rules.txt
helpContent: Fare rules for transfers between legs of travel defined in fare_leg_rules.txt.
fields:
- name: from_leg_group_id
required: false
inputType: TEXT # FARE-TODO: Needs to reference fare_leg_rules
- name: to_leg_group_id
required: false
inputType: TEXT # FARE-TODO: Needs to reference fare_leg_rules
- name: transfer_count
inputType: NUMBER # FARE-TODO: NON-ZERO INT
- name: duration_limit
inputType: POSITIVE_INT
- name: duration_limit_type
inputType: DROPDOWN
# FARE-TODO: Some help content?
options:
- value: '0'
- value: '1'
- value: '2'
- value: '3'
- name: fare_transfer_type
inputType: DROPDOWN
# FARE-TODO: Some help content?
options:
- value: '0'
- value: '1'
- value: '2'
- name: fare_product_id
required: false
inputType: TEXT # FARE-TODO: Needs to reference fare_products
- id: farelegrule
name: fare_leg_rules.txt
# FARE-TODO: Some help content?
fields:
- name: leg_group_id
required: false
inputType: TEXT # FARE-TODO: should this be text or id?
- name: network_id
required: false
inputType: TEXT # FARE-TODO: Needs to reference networks.network_id or routes.network_id
- name: from_area_id
required: false
inputType: TEXT # FARE-TODO: Needs to reference areas.area_id
- name: to_area_id
required: false
inputType: TEXT # FARE-TODO: Needs to reference areas.area_id
- name: from_timeframe_group_id
required: false
inputType: TEXT # FARE-TODO: Needs to reference timeframes.timeframe_group_id
- name: to_timeframe_group_id
required: false
inputType: TEXT # FARE-TODO: Needs to reference timeframes.timeframe_group_id
- name: fare_product_id
required: true
inputType: TEXT # FARE-TODO: Needs to reference fare_products.fare_product_id
- name: rule_priority
required: false
inputType: POSITIVE_INT
22 changes: 21 additions & 1 deletion lib/editor/actions/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,29 @@ export function fetchBaseGtfs ({
id
fare_id
}
fare_product (limit: -1) {
id
fare_product_id
fare_media_id
}
fare_media (limit: -1) {
id
fare_media_id
}
fare_transfer_rule (limit: -1) {
id
from_leg_group_id
to_leg_group_id
fare_product_id
}
fare_leg_rule (limit: -1) {
fare_product_id
leg_group_id
id
}
routes (limit: -1) {
id
route_id
route_id
route_short_name
route_long_name
# Ensure that we know route type when setting active entity (for edit
Expand Down
29 changes: 27 additions & 2 deletions lib/editor/util/gtfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export const COMPONENT_LIST = [
// FIXME: table name for calendar, fare, and schedule exception
{ id: 'calendar', tableName: 'calendar' },
{ id: 'scheduleexception', tableName: 'schedule_exceptions' },
{ id: 'agency', tableName: 'agency' }
{ id: 'agency', tableName: 'agency' },
{ id: 'fareproduct', tableName: 'fare_product' },
{ id: 'faremedia', tableName: 'fare_media' },
{ id: 'faretransferrule', tableName: 'fare_transfer_rule' },
{ id: 'farelegrule', tableName: 'fare_leg_rule' }
]

export function getTableById (tableData: any, id?: string, emptyArrayOnNull: boolean = true): any {
Expand Down Expand Up @@ -240,7 +244,19 @@ export function getEntityName (entity: any): string {
nameKey = 'description'
} else if (typeof entity.fare_id !== 'undefined') {
nameKey = 'fare_id'
} else if (typeof entity.exemplar !== 'undefined') {
} else if (typeof entity.fare_product_id !== 'undefined' && typeof entity.fare_media_id !== 'undefined') {
nameKey = 'fare_product_id'
} else if (typeof entity.fare_media_id !== 'undefined') {
nameKey = 'fare_media_id'
} else if (typeof entity.from_leg_group_id !== 'undefined' && typeof entity.to_leg_group_id !== 'undefined' && entity.fare_product_id !== 'undefined') {
nameKey = 'fare_transfer_rule_id' // FARE-TODO: fare_media_name? Some combo?
} else if (typeof entity.fare_product_id !== 'undefined' && typeof entity.leg_group_id !== 'undefined') {
nameKey = 'fare_leg_rule_id' // FARE-TODO: fare_media_name? Some combo?
}

// FARE-TODO: what to do with fare_transfer_rules.txt?
// FARE-TODO: what to do with fare_leg_rules.txt?
if (typeof entity.exemplar !== 'undefined') {
nameKey = 'name'
}

Expand Down Expand Up @@ -274,6 +290,15 @@ export function getEntityName (entity: any): string {
return `${serviceCalendar.service_id} ${serviceCalendar.description
? `(${serviceCalendar.description})`
: ''}`
case 'fare_product_id':
// FARE-TODO: type!
return `${entity.fare_product_id} (${entity.fare_media_id})`
case 'fare_transfer_rule_id':
// FARE-TODO: type!
return `${entity.from_leg_group_id} ➡️ ${entity.to_leg_group_id} (${entity.fare_product_id})`
case 'fare_leg_rule_id':
// FARE-TODO: type!
return `${entity.fare_product_id} (${entity.leg_group_id})`
default:
const otherEntityType: any = entity
return otherEntityType[nameKey] || NO_NAME
Expand Down
9 changes: 8 additions & 1 deletion lib/editor/util/objects.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// @flow
import {ENTITY} from '../constants'
import {camelCaseKeys, snakeCaseKeys} from '../../common/util/map-keys'

import type {Entity} from '../../types'

export function componentToText (component: string): string {
switch (component) {
case 'scheduleexception':
return 'exception'
case 'fareproduct':
return 'product'
case 'faremedia':
return 'media'
case 'faretransferrule':
return 'transfer rule'
case 'farelegrule':
return 'leg rule'
default:
return component
}
Expand Down
32 changes: 32 additions & 0 deletions lib/editor/util/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@ export const GTFS_ICONS = [
addable: true,
title: messages('fare.title'),
label: messages('fare.label')
},
{
id: 'fareproduct',
tableName: 'fareproduct',
icon: 'shopping-cart',
addable: true,
title: 'FARE PRODUCT TEST TITLE',
label: 'V2: Products'
},
{
id: 'faremedia',
tableName: 'faremedia',
icon: 'id-card',
addable: true,
title: 'FARE MEDIA TEST TITLE',
label: 'V2: Media'
},
{
id: 'faretransferrule',
tableName: 'faretransferrule',
icon: 'link',
addable: true,
title: 'FARE TRANSFER RULE TEST TITLE',
label: 'V2: Transfer Rules'
},
{
id: 'farelegrule',
tableName: 'farelegrule',
icon: 'book',
addable: true,
title: 'FARE LEG RULE TEST TITLE',
label: 'V2: Leg Rules'
}
]

Expand Down
50 changes: 46 additions & 4 deletions lib/gtfs/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export function getEntityIdField (type: string): string {
return 'agency_id'
case 'fare':
return 'fare_id'
case 'fareproduct':
return 'fare_product_id'
case 'faremedia':
return 'fare_media_id'
case 'faretransferrule':
return 'id'
case 'farelegrule':
return 'id'
case 'calendar':
return 'service_id'
case 'stop':
Expand Down Expand Up @@ -103,6 +111,24 @@ export function getGraphQLFieldsForEntity (type: string, editor: boolean = false
contains_id
}
`
case 'fareproduct':
return `
${fields}
`
case 'faremedia':
return `
${fields}
`
case 'faretransferrule':
return `
id
${fields}
`
case 'farelegrule':
return `
id
${fields}
`
case 'pattern':
return `
shape_id
Expand Down Expand Up @@ -142,6 +168,14 @@ export function getEntityGraphQLRoot (type: string): string {
return 'calendar'
case 'fare':
return 'fares'
case 'fareproduct':
return 'fare_product'
case 'faremedia':
return 'fare_media'
case 'faretransferrule':
return 'fare_transfer_rule'
case 'farelegrule':
return 'fare_leg_rule'
case 'feedinfo':
return 'feed_info'
case 'stop':
Expand Down Expand Up @@ -173,10 +207,18 @@ export function getEntityTableString (type: string): string {
return 'agency'
case 'calendar':
return 'calendar'
case 'fare':
return 'fare_attributes'
case 'fare_rules':
return 'fare_rules'
case 'fare': // Fares v1
return 'fare_attributes' // Fares v1
case 'fareproduct':
return 'fareproduct'
case 'faremedia':
return 'faremedia'
case 'fare_rules': // Fares v1
return 'fare_rules' // Fares v1
case 'faretransferrule':
return 'faretransferrule'
case 'farelegrule':
return 'farelegrule'
case 'feedinfo':
return 'feedinfo'
case 'stop':
Expand Down
4 changes: 4 additions & 0 deletions lib/types/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export type EditorTables = {
id: number,
service_id: string
}>,
fare_leg_rule: Array<{}>, // FARE-TODO: Do this
fare_media: Array<{}>, // FARE-TODO: Do this
fare_product: Array<{}>, // FARE-TODO: Do this
fare_transfer_rule: Array<{}>, // FARE-TODO: Do this
fares: Array<{
fare_id: string,
id: number,
Expand Down
Loading