3
3
https://github.com/russellporter/openskidata-format
4
4
"""
5
5
6
+ from dataclasses import dataclass
6
7
from enum import StrEnum
7
8
from typing import Annotated , Literal
8
9
@@ -36,6 +37,36 @@ class SkiRunConvention(StrEnum):
36
37
japan = "japan"
37
38
38
39
40
+ @dataclass
41
+ class _SkiRunColors :
42
+ green : str
43
+ blue : str
44
+ red : str
45
+ black : str
46
+ orange : str
47
+ gray : str
48
+
49
+
50
+ # from https://github.com/russellporter/openskidata-format/blob/e421ef0a0814437c362611e07cb43c32bac4172c/src/Run.ts#L87-L92
51
+ ski_run_colors_bright = _SkiRunColors (
52
+ green = "#00a80e" ,
53
+ blue = "#005aa8" ,
54
+ red = "#f8161a" ,
55
+ black = "#000000" ,
56
+ orange = "#ff9100" ,
57
+ gray = "#595959" ,
58
+ )
59
+
60
+ ski_run_colors_subtle = _SkiRunColors (
61
+ green = "#badbb8" ,
62
+ blue = "#a1a1d8" ,
63
+ red = "#ff8c8e" ,
64
+ black = "#828282" ,
65
+ orange = "#e5c47e" ,
66
+ gray = "#d9d9d9" ,
67
+ )
68
+
69
+
39
70
class SkiRunDifficulty (StrEnum ):
40
71
"""
41
72
https://wiki.openstreetmap.org/wiki/Key:piste:difficulty
@@ -76,35 +107,53 @@ def condensed_values(cls) -> "list[SkiRunDifficulty]":
76
107
77
108
@classmethod
78
109
def colormap (
79
- cls , condense : bool = False , subtle : bool = True
110
+ cls ,
111
+ condense : bool = False ,
112
+ subtle : bool = True ,
113
+ convention : SkiRunConvention = SkiRunConvention .north_america ,
80
114
) -> "dict[SkiRunDifficulty, str]" :
81
115
"""
82
- Difficulty to color mapping based on North American conventions.
83
- https://www.nsaa.org/NSAA/Safety/Trail_Signage/NSAA/Safety/Trail_Signage.aspx
116
+ Difficulty to color mapping according to the local convention.
117
+ See:
118
+ <https://github.com/russellporter/openskidata-format/blob/e421ef0a0814437c362611e07cb43c32bac4172c/src/Run.ts#L113-L166>
119
+ <https://www.nsaa.org/NSAA/Safety/Trail_Signage/NSAA/Safety/Trail_Signage.aspx>
84
120
"""
85
- colormap = (
86
- {
87
- cls .novice : "#badbb8" ,
88
- cls .easy : "#badbb8" ,
89
- cls .intermediate : "#a1a1d8" ,
90
- cls .advanced : "#828282" ,
91
- cls .expert : "#828282" ,
92
- cls .extreme : "#828282" ,
93
- cls .freeride : "#828282" , # considered "#e5c47e"
94
- cls .other : "#d9d9d9" ,
121
+ colors = ski_run_colors_subtle if subtle else ski_run_colors_bright
122
+ if convention == SkiRunConvention .north_america :
123
+ colormap = {
124
+ cls .novice : colors .green ,
125
+ cls .easy : colors .green ,
126
+ cls .intermediate : colors .blue ,
127
+ cls .advanced : colors .black ,
128
+ cls .expert : colors .black ,
129
+ cls .extreme : colors .orange ,
130
+ cls .freeride : colors .orange ,
131
+ cls .other : colors .gray ,
132
+ }
133
+ elif convention == SkiRunConvention .europe :
134
+ colormap = {
135
+ cls .novice : colors .green ,
136
+ cls .easy : colors .blue ,
137
+ cls .intermediate : colors .red ,
138
+ cls .advanced : colors .black ,
139
+ cls .expert : colors .black ,
140
+ cls .extreme : colors .orange ,
141
+ cls .freeride : colors .orange ,
142
+ cls .other : colors .gray ,
95
143
}
96
- if subtle
97
- else {
98
- cls .novice : "#60A45C" ,
99
- cls .easy : "#60A45C" ,
100
- cls .intermediate : "#3E7DBF" ,
101
- cls .advanced : "#000000" ,
102
- cls .expert : "#000000" ,
103
- cls .extreme : "#000000" ,
104
- cls .freeride : "#000000" , # considered "#DEB251"
105
- cls .other : "#bfbfbf" ,
144
+ elif convention == SkiRunConvention . japan :
145
+ colormap = {
146
+ cls .novice : colors . green ,
147
+ cls .easy : colors . green ,
148
+ cls .intermediate : colors . red ,
149
+ cls .advanced : colors . black ,
150
+ cls .expert : colors . black ,
151
+ cls .extreme : colors . orange ,
152
+ cls .freeride : colors . orange ,
153
+ cls .other : colors . gray ,
106
154
}
107
- )
155
+ else :
156
+ raise ValueError (f"Unsupported run coloring convention: { convention } " )
108
157
if condense :
109
158
colormap = {
110
159
key : value
@@ -113,9 +162,13 @@ def colormap(
113
162
}
114
163
return colormap
115
164
116
- def color (self , subtle : bool = False ) -> str :
165
+ def color (
166
+ self ,
167
+ subtle : bool = True ,
168
+ convention : SkiRunConvention = SkiRunConvention .north_america ,
169
+ ) -> str :
117
170
"""Get the color for the difficulty level."""
118
- return self .colormap (subtle = subtle )[self ]
171
+ return self .colormap (subtle = subtle , convention = convention )[self ]
119
172
120
173
@classmethod
121
174
def markdown_description (cls , mode : Literal ["phrase" , "list" ] = "phrase" ) -> str :
0 commit comments