Skip to content

Commit

Permalink
fix(teacher_tab): Display (Open/Close)GloballyInconsistent exos and f…
Browse files Browse the repository at this point in the history
…ix them

* Refactor the Learnocaml_data.Exercise.Status.global_status variant to do so.
  • Loading branch information
erikmd committed Sep 10, 2023
1 parent 3a0ceb4 commit 10c9fc3
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 41 deletions.
4 changes: 3 additions & 1 deletion src/app/learnocaml_teacher_tab.ml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ let rec teacher_tab token _select _params () =
| GloballyOpenOrAssigned -> "exo_assigned", [%i"Open/Assigned"]
| GloballyClosedOrAssigned -> "exo_assigned", [%i"Assigned"]
| GloballyClosed -> "exo_closed", [%i"Closed"]
| GloballyInconsistent -> "exo_closed", [%i"Inconsistent"]
in
H.span ~a:[H.a_class [cls]] [H.txt text]
];
Expand Down Expand Up @@ -857,7 +858,8 @@ let rec teacher_tab token _select _params () =
if List.exists (fun id ->
let st = get_status id in
let open_assg = ES.is_open_or_assigned_globally st.ES.assignments in
open_assg = ES.GloballyOpen || open_assg = ES.GloballyOpenOrAssigned)
open_assg = ES.GloballyOpen || open_assg = ES.GloballyOpenOrAssigned
|| open_assg = ES.GloballyInconsistent)
ids
then ES.set_close_or_assigned_globally
else ES.set_open_or_assigned_globally
Expand Down
66 changes: 48 additions & 18 deletions src/state/learnocaml_data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ module Exercise = struct
| GloballyClosed (** "Closed" *)
| GloballyOpenOrAssigned (** "Open/Assigned" *)
| GloballyClosedOrAssigned (** "Assigned" *)
| GloballyInconsistent (** "Inconsistent" *)

let check_open_close a =
match a.default with
Expand All @@ -546,33 +547,60 @@ module Exercise = struct
c && st <> Open)) a.token_map (true, true) in
o || c

let fix_open_close a =
let mp =
Token.Map.map (function Open -> Closed | st -> st) a.token_map in
match a.default with
| Open | Closed ->
make_assignments mp Closed
| assg ->
make_assignments mp assg
let fix_open_close ?(close=true) a =
if close then
let mp =
Token.Map.map (function Open -> Closed | st -> st) a.token_map in
match a.default with
| Open | Closed ->
make_assignments mp Closed
| assg ->
make_assignments mp assg
else
let mp =
Token.Map.map (function Closed -> Open | st -> st) a.token_map in
match a.default with
| Open | Closed ->
make_assignments mp Open
| assg ->
make_assignments mp assg

let check_and_fix_open_close a =
if check_open_close a then a
else fix_open_close a

let is_open_or_assigned_globally a =
match a.default with
| Assigned _ ->
let o, c =
Token.Map.fold (fun _tok st (o, c) ->
(o || st = Open,
c || st = Closed)) a.token_map (false, false) in
begin match o, c with
| true, true -> GloballyInconsistent
| true, false -> GloballyOpenOrAssigned
| false, _ -> GloballyClosedOrAssigned
end
| Open ->
if Token.Map.exists (fun _tok -> function Assigned _ -> true | _ -> false) a.token_map
then GloballyOpenOrAssigned
else GloballyOpen
let d, c =
Token.Map.fold (fun _tok st (d, c) ->
(d || (match st with Assigned _ -> true | _ -> false),
c || st = Closed)) a.token_map (false, false) in
begin match d, c with
| _, true -> GloballyInconsistent
| true, false -> GloballyOpenOrAssigned
| false, false -> GloballyOpen
end
| Closed ->
if Token.Map.exists (fun _tok -> function Assigned _ -> true | _ -> false) a.token_map
then GloballyClosedOrAssigned
else GloballyClosed
| Assigned _ ->
if Token.Map.exists (fun _tok -> (=) Open) a.token_map
then GloballyOpenOrAssigned
else GloballyClosedOrAssigned
let d, o =
Token.Map.fold (fun _tok st (d, o) ->
(d || (match st with Assigned _ -> true | _ -> false),
o || st = Open)) a.token_map (false, false) in
begin match d, o with
| _, true -> GloballyInconsistent
| true, false -> GloballyClosedOrAssigned
| false, false -> GloballyClosed
end

