calcularTarifa. Rules are checked in strict order — the first rule that matches wins, and no further rules are evaluated.
Priority rule engine
Special route (ruta especial única)
If either the origin or destination matches a zone defined in
rutas_especiales.json, the fixed fare for that route is applied immediately. This is a total override — the sector tables are never consulted.The response will include:sector_aplicado: "ruta especial única"fuente: "rutas_especiales.json → <route id>"
Terminal de Transporte table
If neither endpoint triggers a special route, the API checks whether the origin or destination is the Terminal de Transporte (or Carrera 42). The following keywords are recognized (case-insensitive, accent-insensitive):
terminalterminal de transportecarrera 42cra 42cra. 42
barrios_terminal.json — a separate table that assigns different sector values for Terminal trips. If the neighborhood is found there, its sector fare applies.If the neighborhood is not explicitly listed in barrios_terminal.json, the API falls through to Priority 3 and logs a warning.The fuente field will read: "barrios_terminal.json → <sector>".General sector table
For all other trips, both the origin and destination neighborhoods are looked up in
barrios.json. The highest sector between the two is used to determine the fare.Sector order from lowest to highest:
primer_sector → segundo_sector → tarifa_especial → tercer_sector → cuarto_sectorThe fuente field will read: "barrios.json → <sector>".Neighborhood matching
Matching is exact — there is no fuzzy matching, substring matching, or approximate search. Before comparison, both the input and the stored neighborhood name are normalized using the same function:"San Fernando"→"san fernando""Córdoba"→"cordoba"" Centro "→"centro"
"Cogollo Alto" does not match "Cogollo".
Concrete example
Request:- Neither “San Fernando” nor “Centro” is in any special route zone — Priority 1 skipped.
- Neither is a Terminal keyword — Priority 2 skipped.
- Both are looked up in
barrios.json. Both belong toprimer_sector. Highest sector:primer_sector. - Time is daytime → fare is $7,000.
The fuente field
Every response includes a fuente field that identifies exactly which data file and sector produced the fare. This is useful for debugging and audit purposes.
| Value | Meaning |
|---|---|
rutas_especiales.json → ruta_1 | Matched special route 1 |
barrios_terminal.json → tercer_sector | Terminal table, third sector |
barrios.json → segundo_sector | General table, second sector |
If a neighborhood cannot be found in any table, the API returns an error. There are no default or fallback fares.