@nshiab/simple-data-analysis-core 2.1.7 → 2.1.9
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/class/SimpleTable.d.ts +191 -108
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +188 -105
- package/esm/helpers/buildGraphTemporalCostStateSql.d.ts +1 -1
- package/esm/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -1
- package/esm/helpers/buildGraphTemporalCostStateSql.js +23 -9
- package/esm/helpers/graphRouteResultSchema.d.ts +1 -1
- package/esm/helpers/graphRouteResultSchema.d.ts.map +1 -1
- package/esm/helpers/graphRouteResultSchema.js +3 -3
- package/esm/helpers/graphRouteResultSelect.d.ts +1 -1
- package/esm/helpers/graphRouteResultSelect.d.ts.map +1 -1
- package/esm/helpers/graphRouteResultSelect.js +2 -2
- package/esm/helpers/prepareGraphMetricOptions.d.ts +2 -2
- package/esm/helpers/prepareGraphMetricOptions.d.ts.map +1 -1
- package/esm/helpers/prepareGraphMetricOptions.js +5 -4
- package/esm/helpers/prepareGraphRouteSql.d.ts +2 -2
- package/esm/helpers/prepareGraphRouteSql.d.ts.map +1 -1
- package/esm/helpers/prepareGraphRouteSql.js +4 -4
- package/esm/helpers/validateGraphRouteResultSchema.d.ts +1 -1
- package/esm/helpers/validateGraphRouteResultSchema.d.ts.map +1 -1
- package/esm/helpers/validateGraphRouteResultSchema.js +3 -1
- package/esm/methods/distances.d.ts +1 -1
- package/esm/methods/distances.d.ts.map +1 -1
- package/esm/methods/distances.js +235 -73
- package/esm/methods/shortestPath.d.ts +1 -1
- package/esm/methods/shortestPath.d.ts.map +1 -1
- package/esm/methods/shortestPath.js +44 -28
- package/esm/methods/similarityMahalanobis.js +3 -3
- package/llm.md +214 -119
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/script/class/SimpleTable.d.ts +191 -108
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +188 -105
- package/script/helpers/buildGraphTemporalCostStateSql.d.ts +1 -1
- package/script/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -1
- package/script/helpers/buildGraphTemporalCostStateSql.js +23 -9
- package/script/helpers/graphRouteResultSchema.d.ts +1 -1
- package/script/helpers/graphRouteResultSchema.d.ts.map +1 -1
- package/script/helpers/graphRouteResultSchema.js +3 -3
- package/script/helpers/graphRouteResultSelect.d.ts +1 -1
- package/script/helpers/graphRouteResultSelect.d.ts.map +1 -1
- package/script/helpers/graphRouteResultSelect.js +2 -2
- package/script/helpers/prepareGraphMetricOptions.d.ts +2 -2
- package/script/helpers/prepareGraphMetricOptions.d.ts.map +1 -1
- package/script/helpers/prepareGraphMetricOptions.js +5 -4
- package/script/helpers/prepareGraphRouteSql.d.ts +2 -2
- package/script/helpers/prepareGraphRouteSql.d.ts.map +1 -1
- package/script/helpers/prepareGraphRouteSql.js +4 -4
- package/script/helpers/validateGraphRouteResultSchema.d.ts +1 -1
- package/script/helpers/validateGraphRouteResultSchema.d.ts.map +1 -1
- package/script/helpers/validateGraphRouteResultSchema.js +3 -1
- package/script/methods/distances.d.ts +1 -1
- package/script/methods/distances.d.ts.map +1 -1
- package/script/methods/distances.js +235 -73
- package/script/methods/shortestPath.d.ts +1 -1
- package/script/methods/shortestPath.d.ts.map +1 -1
- package/script/methods/shortestPath.js +44 -28
- package/script/methods/similarityMahalanobis.js +3 -3
|
@@ -2776,38 +2776,23 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2776
2776
|
}
|
|
2777
2777
|
/**
|
|
2778
2778
|
* Finds the shortest routes from each starting node to every reachable
|
|
2779
|
-
* node
|
|
2780
|
-
*
|
|
2781
|
-
*
|
|
2779
|
+
* node. Without options, shortest means the fewest connections. Use `weight`
|
|
2780
|
+
* to report total cost and `elapsedTime` to report duration including waiting
|
|
2781
|
+
* between connections. Use `minimize` to choose which metric defines shortest.
|
|
2782
2782
|
*
|
|
2783
|
-
*
|
|
2784
|
-
*
|
|
2785
|
-
*
|
|
2786
|
-
*
|
|
2787
|
-
* Each row gives the selected route's total cost from `start` to `node`.
|
|
2788
|
-
* Intermediate steps along the route are not returned. To get the steps
|
|
2789
|
-
* between two different nodes, use `shortestPath()` for the shortest routes
|
|
2790
|
-
* or `paths()` for all routes without repeated nodes.
|
|
2791
|
-
*
|
|
2792
|
-
* A starting node appears in its own results only when a self-connection
|
|
2793
|
-
* or a route leads back to it. Its total is the cost of the shortest actual
|
|
2794
|
-
* return route, using at least one connection. With `direction: "both"`, this
|
|
2795
|
-
* can mean following the same connection out and back.
|
|
2796
|
-
*
|
|
2797
|
-
* Unknown starting IDs and starts with no connections to follow produce
|
|
2798
|
-
* no rows. Empty start arrays and duplicate starting IDs throw an error.
|
|
2799
|
-
* Weights must be non-null, finite, and non-negative.
|
|
2783
|
+
* Each row contains `start`, `node`, and `steps`, plus `total` when `weight`
|
|
2784
|
+
* is supplied and `elapsedTimeMs` when enabled. Routes tied on the chosen
|
|
2785
|
+
* metric produce separate rows only when their reported summaries differ;
|
|
2786
|
+
* identical summaries appear once.
|
|
2800
2787
|
*
|
|
2801
|
-
*
|
|
2802
|
-
* in
|
|
2803
|
-
*
|
|
2804
|
-
*
|
|
2805
|
-
*
|
|
2806
|
-
* `true`, rejecting zero-duration gaps. These options only work with
|
|
2807
|
-
* `direction: "outgoing"` or `direction: "incoming"`.
|
|
2788
|
+
* Routes cannot repeat nodes except for a final return to the start. A start
|
|
2789
|
+
* appears in its own results only through an actual return or self-connection,
|
|
2790
|
+
* never with zero steps. With `direction: "both"`, a return can follow the
|
|
2791
|
+
* same connection out and back. Use `shortestPath()` to inspect individual
|
|
2792
|
+
* connections between two different nodes.
|
|
2808
2793
|
*
|
|
2809
|
-
*
|
|
2810
|
-
*
|
|
2794
|
+
* Reporting weight or elapsed time can require substantial time and memory
|
|
2795
|
+
* on dense networks because many routes may need to be explored.
|
|
2811
2796
|
*
|
|
2812
2797
|
* The next five examples each start with this data:
|
|
2813
2798
|
*
|
|
@@ -2827,7 +2812,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2827
2812
|
* .log();
|
|
2828
2813
|
* ```
|
|
2829
2814
|
*
|
|
2830
|
-
* | start | node |
|
|
2815
|
+
* | start | node | steps |
|
|
2831
2816
|
* | --- | --- | ---: |
|
|
2832
2817
|
* | A | B | 1 |
|
|
2833
2818
|
* | A | C | 2 |
|
|
@@ -2841,10 +2826,10 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2841
2826
|
* .log();
|
|
2842
2827
|
* ```
|
|
2843
2828
|
*
|
|
2844
|
-
* | start | node | total |
|
|
2845
|
-
* | --- | --- | ---: |
|
|
2846
|
-
* | A | B | 4 |
|
|
2847
|
-
* | A | C | 5 |
|
|
2829
|
+
* | start | node | steps | total |
|
|
2830
|
+
* | --- | --- | ---: | ---: |
|
|
2831
|
+
* | A | B | 1 | 4 |
|
|
2832
|
+
* | A | C | 2 | 5 |
|
|
2848
2833
|
*
|
|
2849
2834
|
* With `direction: "incoming"`, connections are followed from target to
|
|
2850
2835
|
* source. Starting at C:
|
|
@@ -2856,7 +2841,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2856
2841
|
* .log();
|
|
2857
2842
|
* ```
|
|
2858
2843
|
*
|
|
2859
|
-
* | start | node |
|
|
2844
|
+
* | start | node | steps |
|
|
2860
2845
|
* | --- | --- | ---: |
|
|
2861
2846
|
* | C | B | 1 |
|
|
2862
2847
|
* | C | A | 2 |
|
|
@@ -2872,14 +2857,14 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2872
2857
|
* .log();
|
|
2873
2858
|
* ```
|
|
2874
2859
|
*
|
|
2875
|
-
* | start | node |
|
|
2860
|
+
* | start | node | steps |
|
|
2876
2861
|
* | --- | --- | ---: |
|
|
2877
2862
|
* | A | B | 1 |
|
|
2878
2863
|
* | A | A | 2 |
|
|
2879
2864
|
* | A | C | 2 |
|
|
2880
2865
|
* | A | D | 2 |
|
|
2881
2866
|
*
|
|
2882
|
-
* A appears with
|
|
2867
|
+
* A appears with 2 steps because A → B → A follows a connection out
|
|
2883
2868
|
* and back.
|
|
2884
2869
|
*
|
|
2885
2870
|
* An array of starting nodes gives separate distances for each start:
|
|
@@ -2893,12 +2878,12 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2893
2878
|
* .log();
|
|
2894
2879
|
* ```
|
|
2895
2880
|
*
|
|
2896
|
-
* | start | node | total |
|
|
2897
|
-
* | --- | --- | ---: |
|
|
2898
|
-
* | A | B | 4 |
|
|
2899
|
-
* | A | C | 5 |
|
|
2900
|
-
* | D | B | 2 |
|
|
2901
|
-
* | D | C | 3 |
|
|
2881
|
+
* | start | node | steps | total |
|
|
2882
|
+
* | --- | --- | ---: | ---: |
|
|
2883
|
+
* | A | B | 1 | 4 |
|
|
2884
|
+
* | A | C | 2 | 5 |
|
|
2885
|
+
* | D | B | 1 | 2 |
|
|
2886
|
+
* | D | C | 2 | 3 |
|
|
2902
2887
|
*
|
|
2903
2888
|
* A direct self-connection and a longer return route can both lead back
|
|
2904
2889
|
* to the start. This example uses different data:
|
|
@@ -2919,13 +2904,13 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2919
2904
|
* .log();
|
|
2920
2905
|
* ```
|
|
2921
2906
|
*
|
|
2922
|
-
* | start | node | total |
|
|
2923
|
-
* | --- | --- | ---: |
|
|
2924
|
-
* | A | B | 2 |
|
|
2925
|
-
* | A | A | 5 |
|
|
2907
|
+
* | start | node | steps | total |
|
|
2908
|
+
* | --- | --- | ---: | ---: |
|
|
2909
|
+
* | A | B | 1 | 2 |
|
|
2910
|
+
* | A | A | 2 | 5 |
|
|
2926
2911
|
*
|
|
2927
2912
|
* Chronological options can rule out a cheaper sequence that departs too
|
|
2928
|
-
* early.
|
|
2913
|
+
* early. Here, B → C leaves before A → B arrives, while B → D meets the
|
|
2929
2914
|
* one-hour minimum exactly:
|
|
2930
2915
|
*
|
|
2931
2916
|
* | origin | destination | departureTime | arrivalTime | minutes |
|
|
@@ -2946,12 +2931,12 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2946
2931
|
* .log();
|
|
2947
2932
|
* ```
|
|
2948
2933
|
*
|
|
2949
|
-
* | start | node | total |
|
|
2950
|
-
* | --- | --- | ---: |
|
|
2951
|
-
* | A | B | 2 |
|
|
2952
|
-
* | A | D | 5 |
|
|
2934
|
+
* | start | node | steps | total |
|
|
2935
|
+
* | --- | --- | ---: | ---: |
|
|
2936
|
+
* | A | B | 1 | 2 |
|
|
2937
|
+
* | A | D | 2 | 5 |
|
|
2953
2938
|
*
|
|
2954
|
-
* For the next
|
|
2939
|
+
* For the next four examples, `flights` contains these rows, with departure
|
|
2955
2940
|
* and arrival stored as timestamps on the same day:
|
|
2956
2941
|
*
|
|
2957
2942
|
* | flightId | origin | destination | departure | arrival | price |
|
|
@@ -2975,7 +2960,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2975
2960
|
* .log();
|
|
2976
2961
|
* ```
|
|
2977
2962
|
*
|
|
2978
|
-
* | start | node |
|
|
2963
|
+
* | start | node | steps | elapsedTimeMs |
|
|
2979
2964
|
* | --- | --- | ---: | ---: |
|
|
2980
2965
|
* | A | B | 1 | 3600000 |
|
|
2981
2966
|
* | A | C | 1 | 10800000 |
|
|
@@ -2999,29 +2984,94 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2999
2984
|
* .log();
|
|
3000
2985
|
* ```
|
|
3001
2986
|
*
|
|
3002
|
-
* | start | node | total | elapsedTimeMs |
|
|
3003
|
-
* | --- | --- | ---: | ---: |
|
|
3004
|
-
* | A | B | 40 | 3600000 |
|
|
3005
|
-
* | A | C | 120 | 10800000 |
|
|
2987
|
+
* | start | node | steps | total | elapsedTimeMs |
|
|
2988
|
+
* | --- | --- | ---: | ---: | ---: |
|
|
2989
|
+
* | A | B | 1 | 40 | 3600000 |
|
|
2990
|
+
* | A | C | 1 | 120 | 10800000 |
|
|
3006
2991
|
*
|
|
3007
|
-
* Use `minimize: "weight"` to find the cheapest journeys instead.
|
|
3008
|
-
*
|
|
3009
|
-
*
|
|
2992
|
+
* Use `minimize: "weight"` to find the cheapest journeys instead. The
|
|
2993
|
+
* selected route to C now takes two steps through B and costs 80:
|
|
2994
|
+
*
|
|
2995
|
+
* @example
|
|
2996
|
+
* ```ts
|
|
2997
|
+
* await flights
|
|
2998
|
+
* .distances("origin", "destination", "A", {
|
|
2999
|
+
* startTimeColumn: "departure",
|
|
3000
|
+
* endTimeColumn: "arrival",
|
|
3001
|
+
* minGapMs: 60 * 60 * 1000,
|
|
3002
|
+
* elapsedTime: true,
|
|
3003
|
+
* weight: "price",
|
|
3004
|
+
* minimize: "weight",
|
|
3005
|
+
* })
|
|
3006
|
+
* .log();
|
|
3007
|
+
* ```
|
|
3008
|
+
*
|
|
3009
|
+
* | start | node | steps | total | elapsedTimeMs |
|
|
3010
|
+
* | --- | --- | ---: | ---: | ---: |
|
|
3011
|
+
* | A | B | 1 | 40 | 3600000 |
|
|
3012
|
+
* | A | C | 2 | 80 | 14400000 |
|
|
3013
|
+
*
|
|
3014
|
+
* Choose the fewest connections while still reporting price and elapsed
|
|
3015
|
+
* time. The direct flight to C has one step, even though it costs more:
|
|
3016
|
+
*
|
|
3017
|
+
* @example
|
|
3018
|
+
* ```ts
|
|
3019
|
+
* await flights
|
|
3020
|
+
* .distances("origin", "destination", "A", {
|
|
3021
|
+
* startTimeColumn: "departure",
|
|
3022
|
+
* endTimeColumn: "arrival",
|
|
3023
|
+
* minGapMs: 60 * 60 * 1000,
|
|
3024
|
+
* elapsedTime: true,
|
|
3025
|
+
* weight: "price",
|
|
3026
|
+
* minimize: "steps",
|
|
3027
|
+
* })
|
|
3028
|
+
* .log();
|
|
3029
|
+
* ```
|
|
3030
|
+
*
|
|
3031
|
+
* | start | node | steps | total | elapsedTimeMs |
|
|
3032
|
+
* | --- | --- | ---: | ---: | ---: |
|
|
3033
|
+
* | A | B | 1 | 40 | 3600000 |
|
|
3034
|
+
* | A | C | 1 | 120 | 10800000 |
|
|
3035
|
+
*
|
|
3036
|
+
* When two routes to C both take two steps but have different prices,
|
|
3037
|
+
* minimizing steps while reporting price returns both summaries:
|
|
3038
|
+
*
|
|
3039
|
+
* @example
|
|
3040
|
+
* ```ts
|
|
3041
|
+
* await connections
|
|
3042
|
+
* .loadArray([
|
|
3043
|
+
* { origin: "A", destination: "B", price: 20 },
|
|
3044
|
+
* { origin: "B", destination: "C", price: 30 },
|
|
3045
|
+
* { origin: "A", destination: "D", price: 40 },
|
|
3046
|
+
* { origin: "D", destination: "C", price: 40 },
|
|
3047
|
+
* ])
|
|
3048
|
+
* .distances("origin", "destination", "A", {
|
|
3049
|
+
* weight: "price",
|
|
3050
|
+
* minimize: "steps",
|
|
3051
|
+
* })
|
|
3052
|
+
* .filter("node = 'C'")
|
|
3053
|
+
* .log();
|
|
3054
|
+
* ```
|
|
3055
|
+
*
|
|
3056
|
+
* | start | node | steps | total |
|
|
3057
|
+
* | --- | --- | ---: | ---: |
|
|
3058
|
+
* | A | C | 2 | 50 |
|
|
3059
|
+
* | A | C | 2 | 80 |
|
|
3010
3060
|
*
|
|
3011
3061
|
* @param sourceColumn - The name of the column containing each connection's source node ID.
|
|
3012
3062
|
* @param targetColumn - The name of the column containing each connection's target node ID.
|
|
3013
|
-
* @param startNodes - One starting node ID or
|
|
3063
|
+
* @param startNodes - One starting node ID or a non-empty array of distinct IDs. Unknown IDs and starts with no connections to follow produce no rows. Empty arrays and duplicate IDs throw an error.
|
|
3014
3064
|
* @param options - An optional object with direction, time, and result configuration.
|
|
3015
|
-
* @param options.direction - The direction in which to follow connections. Defaults to `"outgoing"`.
|
|
3065
|
+
* @param options.direction - The direction in which to follow connections. Defaults to `"outgoing"`. Chronological traversal supports only `"outgoing"` and `"incoming"`.
|
|
3016
3066
|
* @param options.startTimeColumn - The name of the column containing each connection's start time. Use this or `endTimeColumn` to follow connections in chronological order.
|
|
3017
3067
|
* @param options.endTimeColumn - The name of the column containing each connection's end time. Use this or `startTimeColumn` to follow connections in chronological order.
|
|
3018
|
-
* @param options.minGapMs - The minimum gap between consecutive connections, in milliseconds. Must be a non-negative integer. Defaults to `0`. Requires a time column.
|
|
3068
|
+
* @param options.minGapMs - The minimum gap between consecutive connections, in milliseconds; does not apply before the first connection. With both time columns, measured from one connection's end to the next's start; with one column, between timestamps. Must be a non-negative integer. Defaults to `0`. Requires a time column.
|
|
3019
3069
|
* @param options.strictOrdering - Whether to reject zero-duration gaps between consecutive connections (equal timestamps). Defaults to `true`. Requires a time column.
|
|
3020
|
-
* @param options.weight - The name of the numeric column used as the cost of each connection. If omitted,
|
|
3021
|
-
* @param options.elapsedTime - Whether to add cumulative `elapsedTimeMs` in milliseconds, including connection gaps. Defaults to `false`. Requires both time columns.
|
|
3022
|
-
* @param options.minimize - The metric used to select optimal routes
|
|
3070
|
+
* @param options.weight - The name of the numeric column used as the cost of each connection. Values must be non-null, finite, and non-negative. Adds `total`, the cumulative sum of those costs. If omitted, no `total` column is generated.
|
|
3071
|
+
* @param options.elapsedTime - Whether to add cumulative `elapsedTimeMs` in milliseconds, including connection gaps. Defaults to `false`. Requires both time columns. Optimization compares native timestamp precision before conversion to milliseconds.
|
|
3072
|
+
* @param options.minimize - The metric used to select optimal routes: `"steps"`, `"weight"`, or `"elapsedTime"`. Defaults to `"weight"` when only `weight` is enabled, `"elapsedTime"` when only elapsed-time reporting is enabled, and `"steps"` when neither is enabled. Required when both are enabled. `"steps"` is always available; the other metrics require their corresponding options.
|
|
3023
3073
|
* @param options.outputTable - If `true`, stores the result in a new table with a generated name. If a string, uses it as the new table's name. If `false` or omitted, overwrites the current table. Defaults to `false`.
|
|
3024
|
-
* @returns The
|
|
3074
|
+
* @returns The table of distinct optimal summaries with `start`, `node`, and `steps`, plus `total` when `weight` is supplied and `elapsedTimeMs` when enabled, so methods can be chained. Sorted by start, the chosen metric, node, then remaining metrics in the order steps, total, elapsed time.
|
|
3025
3075
|
* @category Graph Operations
|
|
3026
3076
|
*/
|
|
3027
3077
|
distances(sourceColumn, targetColumn, startNodes, options = {}) {
|
|
@@ -3042,15 +3092,17 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3042
3092
|
* containing these IDs as the `edgeId` argument. If your table is missing
|
|
3043
3093
|
* an ID column, you can easily create one with `addId()`.
|
|
3044
3094
|
*
|
|
3045
|
-
* The result starts with
|
|
3046
|
-
* columns
|
|
3047
|
-
* the search direction. The `weight` column is the connection cost,
|
|
3048
|
-
*
|
|
3049
|
-
*
|
|
3095
|
+
* The result starts with `pathId`, `step`, and `weight`, followed by the
|
|
3096
|
+
* optional metric columns and all original columns. Steps start at one and
|
|
3097
|
+
* follow the search direction. The `weight` column is the connection cost,
|
|
3098
|
+
* or one when no `weight` option is supplied. Supplying `weight` also adds
|
|
3099
|
+
* `total`, the sum of those costs up to and including the current step.
|
|
3100
|
+
* Enabling `elapsedTime` adds cumulative `elapsedTimeMs`, including gaps.
|
|
3050
3101
|
*
|
|
3051
|
-
* If an input column
|
|
3052
|
-
*
|
|
3053
|
-
*
|
|
3102
|
+
* If an input column conflicts with a generated result column (regardless
|
|
3103
|
+
* of capitalization), the method throws an error. Rename it with
|
|
3104
|
+
* `renameColumns()` first. `total` is reserved only when `weight` is supplied,
|
|
3105
|
+
* and `elapsedTimeMs` only when elapsed-time reporting is enabled.
|
|
3054
3106
|
*
|
|
3055
3107
|
* Each row is one connection along a route.
|
|
3056
3108
|
*
|
|
@@ -3065,6 +3117,16 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3065
3117
|
* The minimum gap applies only between consecutive connections, not before
|
|
3066
3118
|
* the first connection.
|
|
3067
3119
|
*
|
|
3120
|
+
* Use `minimize: "steps"` to choose the fewest connections even when weight
|
|
3121
|
+
* or elapsed-time reporting is enabled. Without an explicit `minimize`, the
|
|
3122
|
+
* method minimizes weight when only `weight` is enabled, elapsed time when
|
|
3123
|
+
* only `elapsedTime` is enabled, and steps when neither is enabled. With
|
|
3124
|
+
* both enabled, specify `"steps"`, `"weight"`, or `"elapsedTime"` explicitly.
|
|
3125
|
+
* Elapsed-time reporting requires both time columns.
|
|
3126
|
+
*
|
|
3127
|
+
* All routes tied on the selected metric are returned, even if their other
|
|
3128
|
+
* metrics differ. Each route reports its own weights and elapsed times.
|
|
3129
|
+
*
|
|
3068
3130
|
* Routes are numbered from zero by comparing their sequences of connection
|
|
3069
3131
|
* IDs, element by element. Rows are sorted by `pathId`, then `step`.
|
|
3070
3132
|
*
|
|
@@ -3095,14 +3157,14 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3095
3157
|
* .log();
|
|
3096
3158
|
* ```
|
|
3097
3159
|
*
|
|
3098
|
-
* | pathId | step | weight |
|
|
3099
|
-
* | ---: | ---: | ---: |
|
|
3100
|
-
* | 0 | 1 | 1 |
|
|
3101
|
-
* | 0 | 2 | 1 |
|
|
3102
|
-
* | 0 | 3 | 1 |
|
|
3103
|
-
* | 1 | 1 | 1 |
|
|
3104
|
-
* | 1 | 2 | 1 |
|
|
3105
|
-
* | 1 | 3 | 1 |
|
|
3160
|
+
* | pathId | step | weight | edgeId | source | target |
|
|
3161
|
+
* | ---: | ---: | ---: | --- | --- | --- |
|
|
3162
|
+
* | 0 | 1 | 1 | E1 | A | B |
|
|
3163
|
+
* | 0 | 2 | 1 | E3 | B | D |
|
|
3164
|
+
* | 0 | 3 | 1 | E5 | D | E |
|
|
3165
|
+
* | 1 | 1 | 1 | E2 | A | C |
|
|
3166
|
+
* | 1 | 2 | 1 | E4 | C | D |
|
|
3167
|
+
* | 1 | 3 | 1 | E5 | D | E |
|
|
3106
3168
|
*
|
|
3107
3169
|
* For an input without connection IDs, use `addId()` first:
|
|
3108
3170
|
*
|
|
@@ -3121,10 +3183,10 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3121
3183
|
* .log();
|
|
3122
3184
|
* ```
|
|
3123
3185
|
*
|
|
3124
|
-
* | pathId | step | weight |
|
|
3125
|
-
* | ---: | ---: | ---: |
|
|
3126
|
-
* | 0 | 1 | 1 |
|
|
3127
|
-
* | 0 | 2 | 1 |
|
|
3186
|
+
* | pathId | step | weight | source | target | edgeId |
|
|
3187
|
+
* | ---: | ---: | ---: | --- | --- | --- |
|
|
3188
|
+
* | 0 | 1 | 1 | A | B | edge-0 |
|
|
3189
|
+
* | 0 | 2 | 1 | B | E | edge-1 |
|
|
3128
3190
|
*
|
|
3129
3191
|
* The next two examples each start with these flights. The direct flight
|
|
3130
3192
|
* takes ten minutes; the route through B and D takes three:
|
|
@@ -3164,9 +3226,9 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3164
3226
|
* .log();
|
|
3165
3227
|
* ```
|
|
3166
3228
|
*
|
|
3167
|
-
* | pathId | step | weight |
|
|
3168
|
-
* | ---: | ---: | ---: |
|
|
3169
|
-
* | 0 | 1 | 1 |
|
|
3229
|
+
* | pathId | step | weight | flightId | origin | destination | minutes |
|
|
3230
|
+
* | ---: | ---: | ---: | --- | --- | --- | ---: |
|
|
3231
|
+
* | 0 | 1 | 1 | F1 | A | E | 10 |
|
|
3170
3232
|
*
|
|
3171
3233
|
* With time options, the cheaper route through B is ruled out because F2
|
|
3172
3234
|
* leaves before F1 arrives. The route through C meets the one-hour minimum
|
|
@@ -3213,11 +3275,11 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3213
3275
|
* .log();
|
|
3214
3276
|
* ```
|
|
3215
3277
|
*
|
|
3216
|
-
* | pathId | step | weight |
|
|
3217
|
-
* | ---: | ---: | ---: |
|
|
3218
|
-
* | 0 | 1 | 1 |
|
|
3278
|
+
* | pathId | step | weight | edgeId | source | target |
|
|
3279
|
+
* | ---: | ---: | ---: | --- | --- | --- |
|
|
3280
|
+
* | 0 | 1 | 1 | F1 | A | B |
|
|
3219
3281
|
*
|
|
3220
|
-
* For the next
|
|
3282
|
+
* For the next three examples, `flights` contains these rows, with departure
|
|
3221
3283
|
* and arrival stored as timestamps on the same day:
|
|
3222
3284
|
*
|
|
3223
3285
|
* | flightId | origin | destination | departure | arrival | price |
|
|
@@ -3242,10 +3304,10 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3242
3304
|
* .log();
|
|
3243
3305
|
* ```
|
|
3244
3306
|
*
|
|
3245
|
-
* | pathId | step | weight |
|
|
3246
|
-
* | ---: | ---: | ---: | ---: |
|
|
3247
|
-
* | 0 | 1 | 1 |
|
|
3248
|
-
* | 0 | 2 | 1 |
|
|
3307
|
+
* | pathId | step | weight | elapsedTimeMs | flightId | origin | destination | departure | arrival | price |
|
|
3308
|
+
* | ---: | ---: | ---: | ---: | --- | --- | --- | --- | --- | ---: |
|
|
3309
|
+
* | 0 | 1 | 1 | 1800000 | F4 | A | D | 2025-01-01 09:00:00 | 2025-01-01 09:30:00 | 60 |
|
|
3310
|
+
* | 0 | 2 | 1 | 7200000 | F5 | D | C | 2025-01-01 10:30:00 | 2025-01-01 11:00:00 | 80 |
|
|
3249
3311
|
*
|
|
3250
3312
|
* The route through D takes two hours (7,200,000 milliseconds), including
|
|
3251
3313
|
* a one-hour layover. The direct flight takes three hours.
|
|
@@ -3274,6 +3336,27 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3274
3336
|
* Use `minimize: "weight"` to find the cheapest journey instead.
|
|
3275
3337
|
* All ties on the chosen metric are returned.
|
|
3276
3338
|
*
|
|
3339
|
+
* Choose the fewest flights while still reporting price and elapsed time.
|
|
3340
|
+
* The direct flight takes one step, although the route through D is faster:
|
|
3341
|
+
*
|
|
3342
|
+
* @example
|
|
3343
|
+
* ```ts
|
|
3344
|
+
* await flights
|
|
3345
|
+
* .shortestPath("origin", "destination", "flightId", "A", "C", {
|
|
3346
|
+
* startTimeColumn: "departure",
|
|
3347
|
+
* endTimeColumn: "arrival",
|
|
3348
|
+
* minGapMs: 60 * 60 * 1000,
|
|
3349
|
+
* elapsedTime: true,
|
|
3350
|
+
* weight: "price",
|
|
3351
|
+
* minimize: "steps",
|
|
3352
|
+
* })
|
|
3353
|
+
* .log();
|
|
3354
|
+
* ```
|
|
3355
|
+
*
|
|
3356
|
+
* | pathId | step | weight | total | elapsedTimeMs | flightId | origin | destination | departure | arrival | price |
|
|
3357
|
+
* | ---: | ---: | ---: | ---: | ---: | --- | --- | --- | --- | --- | ---: |
|
|
3358
|
+
* | 0 | 1 | 120 | 120 | 10800000 | F3 | A | C | 2025-01-01 09:00:00 | 2025-01-01 12:00:00 | 120 |
|
|
3359
|
+
*
|
|
3277
3360
|
* @param sourceColumn - The name of the column containing each connection's source node ID.
|
|
3278
3361
|
* @param targetColumn - The name of the column containing each connection's target node ID.
|
|
3279
3362
|
* @param edgeId - The name of the column uniquely identifying each connection (edge).
|
|
@@ -3285,11 +3368,11 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3285
3368
|
* @param options.endTimeColumn - The name of the column containing each connection's end time. Use this or `startTimeColumn` to follow connections in chronological order.
|
|
3286
3369
|
* @param options.minGapMs - The minimum gap between consecutive connections, in milliseconds. Must be a non-negative integer. Defaults to `0`. Requires a time column.
|
|
3287
3370
|
* @param options.strictOrdering - Whether to reject zero-duration gaps between consecutive connections (equal timestamps). Defaults to `true`. Requires a time column.
|
|
3288
|
-
* @param options.weight - The name of the numeric column used as the cost of each connection. If omitted,
|
|
3371
|
+
* @param options.weight - The name of the numeric column used as the cost of each connection. Adds `total`, the cumulative sum of those costs. If omitted, no `total` column is generated.
|
|
3289
3372
|
* @param options.elapsedTime - Whether to add cumulative `elapsedTimeMs` in milliseconds, including connection gaps. Defaults to `false`. Requires both time columns.
|
|
3290
|
-
* @param options.minimize - The metric used to select optimal routes
|
|
3373
|
+
* @param options.minimize - The metric used to select optimal routes: `"steps"`, `"weight"`, or `"elapsedTime"`. Defaults to `"weight"` when only `weight` is enabled, `"elapsedTime"` when only elapsed-time reporting is enabled, and `"steps"` when neither is enabled. Required when both are enabled. `"steps"` is always available; the other metrics require their corresponding options.
|
|
3291
3374
|
* @param options.outputTable - If `true`, stores the result in a new table with a generated name. If a string, uses it as the new table's name. If `false` or omitted, overwrites the current table. Defaults to `false`.
|
|
3292
|
-
* @returns The
|
|
3375
|
+
* @returns The table of route connections with optional cumulative `total` and `elapsedTimeMs` metrics, so methods can be chained.
|
|
3293
3376
|
* @category Graph Operations
|
|
3294
3377
|
*/
|
|
3295
3378
|
shortestPath(sourceColumn, targetColumn, edgeId, start, end, options = {}) {
|
|
@@ -4646,7 +4729,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4646
4729
|
* // Compare feature vectors and add a dataset-relative similarity score.
|
|
4647
4730
|
* await table
|
|
4648
4731
|
* .similarityMahalanobis("features", [175, 70], "distance", {
|
|
4649
|
-
*
|
|
4732
|
+
* similarityColumn: "similarity",
|
|
4650
4733
|
* })
|
|
4651
4734
|
* .log();
|
|
4652
4735
|
* ```
|
|
@@ -4657,7 +4740,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4657
4740
|
* const reference = await table.getRow("name === 'Alex'");
|
|
4658
4741
|
* await table
|
|
4659
4742
|
* .similarityMahalanobis(["height", "weight"], reference, "distance", {
|
|
4660
|
-
*
|
|
4743
|
+
* similarityColumn: true,
|
|
4661
4744
|
* })
|
|
4662
4745
|
* .log();
|
|
4663
4746
|
* ```
|
|
@@ -4665,7 +4748,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4665
4748
|
* @param referencePoint - An array of finite numbers in feature order, or an object with an own finite numeric value for each scalar feature column; may be outside the dataset.
|
|
4666
4749
|
* @param newColumn - The name of the new DOUBLE distance column.
|
|
4667
4750
|
* @param options - Optional output settings.
|
|
4668
|
-
* @param options.
|
|
4751
|
+
* @param options.similarityColumn - A custom name, or true for a new DOUBLE column named "similarity"; false or omitted adds no score. The dataset-relative
|
|
4669
4752
|
* score is `1 - distance / maxDistance`. Exact matches score 1 and the farthest
|
|
4670
4753
|
* rows score 0; if all distances are zero, every score is 1.
|
|
4671
4754
|
* @returns The table, so methods can be chained.
|
|
@@ -8,5 +8,5 @@ export type GraphTemporalCostStateSql = {
|
|
|
8
8
|
withClause: string;
|
|
9
9
|
};
|
|
10
10
|
/** Builds keyed best-cost chronological states from an arbitrary start relation. */
|
|
11
|
-
export default function buildGraphTemporalCostStateSql(prepared: PreparedGraphSql, startsSelect: string | ((validEdgesRelation: string) => string), direction: Exclude<GraphDirection, "both">, temporal: PreparedGraphTemporalSql, distanceType: string, edgeWeight: string, eventSelections?: string[]): GraphTemporalCostStateSql;
|
|
11
|
+
export default function buildGraphTemporalCostStateSql(prepared: PreparedGraphSql, startsSelect: string | ((validEdgesRelation: string) => string), direction: Exclude<GraphDirection, "both">, temporal: PreparedGraphTemporalSql, distanceType: string, edgeWeight: string, eventSelections?: string[], minimize?: "weight" | "steps"): GraphTemporalCostStateSql;
|
|
12
12
|
//# sourceMappingURL=buildGraphTemporalCostStateSql.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildGraphTemporalCostStateSql.d.ts","sourceRoot":"","sources":["../../src/helpers/buildGraphTemporalCostStateSql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAGpC,MAAM,MAAM,yBAAyB,GAAG;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,oFAAoF;AACpF,MAAM,CAAC,OAAO,UAAU,8BAA8B,CACpD,QAAQ,EAAE,gBAAgB,EAC1B,YAAY,EAAE,MAAM,GAAG,CAAC,CAAC,kBAAkB,EAAE,MAAM,KAAK,MAAM,CAAC,EAC/D,SAAS,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,EAC1C,QAAQ,EAAE,wBAAwB,EAClC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,eAAe,GAAE,MAAM,EAAO,
|
|
1
|
+
{"version":3,"file":"buildGraphTemporalCostStateSql.d.ts","sourceRoot":"","sources":["../../src/helpers/buildGraphTemporalCostStateSql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAGpC,MAAM,MAAM,yBAAyB,GAAG;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,oFAAoF;AACpF,MAAM,CAAC,OAAO,UAAU,8BAA8B,CACpD,QAAQ,EAAE,gBAAgB,EAC1B,YAAY,EAAE,MAAM,GAAG,CAAC,CAAC,kBAAkB,EAAE,MAAM,KAAK,MAAM,CAAC,EAC/D,SAAS,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,EAC1C,QAAQ,EAAE,wBAAwB,EAClC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,eAAe,GAAE,MAAM,EAAO,EAC9B,QAAQ,GAAE,QAAQ,GAAG,OAAkB,GACtC,yBAAyB,CAyG3B"}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = buildGraphTemporalCostStateSql;
|
|
7
7
|
const quoteIdentifier_js_1 = __importDefault(require("./quoteIdentifier.js"));
|
|
8
8
|
/** Builds keyed best-cost chronological states from an arbitrary start relation. */
|
|
9
|
-
function buildGraphTemporalCostStateSql(prepared, startsSelect, direction, temporal, distanceType, edgeWeight, eventSelections = []) {
|
|
9
|
+
function buildGraphTemporalCostStateSql(prepared, startsSelect, direction, temporal, distanceType, edgeWeight, eventSelections = [], minimize = "weight") {
|
|
10
10
|
const q = quoteIdentifier_js_1.default;
|
|
11
11
|
const relations = prepared.relationNames([
|
|
12
12
|
"graph_starts",
|
|
@@ -35,12 +35,26 @@ function buildGraphTemporalCostStateSql(prepared, startsSelect, direction, tempo
|
|
|
35
35
|
const edgeCost = `${q("edges")}.${q("__weight")}`;
|
|
36
36
|
const bestDistance = `${q("best")}.${q("distance")}`;
|
|
37
37
|
const gap = `${q("settings")}.${q("__gap")}`;
|
|
38
|
-
const
|
|
38
|
+
const candidateSteps = `${q("reached")}.${q("steps")} + 1`;
|
|
39
|
+
// A steps-only bound must not sum reported weights: discarded routes can
|
|
40
|
+
// overflow even when every optimal route's reported total is representable.
|
|
41
|
+
const firstDistance = minimize === "steps" ? "CAST(1 AS BIGINT)" : edgeCost;
|
|
42
|
+
const candidateDistance = minimize === "steps"
|
|
43
|
+
? candidateSteps
|
|
44
|
+
: `CAST(${reachedDistance} + ${edgeCost} AS ${distanceType})`;
|
|
45
|
+
const bestSteps = `${q("best")}.${q("steps")}`;
|
|
46
|
+
const order = (distance, steps) => minimize === "steps"
|
|
47
|
+
? `ROW(${steps}, ${distance})`
|
|
48
|
+
: `ROW(${distance}, ${steps})`;
|
|
49
|
+
const candidateOrder = order(candidateDistance, candidateSteps);
|
|
50
|
+
const selectedDistance = `arg_min(${candidateDistance}, ${candidateOrder})`;
|
|
51
|
+
const selectedSteps = `arg_min(${candidateSteps}, ${candidateOrder})`;
|
|
39
52
|
const resolvedStartsSelect = typeof startsSelect === "string"
|
|
40
53
|
? startsSelect
|
|
41
54
|
: startsSelect(edgesRelation);
|
|
42
|
-
// Only
|
|
43
|
-
//
|
|
55
|
+
// Only states for the same start and physical event can dominate each other.
|
|
56
|
+
// Weight optimization orders by cost then steps; step optimization counts
|
|
57
|
+
// only connections. Strict improvements terminate even zero-cost cycles.
|
|
44
58
|
return {
|
|
45
59
|
costRelation,
|
|
46
60
|
edgesRelation,
|
|
@@ -64,17 +78,17 @@ function buildGraphTemporalCostStateSql(prepared, startsSelect, direction, tempo
|
|
|
64
78
|
${q("start")}, ${q("node")},
|
|
65
79
|
${q("__start_key")}, ${q("__node_key")},
|
|
66
80
|
${q("__event_id")}, ${q("__event_start")}, ${q("__event_end")},
|
|
67
|
-
${q("distance")}
|
|
81
|
+
${q("distance")}, ${q("steps")}
|
|
68
82
|
) USING KEY(${q("__start_key")}, ${q("__event_id")}) AS (
|
|
69
83
|
SELECT ${start}, ${edgeTo}, ${startKey}, ${edgeToKey},
|
|
70
|
-
${eventId}, ${eventStart}, ${eventEnd}, ${
|
|
84
|
+
${eventId}, ${eventStart}, ${eventEnd}, ${firstDistance}, CAST(1 AS BIGINT)
|
|
71
85
|
FROM ${startsRelation} AS ${q("starts")}
|
|
72
86
|
INNER JOIN ${edgesRelation} AS ${q("edges")}
|
|
73
87
|
ON ${startKey} = ${edgeFromKey}
|
|
74
88
|
UNION
|
|
75
89
|
SELECT ${reachedStart}, ${edgeTo}, ${reachedStartKey}, ${edgeToKey},
|
|
76
90
|
${eventId}, ${eventStart}, ${eventEnd},
|
|
77
|
-
|
|
91
|
+
${selectedDistance} AS ${q("distance")}, ${selectedSteps} AS ${q("steps")}
|
|
78
92
|
FROM ${costRelation} AS ${q("reached")}
|
|
79
93
|
INNER JOIN ${edgesRelation} AS ${q("edges")}
|
|
80
94
|
ON ${reachedNodeKey} = ${edgeFromKey}
|
|
@@ -84,9 +98,9 @@ function buildGraphTemporalCostStateSql(prepared, startsSelect, direction, tempo
|
|
|
84
98
|
AND ${eventId} = ${q("best")}.${q("__event_id")}
|
|
85
99
|
WHERE ${temporal.transition("reached", "edges", direction, gap)}
|
|
86
100
|
GROUP BY ${reachedStart}, ${edgeTo}, ${reachedStartKey}, ${edgeToKey},
|
|
87
|
-
${eventId}, ${eventStart}, ${eventEnd}, ${bestDistance}
|
|
101
|
+
${eventId}, ${eventStart}, ${eventEnd}, ${bestDistance}, ${bestSteps}
|
|
88
102
|
HAVING ${bestDistance} IS NULL OR
|
|
89
|
-
|
|
103
|
+
${order(selectedDistance, selectedSteps)} < ${order(bestDistance, bestSteps)}
|
|
90
104
|
)`,
|
|
91
105
|
};
|
|
92
106
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { TableSchema } from "./pendingOps.js";
|
|
2
2
|
/** Derives the route result schema while preserving input columns and types. */
|
|
3
|
-
export default function graphRouteResultSchema(schema: TableSchema, distanceType: string, method: string, elapsedTime?: boolean): TableSchema;
|
|
3
|
+
export default function graphRouteResultSchema(schema: TableSchema, distanceType: string, method: string, elapsedTime?: boolean, includeTotal?: boolean): TableSchema;
|
|
4
4
|
//# sourceMappingURL=graphRouteResultSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphRouteResultSchema.d.ts","sourceRoot":"","sources":["../../src/helpers/graphRouteResultSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,gFAAgF;AAChF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,WAAW,UAAQ,GAClB,WAAW,
|
|
1
|
+
{"version":3,"file":"graphRouteResultSchema.d.ts","sourceRoot":"","sources":["../../src/helpers/graphRouteResultSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,gFAAgF;AAChF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,WAAW,UAAQ,EACnB,YAAY,UAAO,GAClB,WAAW,CAeb"}
|
|
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = graphRouteResultSchema;
|
|
7
7
|
const validateGraphRouteResultSchema_js_1 = __importDefault(require("./validateGraphRouteResultSchema.js"));
|
|
8
8
|
/** Derives the route result schema while preserving input columns and types. */
|
|
9
|
-
function graphRouteResultSchema(schema, distanceType, method, elapsedTime = false) {
|
|
10
|
-
(0, validateGraphRouteResultSchema_js_1.default)(schema, method, elapsedTime ? ["elapsedTimeMs"] : []);
|
|
9
|
+
function graphRouteResultSchema(schema, distanceType, method, elapsedTime = false, includeTotal = true) {
|
|
10
|
+
(0, validateGraphRouteResultSchema_js_1.default)(schema, method, elapsedTime ? ["elapsedTimeMs"] : [], includeTotal);
|
|
11
11
|
return {
|
|
12
12
|
pathId: "BIGINT",
|
|
13
13
|
step: "BIGINT",
|
|
14
14
|
weight: distanceType,
|
|
15
|
-
total: distanceType,
|
|
15
|
+
...(includeTotal ? { total: distanceType } : {}),
|
|
16
16
|
...(elapsedTime ? { elapsedTimeMs: "DOUBLE" } : {}),
|
|
17
17
|
...schema,
|
|
18
18
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { GraphEdgeIdColumn } from "./getGraphEdgeIdColumn.js";
|
|
2
2
|
/** Joins ranked route steps to their original input rows for final output. */
|
|
3
|
-
export default function graphRouteResultSelect(rankedRelation: string, input: string, edgeIdColumn: GraphEdgeIdColumn, includeStart?: boolean, elapsedTime?: boolean): string;
|
|
3
|
+
export default function graphRouteResultSelect(rankedRelation: string, input: string, edgeIdColumn: GraphEdgeIdColumn, includeStart?: boolean, elapsedTime?: boolean, includeTotal?: boolean): string;
|
|
4
4
|
//# sourceMappingURL=graphRouteResultSelect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphRouteResultSelect.d.ts","sourceRoot":"","sources":["../../src/helpers/graphRouteResultSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,8EAA8E;AAC9E,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,iBAAiB,EAC/B,YAAY,UAAQ,EACpB,WAAW,UAAQ,GAClB,MAAM,CA8BR"}
|
|
1
|
+
{"version":3,"file":"graphRouteResultSelect.d.ts","sourceRoot":"","sources":["../../src/helpers/graphRouteResultSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,8EAA8E;AAC9E,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,iBAAiB,EAC/B,YAAY,UAAQ,EACpB,WAAW,UAAQ,EACnB,YAAY,UAAO,GAClB,MAAM,CA8BR"}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = graphRouteResultSelect;
|
|
7
7
|
const quoteIdentifier_js_1 = __importDefault(require("./quoteIdentifier.js"));
|
|
8
8
|
/** Joins ranked route steps to their original input rows for final output. */
|
|
9
|
-
function graphRouteResultSelect(rankedRelation, input, edgeIdColumn, includeStart = false, elapsedTime = false) {
|
|
9
|
+
function graphRouteResultSelect(rankedRelation, input, edgeIdColumn, includeStart = false, elapsedTime = false, includeTotal = true) {
|
|
10
10
|
const q = quoteIdentifier_js_1.default;
|
|
11
11
|
const routeStep = `${q("unnested")}.${q("route_step")}`;
|
|
12
12
|
const originalEdgeId = `${q("original")}.${q(edgeIdColumn.column)}`;
|
|
@@ -18,7 +18,7 @@ function graphRouteResultSelect(rankedRelation, input, edgeIdColumn, includeStar
|
|
|
18
18
|
return `SELECT ${includeStart ? `${q("ranked")}.${q("start")},\n ` : ""}${q("ranked")}.${q("pathId")},
|
|
19
19
|
CAST(${q("unnested")}.${q("step")} AS BIGINT) AS ${q("step")},
|
|
20
20
|
${routeStep}.${q("weight")} AS ${q("weight")},
|
|
21
|
-
${routeStep}.${q("distance")} AS ${q("total")}
|
|
21
|
+
${includeTotal ? `${routeStep}.${q("distance")} AS ${q("total")},` : ""}
|
|
22
22
|
${elapsedTime
|
|
23
23
|
? `${routeStep}.${q("elapsedTimeMs")} AS ${q("elapsedTimeMs")},`
|
|
24
24
|
: ""}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export type GraphMetricOptions = {
|
|
2
2
|
elapsedTime?: boolean;
|
|
3
|
-
minimize?: "weight" | "elapsedTime";
|
|
3
|
+
minimize?: "steps" | "weight" | "elapsedTime";
|
|
4
4
|
weight?: string;
|
|
5
5
|
startTimeColumn?: string;
|
|
6
6
|
endTimeColumn?: string;
|
|
7
7
|
};
|
|
8
8
|
export type PreparedGraphMetricOptions = {
|
|
9
9
|
elapsedTime: boolean;
|
|
10
|
-
minimize: "
|
|
10
|
+
minimize: "steps" | "weight" | "elapsedTime";
|
|
11
11
|
};
|
|
12
12
|
/** Resolves graph cost selection separately from optional elapsed-time reporting. */
|
|
13
13
|
export default function prepareGraphMetricOptions(options: GraphMetricOptions, method: string, optimize: boolean): PreparedGraphMetricOptions;
|