let set_close_or_assigned_globally a =
match is_open_or_assigned_globally a with
Expand All @@ -584,6 +612,7 @@ module Exercise = struct
(* otherwise, maybe: forget the map and re-add all tokens ? *)
| GloballyClosedOrAssigned -> a
| GloballyClosed -> a
| GloballyInconsistent -> fix_open_close ~close:true a

let set_open_or_assigned_globally a =
match is_open_or_assigned_globally a with
Expand All @@ -595,6 +624,7 @@ module Exercise = struct
(* otherwise, maybe: forget the map and re-add all tokens ? *)
| GloballyOpenOrAssigned -> a
| GloballyOpen -> a
| GloballyInconsistent -> fix_open_close ~close:false a

(* Note/Erik: we may also want to implement set_assigned_globally *)

Expand Down
5 changes: 3 additions & 2 deletions src/state/learnocaml_data.mli
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ module Exercise: sig
| GloballyClosed (** "Closed" *)
| GloballyOpenOrAssigned (** "Open/Assigned" *)
| GloballyClosedOrAssigned (** "Assigned" *)
| GloballyInconsistent (** "Inconsistent" *)

val is_open_or_assigned_globally: assignments -> global_status

Expand All @@ -244,8 +245,8 @@ module Exercise: sig
Return false if there are at least one Open and at least one Closed. *)
val check_open_close: assignments -> bool

(** Replace all Open with Closed. *)
val fix_open_close: assignments -> assignments
(** Replace all Open with Closed (or conversly if close=false). *)
val fix_open_close: ?close:bool -> assignments -> assignments

(** Call [check_open_close] then (if need be) [fix_open_close] *)
val check_and_fix_open_close: assignments -> assignments
Expand Down
8 changes: 6 additions & 2 deletions src/state/learnocaml_data_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let%test_module _ =
| GloballyClosed -> "GloballyClosed"
| GloballyOpenOrAssigned -> "GloballyOpenOrAssigned"
| GloballyClosedOrAssigned -> "GloballyClosedOrAssigned"
| GloballyInconsistent -> "GloballyInconsistent"

let testdata_map_of list =
List.fold_right (fun (tok, st) res -> Token.Map.add tok st res) list Token.Map.empty
Expand Down Expand Up @@ -62,7 +63,7 @@ let%test_module _ =
List.iter (fun glob -> Printf.printf "%s\n"
@@ testdata_str_of_globalstatus
@@ is_open_or_assigned_globally glob)
testdata_good_assignments;
(testdata_good_assignments @ testdata_wrong_assignments);
[%expect{|
GloballyOpen
GloballyClosed
Expand All @@ -73,7 +74,10 @@ let%test_module _ =
GloballyClosedOrAssigned
GloballyOpen
GloballyClosed
GloballyClosedOrAssigned |}]
GloballyClosedOrAssigned
GloballyInconsistent
GloballyInconsistent
GloballyInconsistent |}]

let%test "check_open_close/good" =
List.for_all check_open_close testdata_good_assignments
Expand Down
40 changes: 22 additions & 18 deletions translations/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: learn-ocaml ~dev\n"
"PO-Revision-Date: 2023-08-25 12:59+0200\n"
"PO-Revision-Date: 2023-08-28 09:10+0200\n"
"Last-Translator: Erik Martin-Dorel <erik.martin-dorel@irit.fr>\n"
"Language-Team: OCSF\n"
"Language: french\n"
Expand Down Expand Up @@ -599,21 +599,25 @@ msgstr ""
"\n"
"Notez-le !"

