openskidata-format 5.2.0 → 5.3.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/dist/Run.d.ts +1 -31
- package/dist/Run.js +5 -36
- package/dist/Run.js.map +1 -1
- package/dist/RunDifficultyConvention.d.ts +42 -0
- package/dist/RunDifficultyConvention.js +333 -0
- package/dist/RunDifficultyConvention.js.map +1 -0
- package/dist/SkiArea.d.ts +2 -1
- package/dist/SkiArea.js.map +1 -1
- package/dist/SlopeGradingScale.d.ts +32 -0
- package/dist/SlopeGradingScale.js +54 -0
- package/dist/SlopeGradingScale.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
- package/src/ElevationProfile.test.ts +1 -1
- package/src/Run.ts +1 -33
- package/src/RunDifficultyConvention.test.ts +79 -0
- package/src/RunDifficultyConvention.ts +335 -0
- package/src/SkiArea.ts +2 -1
- package/src/SlopeGradingScale.test.ts +129 -0
- package/src/SlopeGradingScale.ts +66 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { RunDifficulty, RunFeature, RunUse } from "./Run";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a slope grading scale with steepness thresholds for different run types.
|
|
5
|
+
* Used to estimate run difficulty based on slope steepness. Each scale defines
|
|
6
|
+
* threshold points where the difficulty classification changes based on gradient.
|
|
7
|
+
*/
|
|
8
|
+
export type SlopeGradingScale = {
|
|
9
|
+
/** Stops must be ordered ascending by steepness */
|
|
10
|
+
stops: { maxSteepness: number; difficulty: RunDifficulty | null }[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Gets the appropriate slope grading scale for a run based on its use types.
|
|
15
|
+
* Different run uses (downhill, nordic, etc.) have different steepness thresholds
|
|
16
|
+
* for difficulty classification due to the nature of the activity and equipment used.
|
|
17
|
+
*
|
|
18
|
+
* @param feature - The run feature to get the grading scale for
|
|
19
|
+
* @returns The appropriate slope grading scale with steepness thresholds
|
|
20
|
+
*/
|
|
21
|
+
export function getSlopeGradingScale(feature: RunFeature): SlopeGradingScale {
|
|
22
|
+
if (
|
|
23
|
+
feature.properties.uses.includes(RunUse.Downhill) ||
|
|
24
|
+
feature.properties.uses.includes(RunUse.Skitour)
|
|
25
|
+
) {
|
|
26
|
+
return {
|
|
27
|
+
stops: [
|
|
28
|
+
{ maxSteepness: 0.05, difficulty: null }, // No difficulty below 5%
|
|
29
|
+
{ maxSteepness: 0.25, difficulty: RunDifficulty.EASY },
|
|
30
|
+
{ maxSteepness: 0.4, difficulty: RunDifficulty.INTERMEDIATE },
|
|
31
|
+
{ maxSteepness: 0.8, difficulty: RunDifficulty.ADVANCED }, // Advanced up to 80%
|
|
32
|
+
{ maxSteepness: 1.2, difficulty: RunDifficulty.EXPERT }, // Expert up to 120%
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
} else if (feature.properties.uses.includes(RunUse.Nordic)) {
|
|
36
|
+
return {
|
|
37
|
+
stops: [
|
|
38
|
+
{ maxSteepness: 0.1, difficulty: RunDifficulty.EASY },
|
|
39
|
+
{ maxSteepness: 0.15, difficulty: RunDifficulty.INTERMEDIATE },
|
|
40
|
+
{ maxSteepness: 0.3, difficulty: RunDifficulty.ADVANCED },
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
return { stops: [] };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Estimates the run difficulty based on steepness and the provided slope grading scale.
|
|
50
|
+
* Uses the absolute value of steepness to handle both uphill and downhill slopes.
|
|
51
|
+
* Finds the first threshold that the steepness falls under.
|
|
52
|
+
*
|
|
53
|
+
* @param steepness - The steepness value (slope gradient as a decimal, e.g., 0.1 = 10%)
|
|
54
|
+
* @param scale - The slope grading scale with steepness thresholds
|
|
55
|
+
* @returns The estimated difficulty based on steepness, or null if no match or below minimum threshold
|
|
56
|
+
*/
|
|
57
|
+
export function getEstimatedRunDifficulty(
|
|
58
|
+
steepness: number,
|
|
59
|
+
scale: SlopeGradingScale
|
|
60
|
+
): RunDifficulty | null {
|
|
61
|
+
const absoluteSteepness = Math.abs(steepness);
|
|
62
|
+
return (
|
|
63
|
+
scale.stops.find((stop) => stop.maxSteepness > absoluteSteepness)
|
|
64
|
+
?.difficulty || null
|
|
65
|
+
);
|
|
66
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ export * from './Lift'
|
|
|
4
4
|
export * from './LiftNameFormatter'
|
|
5
5
|
export * from './Location'
|
|
6
6
|
export * from './Run'
|
|
7
|
+
export * from './RunDifficultyConvention'
|
|
8
|
+
export * from './SlopeGradingScale'
|
|
7
9
|
export * from './SkiArea'
|
|
8
10
|
export * from './SnowCoverHistory'
|
|
9
11
|
export * from './Source'
|