@@ -77,7 +77,7 @@ let get_url token dynamic_url static_url id =
77
77
| Some _ -> dynamic_url ^ Url. urlencode id ^ " /"
78
78
| None -> api_server ^ " /" ^ static_url ^ Url. urlencode id
79
79
80
- type exercise_ordering = By_category | By_prereq | By_difficulty
80
+ type exercise_ordering = By_category | By_skill | By_difficulty
81
81
82
82
let (exercise_filter_signal: string option React.signal ), set_exercise_filter =
83
83
React.S. create None
@@ -90,14 +90,34 @@ let make_exercises_to_display_signal index =
90
90
let index =
91
91
match exo_sort with
92
92
| By_category -> index
93
- | By_prereq ->
94
- Exercise.Index. Exercises
95
- Exercise.Graph. (compute_graph index |>
96
- fold (fun acc node ->
97
- let id = node_exercise node in
98
- (id, Some (Exercise.Index. find index id)) :: acc
99
- ) [] |>
100
- List. rev)
93
+ | By_skill ->
94
+ let module StrMap = Map. Make (struct
95
+ type t = string
96
+ (* Case-insensitive ordering *)
97
+ let compare a b =
98
+ String. (compare (lowercase_ascii a) (lowercase_ascii b))
99
+ end )
100
+ in
101
+ let by_skill =
102
+ Exercise.Index. fold_exercises (fun map id meta ->
103
+ List. fold_left (fun acc skill ->
104
+ StrMap. update skill
105
+ (function None -> Some [id, Some meta]
106
+ | Some l -> Some ((id, Some meta) :: l))
107
+ acc)
108
+ map
109
+ meta.Exercise.Meta. focus)
110
+ StrMap. empty index
111
+ in
112
+ let groups =
113
+ StrMap. fold (fun skill exercises acc ->
114
+ (skill,
115
+ {Exercise.Index. title = skill;
116
+ contents = Exercise.Index. Exercises (List. rev exercises)})
117
+ :: acc)
118
+ by_skill []
119
+ in
120
+ Exercise.Index. Groups (List. rev groups)
101
121
| By_difficulty ->
102
122
let module IntMap = Map. Make (Int ) in
103
123
let starmap =
@@ -259,7 +279,7 @@ let exercises_tab token : tab_handler =
259
279
btn, signal)
260
280
[
261
281
" by_category" , By_category , [% i" By category" ];
262
- " by_prereq " , By_prereq , [% i" By prerequisites " ];
282
+ " by_skill " , By_skill , [% i" By skill " ];
263
283
" by_difficulty" , By_difficulty , [% i" By difficulty" ];
264
284
]
265
285
in
0 commit comments