Skip to content

Commit 10c9fc3

Browse files
committed
fix(teacher_tab): Display (Open/Close)GloballyInconsistent exos and fix them
* Refactor the Learnocaml_data.Exercise.Status.global_status variant to do so.
1 parent 3a0ceb4 commit 10c9fc3

File tree

5 files changed

+82
-41
lines changed

5 files changed

+82
-41
lines changed

src/app/learnocaml_teacher_tab.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ let rec teacher_tab token _select _params () =
305305
| GloballyOpenOrAssigned -> "exo_assigned", [%i"Open/Assigned"]
306306
| GloballyClosedOrAssigned -> "exo_assigned", [%i"Assigned"]
307307
| GloballyClosed -> "exo_closed", [%i"Closed"]
308+
| GloballyInconsistent -> "exo_closed", [%i"Inconsistent"]
308309
in
309310
H.span ~a:[H.a_class [cls]] [H.txt text]
310311
];
@@ -857,7 +858,8 @@ let rec teacher_tab token _select _params () =
857858
if List.exists (fun id ->
858859
let st = get_status id in
859860
let open_assg = ES.is_open_or_assigned_globally st.ES.assignments in
860-
open_assg = ES.GloballyOpen || open_assg = ES.GloballyOpenOrAssigned)
861+
open_assg = ES.GloballyOpen || open_assg = ES.GloballyOpenOrAssigned
862+
|| open_assg = ES.GloballyInconsistent)
861863
ids
862864
then ES.set_close_or_assigned_globally
863865
else ES.set_open_or_assigned_globally

src/state/learnocaml_data.ml

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ module Exercise = struct
532532
| GloballyClosed (** "Closed" *)
533533
| GloballyOpenOrAssigned (** "Open/Assigned" *)
534534
| GloballyClosedOrAssigned (** "Assigned" *)
535+
| GloballyInconsistent (** "Inconsistent" *)
535536

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

549-
let fix_open_close a =
550-
let mp =
551-
Token.Map.map (function Open -> Closed | st -> st) a.token_map in
552-
match a.default with
553-
| Open | Closed ->
554-
make_assignments mp Closed
555-
| assg ->
556-
make_assignments mp assg
550+
let fix_open_close ?(close=true) a =
551+
if close then
552+
let mp =
553+
Token.Map.map (function Open -> Closed | st -> st) a.token_map in
554+
match a.default with
555+
| Open | Closed ->
556+
make_assignments mp Closed
557+
| assg ->
558+
make_assignments mp assg
559+
else
560+
let mp =
561+
Token.Map.map (function Closed -> Open | st -> st) a.token_map in
562+
match a.default with
563+
| Open | Closed ->
564+
make_assignments mp Open
565+
| assg ->
566+
make_assignments mp assg
557567

558568
let check_and_fix_open_close a =
559569
if check_open_close a then a
560570
else fix_open_close a
561571

562572
let is_open_or_assigned_globally a =
563573
match a.default with
574+
| Assigned _ ->
575+
let o, c =
576+
Token.Map.fold (fun _tok st (o, c) ->
577+
(o || st = Open,
578+
c || st = Closed)) a.token_map (false, false) in
579+
begin match o, c with
580+
| true, true -> GloballyInconsistent
581+
| true, false -> GloballyOpenOrAssigned
582+
| false, _ -> GloballyClosedOrAssigned
583+
end
564584
| Open ->
565-
if Token.Map.exists (fun _tok -> function Assigned _ -> true | _ -> false) a.token_map
566-
then GloballyOpenOrAssigned
567-
else GloballyOpen
585+
let d, c =
586+
Token.Map.fold (fun _tok st (d, c) ->
587+
(d || (match st with Assigned _ -> true | _ -> false),
588+
c || st = Closed)) a.token_map (false, false) in
589+
begin match d, c with
590+
| _, true -> GloballyInconsistent
591+
| true, false -> GloballyOpenOrAssigned
592+
| false, false -> GloballyOpen
593+
end
568594
| Closed ->
569-
if Token.Map.exists (fun _tok -> function Assigned _ -> true | _ -> false) a.token_map
570-
then GloballyClosedOrAssigned
571-
else GloballyClosed
572-
| Assigned _ ->
573-
if Token.Map.exists (fun _tok -> (=) Open) a.token_map
574-
then GloballyOpenOrAssigned
575-
else GloballyClosedOrAssigned
595+
let d, o =
596+
Token.Map.fold (fun _tok st (d, o) ->
597+
(d || (match st with Assigned _ -> true | _ -> false),
598+
o || st = Open)) a.token_map (false, false) in
599+
begin match d, o with
600+
| _, true -> GloballyInconsistent
601+
| true, false -> GloballyClosedOrAssigned
602+
| false, false -> GloballyClosed
603+
end
576604

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

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

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

