File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,21 @@ let result items =
109109 let (n, b) = do_report items in
110110 (max n 0 , b)
111111
112+ let rec scale ?(penalties = true ) factor items =
113+ List. map (scale_item penalties factor) items
114+ and scale_item penalties factor = function
115+ | Section (text , report ) ->
116+ Section (text, scale ~penalties factor report)
117+ | SectionMin (text , report , min ) ->
118+ SectionMin (text,
119+ scale ~penalties factor report,
120+ if penalties then factor * min else min)
121+ | Message (text , Success n ) ->
122+ Message (text, Success (factor * n))
123+ | Message (text , Penalty n ) when penalties ->
124+ Message (text, Penalty (factor * n))
125+ | item -> item
126+
112127let enc =
113128 let open Json_encoding in
114129 let text_enc =
Original file line number Diff line number Diff line change @@ -34,6 +34,13 @@ and inline =
3434(* * Gets the total successes of a report, and tells if a failure happened *)
3535val result : t -> int * bool
3636
37+ (* * Scales all of the point values of the items in a report by an integer
38+ factor. Useful for weighting different components of an exercise.
39+ If [penalties] ([true] by default), scales the values of [Penalty]
40+ items and the minimum values for [SectionMin], otherwise leaves them
41+ untouched. *)
42+ val scale : ?penalties : bool -> int -> t -> t
43+
3744(* * Gets a report as HTML in a string
3845 (if [not bare] add a container div and inline style) *)
3946val to_html : ?bare : bool -> t -> string
Original file line number Diff line number Diff line change @@ -461,6 +461,8 @@ module type S = sig
461461 end
462462
463463 val (@@@ ) : ('a -> Learnocaml_report.t ) -> ('a -> Learnocaml_report. t) -> ('a -> Learnocaml_report. t)
464+ val (@@> ) : Learnocaml_report. t -> (unit -> Learnocaml_report. t) -> Learnocaml_report. t
465+ val (@@= ) : Learnocaml_report. t -> (unit -> Learnocaml_report. t) -> Learnocaml_report. t
464466
465467 (* */**)
466468 include (module type of Ast_checker )
@@ -1883,6 +1885,9 @@ module Make
18831885 end
18841886
18851887 let (@@@) f g = fun x -> f x @ g x
1888+ let (@@>) r1 f = if snd (Learnocaml_report. result r1) then r1 else f ()
1889+ let (@@=) r1 f = if snd (Learnocaml_report. result r1) then r1 else r1 @ f ()
1890+
18861891 (* */**)
18871892 include Ast_checker
18881893 include Tester
Original file line number Diff line number Diff line change @@ -1243,6 +1243,22 @@ module type S = sig
12431243 -> ('a -> Learnocaml_report. t)
12441244 -> ('a -> Learnocaml_report. t)
12451245
1246+ (* * [r1 @@> f] returns [r1] if [r1] is a failure report,
1247+ otherwise returns the result of report generator
1248+ [f ()]. *)
1249+ val (@@> ) :
1250+ Learnocaml_report. t
1251+ -> (unit -> Learnocaml_report. t)
1252+ -> Learnocaml_report. t
1253+
1254+ (* * [r1 @@= f] returns [r1] if [r1] is a failure report,
1255+ otherwise concatenates [r1] to the result of report
1256+ generator [f ()]. *)
1257+ val (@@= ) :
1258+ Learnocaml_report. t
1259+ -> (unit -> Learnocaml_report. t)
1260+ -> Learnocaml_report. t
1261+
12461262 (* */**)
12471263 include (module type of Ast_checker )
12481264 include (module type of Tester )
You can’t perform that action at this time.
0 commit comments