@opentripplanner/core-utils 7.0.0-alpha.2 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/itinerary.js +93 -63
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +2 -17
- package/esm/map.js.map +1 -1
- package/esm/query.js +2 -4
- package/esm/query.js.map +1 -1
- package/esm/time.js +4 -7
- package/esm/time.js.map +1 -1
- package/lib/itinerary.d.ts +7 -0
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +86 -63
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +0 -1
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +2 -19
- package/lib/map.js.map +1 -1
- package/lib/query.js +1 -4
- package/lib/query.js.map +1 -1
- package/lib/time.d.ts +1 -2
- package/lib/time.d.ts.map +1 -1
- package/lib/time.js +5 -9
- package/lib/time.js.map +1 -1
- package/package.json +5 -4
- package/src/__tests__/itinerary.js +42 -32
- package/src/itinerary.ts +90 -56
- package/src/map.ts +2 -20
- package/src/query.js +3 -7
- package/src/time.ts +4 -10
- package/tsconfig.json +1 -6
- package/tsconfig.tsbuildinfo +1 -5014
package/esm/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/time.ts"],"names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","
|
|
1
|
+
{"version":3,"sources":["../src/time.ts"],"names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"mappings":"AACA,SAASA,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O,SAASC,0BAAT,CACLjB,OADK,EAELQ,UAFK,EAGG;AACR,MAAMU,IAAI,GAAGxB,GAAG,CAACD,UAAU,CAAC,IAAI0B,IAAJ,EAAD,CAAX,EAAyB;AAAEnB,IAAAA,OAAO,EAAPA;AAAF,GAAzB,CAAhB;AACA,SAAOL,MAAM,CAACuB,IAAD,EAAOV,UAAP,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASY,eAAT,GAAqE;AAAA;;AAAA,MAA5CC,gBAA4C,uEAAzB,eAAyB;AAC1E,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAA7B,EAAqC,OAAOF,OAAO,CAACC,GAAR,CAAYE,EAAnB;AACrC,SAAO,UAAAC,IAAI,UAAJ,sCAAMC,cAAN,GAAuBC,eAAvB,GAAyCC,QAAzC,KAAqDR,gBAA5D;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASS,cAAT,GAA8D;AAAA,MAAtCC,QAAsC,uEAA3BX,eAAe,EAAY;AACnE,SAAOzB,MAAM,CAACC,cAAc,CAACuB,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CAAf,EAAuCjC,mBAAvC,CAAb;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASmC,cAAT,GAA8D;AAAA,MAAtCF,QAAsC,uEAA3BX,eAAe,EAAY;AACnE,SAAOzB,MAAM,CAACC,cAAc,CAACuB,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CAAf,EAAuClC,mBAAvC,CAAb;AACD","sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport { startOfDay, add, format } from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// Date/time formats (per date-fns) when sending/receiving date from OTP\n// regardless of whatever the user has configured as the display format.\nexport const OTP_API_DATE_FORMAT = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(\n seconds: number\n): {\n hours: number;\n minutes: number;\n seconds: number;\n} {\n return {\n hours: Math.floor(seconds / 3600),\n minutes: Math.floor(seconds / 60) % 60,\n seconds: seconds % 60\n };\n}\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config: Config): string {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config: Config): string {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\nexport function getLongDateFormat(config: Config): string {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(\n seconds: number,\n timeFormat: string\n): string {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\"): string {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);\n}\n"],"file":"time.js"}
|
package/lib/itinerary.d.ts
CHANGED
|
@@ -117,4 +117,11 @@ export declare function getTransitFare(fareComponent: Money): {
|
|
|
117
117
|
currencyCode: string;
|
|
118
118
|
transitFare: number;
|
|
119
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* @param {itinerary} itinerary OTP trip itinierary
|
|
122
|
+
* @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
|
|
123
|
+
* @param {units} units units to be used in return value
|
|
124
|
+
* @return Amount of carbon in chosen unit
|
|
125
|
+
*/
|
|
126
|
+
export declare function calculateEmissions(itinerary: Itinerary, carbonIntensity?: Record<string, number>, units?: string): number;
|
|
120
127
|
//# sourceMappingURL=itinerary.d.ts.map
|
package/lib/itinerary.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,WAAW,EACX,GAAG,EACH,KAAK,EACL,IAAI,EACJ,OAAO,EACR,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,WAAW,EACX,GAAG,EACH,KAAK,EACL,IAAI,EACJ,OAAO,EACR,MAAM,wBAAwB,CAAC;AAIhC,eAAO,MAAM,YAAY,UAOxB,CAAC;AAEF;;;GAGG;AAEH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAOxD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB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ACH,wBAAgB,cAAc,CAC5B,aAAa,EAAE,KAAK,GACnB;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAUA;AA2BD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,eAAe,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAC5C,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,CA2BR"}
|
package/lib/itinerary.js
CHANGED
|
@@ -39,37 +39,13 @@ exports.getTNCLocation = getTNCLocation;
|
|
|
39
39
|
exports.calculatePhysicalActivity = calculatePhysicalActivity;
|
|
40
40
|
exports.calculateTncFares = calculateTncFares;
|
|
41
41
|
exports.getTransitFare = getTransitFare;
|
|
42
|
+
exports.calculateEmissions = calculateEmissions;
|
|
42
43
|
exports.transitModes = void 0;
|
|
43
44
|
|
|
44
45
|
var _polyline = _interopRequireDefault(require("@mapbox/polyline"));
|
|
45
46
|
|
|
46
47
|
var _along = _interopRequireDefault(require("@turf/along"));
|
|
47
48
|
|
|
48
|
-
/*
|
|
49
|
-
import {
|
|
50
|
-
// calculateFares,
|
|
51
|
-
// getLegModeLabel,
|
|
52
|
-
// getModeForPlace,
|
|
53
|
-
// getPlaceName,
|
|
54
|
-
// getStepDirection,
|
|
55
|
-
// getStepInstructions,
|
|
56
|
-
// getStepStreetName,
|
|
57
|
-
// getTimeZoneOffset,
|
|
58
|
-
// getTransitFare
|
|
59
|
-
} from "./deprecated";
|
|
60
|
-
|
|
61
|
-
export {
|
|
62
|
-
// calculateFares,
|
|
63
|
-
// getLegModeLabel,
|
|
64
|
-
// getModeForPlace,
|
|
65
|
-
// getPlaceName,
|
|
66
|
-
// getStepDirection,
|
|
67
|
-
// getStepInstructions,
|
|
68
|
-
// getStepStreetName,
|
|
69
|
-
// getTimeZoneOffset,
|
|
70
|
-
// getTransitFare
|
|
71
|
-
};
|
|
72
|
-
*/
|
|
73
49
|
// All OTP transit modes
|
|
74
50
|
const transitModes = ["TRAM", "BUS", "SUBWAY", "FERRY", "RAIL", "GONDOLA"];
|
|
75
51
|
/**
|
|
@@ -474,31 +450,28 @@ function calculatePhysicalActivity(itinerary) {
|
|
|
474
450
|
|
|
475
451
|
|
|
476
452
|
function calculateTncFares(itinerary) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
hailedCar,
|
|
482
|
-
mode,
|
|
453
|
+
return itinerary.legs.filter(leg => leg.mode === "CAR" && leg.hailedCar && leg.tncData).reduce(({
|
|
454
|
+
maxTNCFare,
|
|
455
|
+
minTNCFare
|
|
456
|
+
}, {
|
|
483
457
|
tncData
|
|
484
458
|
}) => {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
459
|
+
const {
|
|
460
|
+
currency,
|
|
461
|
+
maxCost,
|
|
462
|
+
minCost
|
|
463
|
+
} = tncData;
|
|
464
|
+
return {
|
|
465
|
+
// Assumes a single currency for entire itinerary.
|
|
466
|
+
currencyCode: currency,
|
|
467
|
+
maxTNCFare: maxTNCFare + maxCost,
|
|
468
|
+
minTNCFare: minTNCFare + minCost
|
|
469
|
+
};
|
|
470
|
+
}, {
|
|
471
|
+
currencyCode: null,
|
|
472
|
+
maxTNCFare: 0,
|
|
473
|
+
minTNCFare: 0
|
|
496
474
|
});
|
|
497
|
-
return {
|
|
498
|
-
currencyCode,
|
|
499
|
-
maxTNCFare,
|
|
500
|
-
minTNCFare
|
|
501
|
-
};
|
|
502
475
|
}
|
|
503
476
|
/**
|
|
504
477
|
* For a given fare component (either total fare or component parts), returns
|
|
@@ -507,22 +480,72 @@ function calculateTncFares(itinerary) {
|
|
|
507
480
|
|
|
508
481
|
|
|
509
482
|
function getTransitFare(fareComponent) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration
|
|
517
|
-
({
|
|
518
|
-
currencyCode
|
|
519
|
-
} = fareComponent.currency);
|
|
520
|
-
transitFare = fareComponent.cents;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
return {
|
|
524
|
-
currencyCode,
|
|
525
|
-
transitFare
|
|
483
|
+
return fareComponent ? {
|
|
484
|
+
currencyCode: fareComponent.currency.currencyCode,
|
|
485
|
+
transitFare: fareComponent.cents
|
|
486
|
+
} : {
|
|
487
|
+
currencyCode: "USD",
|
|
488
|
+
transitFare: 0
|
|
526
489
|
};
|
|
527
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Sources:
|
|
493
|
+
* - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf
|
|
494
|
+
* - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey
|
|
495
|
+
* - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx
|
|
496
|
+
* Other values extrapolated.
|
|
497
|
+
*/
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
const CARBON_INTENSITY_DEFAULTS = {
|
|
501
|
+
walk: 0.026,
|
|
502
|
+
bicycle: 0.017,
|
|
503
|
+
car: 0.162,
|
|
504
|
+
tram: 0.066,
|
|
505
|
+
subway: 0.066,
|
|
506
|
+
rail: 0.066,
|
|
507
|
+
bus: 0.09,
|
|
508
|
+
ferry: 0.082,
|
|
509
|
+
cable_car: 0.021,
|
|
510
|
+
gondola: 0.021,
|
|
511
|
+
funicular: 0.066,
|
|
512
|
+
transit: 0.066,
|
|
513
|
+
leg_switch: 0,
|
|
514
|
+
airplane: 0.382,
|
|
515
|
+
micromobility: 0.095
|
|
516
|
+
};
|
|
517
|
+
/**
|
|
518
|
+
* @param {itinerary} itinerary OTP trip itinierary
|
|
519
|
+
* @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
|
|
520
|
+
* @param {units} units units to be used in return value
|
|
521
|
+
* @return Amount of carbon in chosen unit
|
|
522
|
+
*/
|
|
523
|
+
|
|
524
|
+
function calculateEmissions(itinerary, carbonIntensity = {}, units) {
|
|
525
|
+
var _itinerary$legs;
|
|
526
|
+
|
|
527
|
+
// Apply defaults for any values that we don't have.
|
|
528
|
+
const carbonIntensityWithDefaults = { ...CARBON_INTENSITY_DEFAULTS,
|
|
529
|
+
...carbonIntensity
|
|
530
|
+
}; // Distance is in meters, totalCarbon is in grams
|
|
531
|
+
|
|
532
|
+
const totalCarbon = (itinerary === null || itinerary === void 0 ? void 0 : (_itinerary$legs = itinerary.legs) === null || _itinerary$legs === void 0 ? void 0 : _itinerary$legs.reduce((total, leg) => {
|
|
533
|
+
return (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] || 0) + total;
|
|
534
|
+
}, 0)) || 0;
|
|
535
|
+
|
|
536
|
+
switch (units) {
|
|
537
|
+
case "ounce":
|
|
538
|
+
return totalCarbon / 28.35;
|
|
539
|
+
|
|
540
|
+
case "kilogram":
|
|
541
|
+
return totalCarbon / 1000;
|
|
542
|
+
|
|
543
|
+
case "pound":
|
|
544
|
+
return totalCarbon / 454;
|
|
545
|
+
|
|
546
|
+
case "gram":
|
|
547
|
+
default:
|
|
548
|
+
return totalCarbon;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
528
551
|
//# sourceMappingURL=itinerary.js.map
|
package/lib/itinerary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/itinerary.ts"],"names":["transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","isContinuousDropoff","alightRule","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","polyline","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","minTNCFare","maxTNCFare","currencyCode","hailedCar","currency","maxCost","minCost","getTransitFare","fareComponent","transitFare","cents"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAaA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACO,MAAMA,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EAG1B,QAH0B,EAI1B,OAJ0B,EAK1B,MAL0B,EAM1B,SAN0B,CAArB;AASP;AACA;AACA;AACA;;;;AAEO,SAASC,eAAT,CAAyBC,MAAzB,EAAmD;AACxD,MAAI,CAACA,MAAD,IAAW,CAACA,MAAM,CAACC,KAAnB,IAA4B,CAACD,MAAM,CAACC,KAAP,CAAaH,YAA9C,EACE,OAAOA,YAAP;AAEF,SAAOE,MAAM,CAACC,KAAP,CAAaH,YAAb,CAA0BI,GAA1B,CAA8BC,EAAE,IACrC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B,GAAwB,GADxD;AAEA,SAAO;AACLA,IAAAA,YADK;AAELE,IAAAA,cAFK;AAGLH,IAAAA;AAHK,GAAP;AAKD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASI,iBAAT,CAA2BhF,SAA3B,EAA0D;AAC/D,MAAIiF,UAAU,GAAG,CAAjB;AACA,MAAIC,UAAU,GAAG,CAAjB;AACA,MAAIC,YAAJ;AACAnF,EAAAA,SAAS,CAACE,IAAV,CAAeC,OAAf,CAAuB,CAAC;AAAEiF,IAAAA,SAAF;AAAatI,IAAAA,IAAb;AAAmB8C,IAAAA;AAAnB,GAAD,KAAkC;AACvD,QAAI9C,IAAI,KAAK,KAAT,IAAkBsI,SAAlB,IAA+BxF,OAAnC,EAA4C;AAC1C,YAAM;AAAEyF,QAAAA,QAAF;AAAYC,QAAAA,OAAZ;AAAqBC,QAAAA;AAArB,UAAiC3F,OAAvC;AACAqF,MAAAA,UAAU,IAAIM,OAAd;AACAL,MAAAA,UAAU,IAAII,OAAd,CAH0C,CAI1C;;AACAH,MAAAA,YAAY,GAAGE,QAAf;AACD;AACF,GARD;AAUA,SAAO;AACLF,IAAAA,YADK;AAELD,IAAAA,UAFK;AAGLD,IAAAA;AAHK,GAAP;AAKD;AAED;AACA;AACA;AACA;;;AACO,SAASO,cAAT,CACLC,aADK,EAKL;AACA;AACA,MAAIC,WAAW,GAAG,CAAlB;AACA,MAAIP,YAAY,GAAG,KAAnB;;AACA,MAAIM,aAAJ,EAAmB;AACjB;AACA;AACA,KAAC;AAAEN,MAAAA;AAAF,QAAmBM,aAAa,CAACJ,QAAlC;AACAK,IAAAA,WAAW,GAAGD,aAAa,CAACE,KAA5B;AACD;;AACD,SAAO;AACLR,IAAAA,YADK;AAELO,IAAAA;AAFK,GAAP;AAID","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n LatLngArray,\n Leg,\n Money,\n Step,\n TncFare\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\n/*\nimport {\n // calculateFares,\n // getLegModeLabel,\n // getModeForPlace,\n // getPlaceName,\n // getStepDirection,\n // getStepInstructions,\n // getStepStreetName,\n // getTimeZoneOffset,\n // getTransitFare\n} from \"./deprecated\";\n\nexport {\n // calculateFares,\n // getLegModeLabel,\n // getModeForPlace,\n // getPlaceName,\n // getStepDirection,\n // getStepInstructions,\n // getStepStreetName,\n // getTimeZoneOffset,\n // getTransitFare\n};\n*/\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property of boardRule which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\";\n}\n/**\n * Returns true if the leg has continuous dropoff enabled which requires\n * asking the driver to let the user off. \"coordinateWithDriver\" is the only\n * property of alightRule which encodes this info.\n */\nexport function isContinuousDropoff(leg: Leg): boolean {\n return leg.alightRule === \"coordinateWithDriver\";\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return isReservationRequired(leg) || isContinuousDropoff(leg);\n}\n\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && tncData) {\n return tncData.company;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(itinerary: Itinerary): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including re-used canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // re-use canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks: string[],\n companies: Company[] = []\n): string {\n return networks\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: Itinerary\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\n/**\n * For an itinerary, calculates the TNC fares and returns an object with\n * these values and currency info.\n * It is assumed that the same currency is used for all TNC legs.\n */\nexport function calculateTncFares(itinerary: Itinerary): TncFare {\n let minTNCFare = 0;\n let maxTNCFare = 0;\n let currencyCode;\n itinerary.legs.forEach(({ hailedCar, mode, tncData }) => {\n if (mode === \"CAR\" && hailedCar && tncData) {\n const { currency, maxCost, minCost } = tncData;\n minTNCFare += minCost;\n maxTNCFare += maxCost;\n // Assumes a single currency for entire itinerary.\n currencyCode = currency;\n }\n });\n\n return {\n currencyCode,\n maxTNCFare,\n minTNCFare\n };\n}\n\n/**\n * For a given fare component (either total fare or component parts), returns\n * an object with the fare value (in cents).\n */\nexport function getTransitFare(\n fareComponent: Money\n): {\n currencyCode: string;\n transitFare: number;\n} {\n // Default values (if fare component is not valid).\n let transitFare = 0;\n let currencyCode = \"USD\";\n if (fareComponent) {\n // Assign values without declaration.\n // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration\n ({ currencyCode } = fareComponent.currency);\n transitFare = fareComponent.cents;\n }\n return {\n currencyCode,\n transitFare\n };\n}\n"],"file":"itinerary.js"}
|
|
1
|
+
{"version":3,"sources":["../src/itinerary.ts"],"names":["transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","isContinuousDropoff","alightRule","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","polyline","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","hailedCar","reduce","maxTNCFare","minTNCFare","currency","maxCost","minCost","currencyCode","getTransitFare","fareComponent","transitFare","cents","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","carbonIntensityWithDefaults","totalCarbon","total"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAaA;;AAEA;AACO,MAAMA,YAAY,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7J,GAAG,CAACJ,IAAJ,CAASwC,WAAT,EAAD,CAA1C,IACC,CADF,IACO2H,KAFT;AAID,GALD,EAKG,CALH,MAKS,CANX;;AAQA,UAAQ5F,KAAR;AACE,SAAK,OAAL;AACE,aAAO2F,WAAW,GAAG,KAArB;;AACF,SAAK,UAAL;AACE,aAAOA,WAAW,GAAG,IAArB;;AACF,SAAK,OAAL;AACE,aAAOA,WAAW,GAAG,GAArB;;AACF,SAAK,MAAL;AACA;AACE,aAAOA,WAAP;AATJ;AAWD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n LatLngArray,\n Leg,\n Money,\n Step,\n TncFare\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property of boardRule which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\";\n}\n/**\n * Returns true if the leg has continuous dropoff enabled which requires\n * asking the driver to let the user off. \"coordinateWithDriver\" is the only\n * property of alightRule which encodes this info.\n */\nexport function isContinuousDropoff(leg: Leg): boolean {\n return leg.alightRule === \"coordinateWithDriver\";\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return isReservationRequired(leg) || isContinuousDropoff(leg);\n}\n\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && tncData) {\n return tncData.company;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(itinerary: Itinerary): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including re-used canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // re-use canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks: string[],\n companies: Company[] = []\n): string {\n return networks\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: Itinerary\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\n/**\n * For an itinerary, calculates the TNC fares and returns an object with\n * these values and currency info.\n * It is assumed that the same currency is used for all TNC legs.\n */\nexport function calculateTncFares(itinerary: Itinerary): TncFare {\n return itinerary.legs\n .filter(leg => leg.mode === \"CAR\" && leg.hailedCar && leg.tncData)\n .reduce(\n ({ maxTNCFare, minTNCFare }, { tncData }) => {\n const { currency, maxCost, minCost } = tncData;\n return {\n // Assumes a single currency for entire itinerary.\n currencyCode: currency,\n maxTNCFare: maxTNCFare + maxCost,\n minTNCFare: minTNCFare + minCost\n };\n },\n {\n currencyCode: null,\n maxTNCFare: 0,\n minTNCFare: 0\n }\n );\n}\n\n/**\n * For a given fare component (either total fare or component parts), returns\n * an object with the fare value (in cents).\n */\nexport function getTransitFare(\n fareComponent: Money\n): {\n currencyCode: string;\n transitFare: number;\n} {\n return fareComponent\n ? {\n currencyCode: fareComponent.currency.currencyCode,\n transitFare: fareComponent.cents\n }\n : {\n currencyCode: \"USD\",\n transitFare: 0\n };\n}\n\n/**\n * Sources:\n * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf\n * - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey\n * - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx\n * Other values extrapolated.\n */\nconst CARBON_INTENSITY_DEFAULTS = {\n walk: 0.026,\n bicycle: 0.017,\n car: 0.162,\n tram: 0.066,\n subway: 0.066,\n rail: 0.066,\n bus: 0.09,\n ferry: 0.082,\n cable_car: 0.021,\n gondola: 0.021,\n funicular: 0.066,\n transit: 0.066,\n leg_switch: 0,\n airplane: 0.382,\n micromobility: 0.095\n};\n\n/**\n * @param {itinerary} itinerary OTP trip itinierary\n * @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter\n * @param {units} units units to be used in return value\n * @return Amount of carbon in chosen unit\n */\nexport function calculateEmissions(\n itinerary: Itinerary,\n carbonIntensity: Record<string, number> = {},\n units?: string\n): number {\n // Apply defaults for any values that we don't have.\n const carbonIntensityWithDefaults = {\n ...CARBON_INTENSITY_DEFAULTS,\n ...carbonIntensity\n };\n\n // Distance is in meters, totalCarbon is in grams\n const totalCarbon =\n itinerary?.legs?.reduce((total, leg) => {\n return (\n (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] ||\n 0) + total\n );\n }, 0) || 0;\n\n switch (units) {\n case \"ounce\":\n return totalCarbon / 28.35;\n case \"kilogram\":\n return totalCarbon / 1000;\n case \"pound\":\n return totalCarbon / 454;\n case \"gram\":\n default:\n return totalCarbon;\n }\n}\n"],"file":"itinerary.js"}
|
package/lib/map.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export declare function constructLocation(latlng: {
|
|
|
6
6
|
lat: number;
|
|
7
7
|
lng: number;
|
|
8
8
|
}): Location;
|
|
9
|
-
export declare function formatStoredPlaceName(location: Location): string;
|
|
10
9
|
export declare function matchLatLon(location1: Location, location2: Location): boolean;
|
|
11
10
|
declare type TransitivePlaceRaw = {
|
|
12
11
|
place_id: string;
|
package/lib/map.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE7E,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,YAAY,GAC5B,QAAQ,CAYV;AAID,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAEvD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEpD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,QAAQ,CAKX;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,GAAG,OAAO,CAG7E;AAED,aAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AACF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAErE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAEpE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAEtE;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAOvD"}
|
package/lib/map.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.currentPositionToLocation = currentPositionToLocation;
|
|
|
7
7
|
exports.coordsToString = coordsToString;
|
|
8
8
|
exports.stringToCoords = stringToCoords;
|
|
9
9
|
exports.constructLocation = constructLocation;
|
|
10
|
-
exports.formatStoredPlaceName = formatStoredPlaceName;
|
|
11
10
|
exports.matchLatLon = matchLatLon;
|
|
12
11
|
exports.isBikeshareStation = isBikeshareStation;
|
|
13
12
|
exports.isEScooterStation = isEScooterStation;
|
|
@@ -16,18 +15,6 @@ exports.isValidLat = isValidLat;
|
|
|
16
15
|
exports.isValidLng = isValidLng;
|
|
17
16
|
exports.isValidLatLng = isValidLatLng;
|
|
18
17
|
|
|
19
|
-
var _itinerary = require("./itinerary");
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
import {
|
|
23
|
-
// coordsToString,
|
|
24
|
-
// getDetailText //,
|
|
25
|
-
// latlngToString,
|
|
26
|
-
// logDeprecationWarning
|
|
27
|
-
} from "./deprecated";
|
|
28
|
-
|
|
29
|
-
export { coordsToString, getDetailText , latlngToString };
|
|
30
|
-
*/
|
|
31
18
|
function currentPositionToLocation(currentPosition) {
|
|
32
19
|
if (currentPosition.error || !currentPosition.coords) {
|
|
33
20
|
console.warn("Cannot construct location from current position due to geolocation error or missing coordinates.");
|
|
@@ -39,8 +26,8 @@ function currentPositionToLocation(currentPosition) {
|
|
|
39
26
|
lon: currentPosition.coords.longitude,
|
|
40
27
|
category: "CURRENT_LOCATION"
|
|
41
28
|
};
|
|
42
|
-
} // TRICKY:
|
|
43
|
-
// otp-rr actions where the intl context is not available.
|
|
29
|
+
} // TRICKY: This method is used in query.js and in the context of
|
|
30
|
+
// otp-rr actions where the intl context is not available/does not apply.
|
|
44
31
|
|
|
45
32
|
|
|
46
33
|
function coordsToString(coords) {
|
|
@@ -58,10 +45,6 @@ function constructLocation(latlng) {
|
|
|
58
45
|
};
|
|
59
46
|
}
|
|
60
47
|
|
|
61
|
-
function formatStoredPlaceName(location) {
|
|
62
|
-
return location.type === "home" || location.type === "work" ? (0, _itinerary.toSentenceCase)(location.type) : location.name;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
48
|
function matchLatLon(location1, location2) {
|
|
66
49
|
if (!location1 || !location2) return location1 === location2;
|
|
67
50
|
return location1.lat === location2.lat && location1.lon === location2.lon;
|
package/lib/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/map.ts"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","coordsToString","length","map","c","toFixed","join","stringToCoords","str","split","constructLocation","latlng","lng","
|
|
1
|
+
{"version":3,"sources":["../src/map.ts"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","coordsToString","length","map","c","toFixed","join","stringToCoords","str","split","constructLocation","latlng","lng","matchLatLon","location1","location2","isBikeshareStation","place","place_id","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray"],"mappings":";;;;;;;;;;;;;;;;;AAEO,SAASA,yBAAT,CACLC,eADK,EAEK;AACV,MAAIA,eAAe,CAACC,KAAhB,IAAyB,CAACD,eAAe,CAACE,MAA9C,EAAsD;AACpDC,IAAAA,OAAO,CAACC,IAAR,CACE,kGADF;AAGA,WAAO,IAAP;AACD;;AACD,SAAO;AACLC,IAAAA,GAAG,EAAEL,eAAe,CAACE,MAAhB,CAAuBI,QADvB;AAELC,IAAAA,GAAG,EAAEP,eAAe,CAACE,MAAhB,CAAuBM,SAFvB;AAGLC,IAAAA,QAAQ,EAAE;AAHL,GAAP;AAKD,C,CAED;AACA;;;AACO,SAASC,c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,CAACC,QAAP,CAAgB5B,GAAhB,KAAwBA,GAAG,IAAI,CAAC,EAAhC,IAAsCA,GAAG,IAAI,EAApD;AACD;;AAEM,SAAS6B,UAAT,CAAoBb,GAApB,EAA0C;AAC/C,SAAOW,MAAM,CAACC,QAAP,CAAgBZ,GAAhB,KAAwBA,GAAG,IAAI,CAAC,GAAhC,IAAuCA,GAAG,IAAI,GAArD;AACD;;AAEM,SAASc,aAAT,CAAuBC,GAAvB,EAAkD;AACvD,SACEC,KAAK,CAACC,OAAN,CAAcF,GAAd,KACAA,GAAG,CAACzB,MAAJ,KAAe,CADf,IAEAoB,UAAU,CAACK,GAAG,CAAC,CAAD,CAAJ,CAFV,IAGAF,UAAU,CAACE,GAAG,CAAC,CAAD,CAAJ,CAJZ;AAMD","sourcesContent":["import { LatLngArray, Location, UserPosition } from \"@opentripplanner/types\";\n\nexport function currentPositionToLocation(\n currentPosition: UserPosition\n): Location {\n if (currentPosition.error || !currentPosition.coords) {\n console.warn(\n \"Cannot construct location from current position due to geolocation error or missing coordinates.\"\n );\n return null;\n }\n return {\n lat: currentPosition.coords.latitude,\n lon: currentPosition.coords.longitude,\n category: \"CURRENT_LOCATION\"\n };\n}\n\n// TRICKY: This method is used in query.js and in the context of\n// otp-rr actions where the intl context is not available/does not apply.\nexport function coordsToString(coords: number[]): string {\n return coords.length && coords.map(c => (+c).toFixed(5)).join(\", \");\n}\n\nexport function stringToCoords(str: string): number[] {\n return (str && str.split(\",\").map(c => +c)) || [];\n}\n\nexport function constructLocation(latlng: {\n lat: number;\n lng: number;\n}): Location {\n return {\n lat: latlng.lat,\n lon: latlng.lng\n };\n}\n\nexport function matchLatLon(location1: Location, location2: Location): boolean {\n if (!location1 || !location2) return location1 === location2;\n return location1.lat === location2.lat && location1.lon === location2.lon;\n}\n\ntype TransitivePlaceRaw = {\n place_id: string;\n};\nexport function isBikeshareStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"bicycle_rent_station\") !== -1;\n}\n\nexport function isEScooterStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"escooter_rent_station\") !== -1;\n}\n\nexport function isCarWalkTransition(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"itin_car_\") !== -1;\n}\n\nexport function isValidLat(lat: number): boolean {\n return Number.isFinite(lat) && lat >= -90 && lat <= 90;\n}\n\nexport function isValidLng(lng: number): boolean {\n return Number.isFinite(lng) && lng >= -180 && lng <= 180;\n}\n\nexport function isValidLatLng(arr: LatLngArray): boolean {\n return (\n Array.isArray(arr) &&\n arr.length === 2 &&\n isValidLat(arr[0]) &&\n isValidLng(arr[1])\n );\n}\n"],"file":"map.js"}
|
package/lib/query.js
CHANGED
|
@@ -34,9 +34,6 @@ var _queryParams = _interopRequireDefault(require("./query-params"));
|
|
|
34
34
|
|
|
35
35
|
var _time = require("./time");
|
|
36
36
|
|
|
37
|
-
// import { coordsToString, summarizeQuery } from "./deprecated";
|
|
38
|
-
// export { summarizeQuery };
|
|
39
|
-
|
|
40
37
|
/* The list of default parameters considered in the settings panel */
|
|
41
38
|
const defaultParams = ["wheelchair", "maxWalkDistance", "walkReluctance", "maxWalkTime", "walkSpeed", "maxBikeDistance", "maxBikeTime", "bikeSpeed", "optimize", "optimizeBike", "maxEScooterDistance", "watts"];
|
|
42
39
|
/**
|
|
@@ -419,7 +416,7 @@ function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {
|
|
|
419
416
|
} // check date/time validity; ignore both if either is invalid
|
|
420
417
|
|
|
421
418
|
|
|
422
|
-
const dateValid = (0, _dateFns.isMatch)(params.date, _time.
|
|
419
|
+
const dateValid = (0, _dateFns.isMatch)(params.date, _time.OTP_API_DATE_FORMAT);
|
|
423
420
|
const timeValid = (0, _dateFns.isMatch)(params.time, _time.OTP_API_TIME_FORMAT);
|
|
424
421
|
|
|
425
422
|
if (!dateValid || !timeValid) {
|