#: File "src/app/learnocaml_teacher_tab.ml", line 304, characters 52-58
#: File "src/app/learnocaml_teacher_tab.ml", line 304, characters 51-57
msgid "Open"
msgstr "Ouvert"

#: File "src/app/learnocaml_teacher_tab.ml", line 305, characters 56-64
msgid "Closed"
msgstr "Fermé"
#: File "src/app/learnocaml_teacher_tab.ml", line 305, characters 65-80
msgid "Open/Assigned"
msgstr "Ouvert/Devoir"

#: File "src/app/learnocaml_teacher_tab.ml", line 307, characters 41-51
#: File "src/app/learnocaml_teacher_tab.ml", line 306, characters 67-77
msgid "Assigned"
msgstr "Devoir"

#: File "src/app/learnocaml_teacher_tab.ml", line 308, characters 57-68
msgid "Open/Assigned"
msgstr "Ouvert/Devoir"
#: File "src/app/learnocaml_teacher_tab.ml", line 307, characters 55-63
msgid "Closed"
msgstr "Fermé"

#: File "src/app/learnocaml_teacher_tab.ml", line 308, characters 61-75
msgid "Inconsistent"
msgstr "Incohérent"

#: File "src/app/learnocaml_teacher_tab.ml", line 368, characters 49-61 391,
#: 48-60
Expand Down Expand Up @@ -672,39 +676,39 @@ msgstr "%d+ étudiants"
msgid "New assignment"
msgstr "Nouveau devoir"

#: File "src/app/learnocaml_teacher_tab.ml", line 873, characters 16-28
#: File "src/app/learnocaml_teacher_tab.ml", line 869, characters 16-28
msgid "Open/Close"
msgstr "Ouvrir/Fermer"

#: File "src/app/learnocaml_teacher_tab.ml", line 879, characters 47-64
#: File "src/app/learnocaml_teacher_tab.ml", line 875, characters 47-64
msgid "required skills"
msgstr "comp. requises"

#: File "src/app/learnocaml_teacher_tab.ml", line 883, characters 47-63
#: File "src/app/learnocaml_teacher_tab.ml", line 879, characters 47-63
msgid "trained skills"
msgstr "comp. travaillées"

#: File "src/app/learnocaml_teacher_tab.ml", line 892, characters 17-30
#: File "src/app/learnocaml_teacher_tab.ml", line 888, characters 17-30
msgid "Assignments"
msgstr "Devoirs"

#: File "src/app/learnocaml_teacher_tab.ml", line 982, characters 18-25
#: File "src/app/learnocaml_teacher_tab.ml", line 978, characters 18-25
msgid "Apply"
msgstr "Appliquer"

#: File "src/app/learnocaml_teacher_tab.ml", line 983, characters 54-63
#: File "src/app/learnocaml_teacher_tab.ml", line 979, characters 54-63
msgid "Actions"
msgstr "Actions"

#: File "src/app/learnocaml_teacher_tab.ml", line 986, characters 23-49
#: File "src/app/learnocaml_teacher_tab.ml", line 982, characters 23-49
msgid "Create new teacher token"
msgstr "Créer un nouveau token enseignant"

#: File "src/app/learnocaml_teacher_tab.ml", line 988, characters 23-81
#: File "src/app/learnocaml_teacher_tab.ml", line 984, characters 23-81
msgid "Download the data for selected students/exercises as CSV"
msgstr "Télécharger un CSV des exercices/étudiants sélectionnés"

#: File "src/app/learnocaml_teacher_tab.ml", line 1163, characters 55-72
#: File "src/app/learnocaml_teacher_tab.ml", line 1159, characters 55-72
msgid "Unsaved changes"
msgstr "Modifications non sauvegardées"

Expand Down

0 comments on commit 10c9fc3

Please sign in to comment.