src/state/learnocaml_data.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ module Exercise: sig
225225
| GloballyClosed (** "Closed" *)
226226
| GloballyOpenOrAssigned (** "Open/Assigned" *)
227227
| GloballyClosedOrAssigned (** "Assigned" *)
228+
| GloballyInconsistent (** "Inconsistent" *)
228229

229230
val is_open_or_assigned_globally: assignments -> global_status
230231

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

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

250251
(** Call [check_open_close] then (if need be) [fix_open_close] *)
251252
val check_and_fix_open_close: assignments -> assignments

src/state/learnocaml_data_test.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ let%test_module _ =
2020
| GloballyClosed -> "GloballyClosed"
2121
| GloballyOpenOrAssigned -> "GloballyOpenOrAssigned"
2222
| GloballyClosedOrAssigned -> "GloballyClosedOrAssigned"
23+
| GloballyInconsistent -> "GloballyInconsistent"
2324

2425
let testdata_map_of list =
2526
List.fold_right (fun (tok, st) res -> Token.Map.add tok st res) list Token.Map.empty
@@ -62,7 +63,7 @@ let%test_module _ =
6263
List.iter (fun glob -> Printf.printf "%s\n"
6364
@@ testdata_str_of_globalstatus
6465
@@ is_open_or_assigned_globally glob)
65-
testdata_good_assignments;
66+
(testdata_good_assignments @ testdata_wrong_assignments);
6667
[%expect{|
6768
GloballyOpen
6869
GloballyClosed
@@ -73,7 +74,10 @@ let%test_module _ =
7374
GloballyClosedOrAssigned
7475
GloballyOpen
7576
GloballyClosed
76-
GloballyClosedOrAssigned |}]
77+
GloballyClosedOrAssigned
78+
GloballyInconsistent
79+
GloballyInconsistent
80+
GloballyInconsistent |}]
7781

7882
let%test "check_open_close/good" =
7983
List.for_all check_open_close testdata_good_assignments

translations/fr.po

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
msgid ""
77
msgstr ""
88
"Project-Id-Version: learn-ocaml ~dev\n"
9-
"PO-Revision-Date: 2023-08-25 12:59+0200\n"
9+
"PO-Revision-Date: 2023-08-28 09:10+0200\n"
1010
"Last-Translator: Erik Martin-Dorel <[email protected]>\n"
1111
"Language-Team: OCSF\n"
1212
"Language: french\n"
@@ -599,21 +599,25 @@ msgstr ""
599599
"\n"
600600
"Notez-le !"
601601

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

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

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

614-
#: File "src/app/learnocaml_teacher_tab.ml", line 308, characters 57-68
615-
msgid "Open/Assigned"
616-
msgstr "Ouvert/Devoir"
614+
#: File "src/app/learnocaml_teacher_tab.ml", line 307, characters 55-63
615+
msgid "Closed"
616+
msgstr "Fermé"
617+
618+
#: File "src/app/learnocaml_teacher_tab.ml", line 308, characters 61-75
619+
msgid "Inconsistent"
620+
msgstr "Incohérent"
617621

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

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

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

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

687-
#: File "src/app/learnocaml_teacher_tab.ml", line 892, characters 17-30
691+
#: File "src/app/learnocaml_teacher_tab.ml", line 888, characters 17-30
688692
msgid "Assignments"
689693
msgstr "Devoirs"
690694

691-
#: File "src/app/learnocaml_teacher_tab.ml", line 982, characters 18-25
695+
#: File "src/app/learnocaml_teacher_tab.ml", line 978, characters 18-25
692696
msgid "Apply"
693697
msgstr "Appliquer"
694698

695-
#: File "src/app/learnocaml_teacher_tab.ml", line 983, characters 54-63
699+
#: File "src/app/learnocaml_teacher_tab.ml", line 979, characters 54-63
696700
msgid "Actions"
697701
msgstr "Actions"
698702

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

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

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

0 commit comments

Comments
 (0)