projects
/
climbing.kerkeslager.com
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2db9b40
)
Refactor calculation of route grade
author
David Kerkeslager
<kerkeslager@gmail.com>
Fri, 4 Mar 2022 19:06:13 +0000
(14:06 -0500)
committer
David Kerkeslager
<kerkeslager@gmail.com>
Fri, 4 Mar 2022 19:06:13 +0000
(14:06 -0500)
src/climbing/models.py
patch
|
blob
|
history
diff --git
a/src/climbing/models.py
b/src/climbing/models.py
index
dd2493c
..
dc1396a
100644
(file)
--- a/
src/climbing/models.py
+++ b/
src/climbing/models.py
@@
-61,12
+61,11
@@
class Route(models.Model):
diff_index = -1
for pitch in self.pitches.all():
diff_index = -1
for pitch in self.pitches.all():
- for index, diff_choice in enumerate(ROUTE_DIFFICULTY_CHOICES):
- if pitch.difficulty == diff_choice[0]:
- if diff_index < index:
- diff = pitch.difficulty
- diff_index = index
- break
+ p_diff_index = _route_difficulty_index(pitch.difficulty)
+
+ if p_diff_index > diff_index:
+ diff_index = p_diff_index
+ diff = pitch.difficulty
return diff
return diff
@@
-112,6
+111,12
@@
ROUTE_DIFFICULTY_CHOICES = (
('5.15d', '5.15d'),
)
('5.15d', '5.15d'),
)
+def _route_difficulty_index(difficulty):
+ for i, d in enumerate(ROUTE_DIFFICULTY_CHOICES):
+ if difficulty == d[0]:
+ return i
+ return -1
+
SAFETY_CHOICES = (
('G', 'G'),
('PG', 'PG'),
SAFETY_CHOICES = (
('G', 'G'),
('PG', 'PG'),