Skip to content

Commit

Permalink
topbar UI tweaks. renamed school mode to exercise mode across most na…
Browse files Browse the repository at this point in the history
…mespaces
  • Loading branch information
disconcision committed Jul 12, 2023
1 parent ca6cd9a commit 85ad61e
Show file tree
Hide file tree
Showing 34 changed files with 347 additions and 395 deletions.
2 changes: 1 addition & 1 deletion INSTRUCTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
1. Make a copy of src/haz3lweb/exercises/BlankTemplate.ml, filling in the arguments for your exercise.
Make sure the module_name argument matches your module name. Use the .ml extension (for technical reasons).

2. Add your exercise to the exercise list in SchoolSettings_base.re.
2. Add your exercise to the exercise list in ExerciseSettings_base.re.

3. Compile and load Hazel, select your exercise, make sure Instructor Mode is on.

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ change-deps:
opam switch export opam.export

setup-instructor:
cp src/haz3lweb/SchoolSettings_instructor.re src/haz3lweb/SchoolSettings.re
cp src/haz3lweb/ExerciseSettings_instructor.re src/haz3lweb/ExerciseSettings.re

setup-student:
cp src/haz3lweb/SchoolSettings_student.re src/haz3lweb/SchoolSettings.re
cp src/haz3lweb/ExerciseSettings_student.re src/haz3lweb/ExerciseSettings.re

dev-helper:
dune build @src/fmt --auto-promote src --profile dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ module type ExerciseEnv = {
};

let output_header_grading = _module_name =>
"module SchoolExercise = GradePrelude.SchoolExercise\n"
++ "let prompt = ()\n";
"module Exercise = GradePrelude.Exercise\n" ++ "let prompt = ()\n";

module F = (ExerciseEnv: ExerciseEnv) => {
[@deriving (show({with_path: false}), sexp, yojson)]
Expand Down Expand Up @@ -857,7 +856,7 @@ module F = (ExerciseEnv: ExerciseEnv) => {
"let prompt = "
++ module_name
++ "_prompt.prompt\n"
++ "let exercise: SchoolExercise.spec = ";
++ "let exercise: Exercise.spec = ";
let record = show_p(editor_pp, eds);
let data = prefix ++ record ++ "\n";
data;
Expand All @@ -874,15 +873,15 @@ module F = (ExerciseEnv: ExerciseEnv) => {
"let prompt = "
++ module_name
++ "_prompt.prompt\n"
++ "let exercise: SchoolExercise.spec = SchoolExercise.transition(";
++ "let exercise: Exercise.spec = Exercise.transition(";
let record = show_p(transitionary_editor_pp, eds);
let data = prefix ++ record ++ ")\n";
data;
};

let export_grading_module = (module_name, {eds, _}: state) => {
let header = output_header_grading(module_name);
let prefix = "let exercise: SchoolExercise.spec = ";
let prefix = "let exercise: Exercise.spec = ";
let record = show_p(editor_pp, eds);
let data = header ++ prefix ++ record ++ "\n";
data;
Expand Down Expand Up @@ -938,7 +937,7 @@ module F = (ExerciseEnv: ExerciseEnv) => {
// From Store

[@deriving (show({with_path: false}), sexp, yojson)]
type school_export = {
type exercise_export = {
cur_exercise: key,
exercise_data: list((key, persistent_state)),
};
Expand All @@ -956,7 +955,7 @@ module F = (ExerciseEnv: ExerciseEnv) => {
|> unpersist_state(~spec, ~instructor_mode);
};

let deserialize_school_export = data => {
data |> Sexplib.Sexp.of_string |> school_export_of_sexp;
let deserialize_exercise_export = data => {
data |> Sexplib.Sexp.of_string |> exercise_export_of_sexp;
};
};
4 changes: 2 additions & 2 deletions src/haz3lschool/GradePrelude.re
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module ExerciseEnv = {
type node = unit;
let default = ();
let output_header = SchoolExercise.output_header_grading;
let output_header = Exercise.output_header_grading;
};

module SchoolExercise = SchoolExercise.F(ExerciseEnv);
module Exercise = Exercise.F(ExerciseEnv);

module Grading = Grading.F(ExerciseEnv);
10 changes: 5 additions & 5 deletions src/haz3lschool/Gradescope.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open Haz3lschool;
open Core;

open Specs;
open GradePrelude.SchoolExercise;
open GradePrelude.Exercise;
open GradePrelude.Grading;

[@deriving (sexp, yojson)]
Expand Down Expand Up @@ -44,15 +44,15 @@ type section = {
type chapter = list(section);

module Main = {
let name_to_school_export = path => {
let name_to_exercise_export = path => {
let yj = Yojson.Safe.from_file(path);
switch (yj) {
| `Assoc(l) =>
let sch = List.Assoc.find_exn(~equal=String.(==), l, "school");
switch (sch) {
| `String(sch) =>
let school_export = sch |> deserialize_school_export;
school_export;
let exercise_export = sch |> deserialize_exercise_export;
exercise_export;
| _ => failwith("School is not a string")
};
| _ => failwith("Json without school key")
Expand Down Expand Up @@ -98,7 +98,7 @@ module Main = {
};
let run = () => {
let hw_path = Sys.get_argv()[1];
let hw = name_to_school_export(hw_path);
let hw = name_to_exercise_export(hw_path);
let export_chapter =
hw.exercise_data
|> List.map(~f=(((name, _) as key, persistent_state)) => {
Expand Down
4 changes: 2 additions & 2 deletions src/haz3lschool/Grading.re
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
open Haz3lcore;
open Sexplib.Std;

module F = (ExerciseEnv: SchoolExercise.ExerciseEnv) => {
open SchoolExercise.F(ExerciseEnv);
module F = (ExerciseEnv: Exercise.ExerciseEnv) => {
open Exercise.F(ExerciseEnv);

[@deriving (show({with_path: false}), sexp, yojson)]
type percentage = float;
Expand Down
26 changes: 13 additions & 13 deletions src/haz3lweb/Editors.re
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ type scratch = (int, list(ScratchSlide.state));
type examples = (string, list((string, ScratchSlide.state)));

[@deriving (show({with_path: false}), sexp, yojson)]
type school = (int, list(SchoolExercise.spec), SchoolExercise.state);
type exercises = (int, list(Exercise.spec), Exercise.state);

[@deriving (show({with_path: false}), sexp, yojson)]
type t =
| DebugLoad
| Scratch(int, list(ScratchSlide.state))
| Examples(string, list((string, ScratchSlide.state)))
| Exercises(int, list(SchoolExercise.spec), SchoolExercise.state);
| Exercise(int, list(Exercise.spec), Exercise.state);

[@deriving (show({with_path: false}), sexp, yojson)]
type mode =
| DebugLoad
| Scratch
| Examples
| Exercises;
| Exercise;

let mode_of_string = (s: string): mode =>
switch (s) {
| "Scratch" => Scratch
| "Examples" => Examples
| "Exercises" => Exercises
| "Exercise" => Exercise
| _ => Scratch
};

Expand All @@ -47,9 +47,9 @@ let get_editor_and_id = (editors: t): (Id.t, Editor.t) =>
let id = ScratchSlide.id_of_state(slide);
let ed = ScratchSlide.editor_of_state(slide);
(id, ed);
| Exercises(_, _, exercise) =>
let id = SchoolExercise.id_of_state(exercise);
let ed = SchoolExercise.editor_of_state(exercise);
| Exercise(_, _, exercise) =>
let id = Exercise.id_of_state(exercise);
let ed = Exercise.editor_of_state(exercise);
(id, ed);
};

Expand Down Expand Up @@ -78,8 +78,8 @@ let put_editor_and_id = (id: Id.t, ed: Editor.t, eds: t): t =>
|> List.remove_assoc(name)
|> List.cons((name, ScratchSlide.put_editor_and_id(slide, id, ed))),
);
| Exercises(n, specs, exercise) =>
Exercises(n, specs, SchoolExercise.put_editor_and_id(exercise, id, ed))
| Exercise(n, specs, exercise) =>
Exercise(n, specs, Exercise.put_editor_and_id(exercise, id, ed))
};

let get_zipper = (editors: t): Zipper.t => get_editor(editors).state.zipper;
Expand All @@ -93,7 +93,7 @@ let get_spliced_elabs = (editors: t): list((ModelResults.key, DHExp.t)) => {
| Examples(name, slides) =>
let slide = List.assoc(name, slides);
ScratchSlide.spliced_elabs(slide);
| Exercises(_, _, exercise) => SchoolExercise.spliced_elabs(exercise)
| Exercise(_, _, exercise) => Exercise.spliced_elabs(exercise)
};
};

Expand All @@ -102,10 +102,10 @@ let set_instructor_mode = (editors: t, instructor_mode: bool): t =>
| DebugLoad => failwith("no editors in debug load mode")
| Scratch(_)
| Examples(_) => editors
| Exercises(n, specs, exercise) =>
Exercises(
| Exercise(n, specs, exercise) =>
Exercise(
n,
specs,
SchoolExercise.set_instructor_mode(exercise, instructor_mode),
Exercise.set_instructor_mode(exercise, instructor_mode),
)
};
15 changes: 6 additions & 9 deletions src/haz3lweb/Examples.re
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
let init_data = [
("Basic Reference", LanguageRefSlide.lang_ref),
("Basic types", LanguageRefSlide.basic_type_egs),
("ADT Statics", LanguageRefSlide.adt_egs),
("ADT Dynamics", LanguageRefSlide.adt_dynamics_tests),
let init = [
("Basic Reference", SerializedExamples.lang_ref),
("Types & errors", SerializedExamples.basic_type_egs),
("ADT Statics", SerializedExamples.adt_egs),
("ADT Dynamics", SerializedExamples.adt_dynamics_tests),
];

let init_name = name => {
let data = List.assoc(name, init_data);
ScratchSlide.unpersist(data);
};
let init_name = name => ScratchSlide.unpersist(List.assoc(name, init));
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ module ExerciseEnv = {
"let prompt = " ++ module_name ++ "_prompt.prompt\n";
};

include Haz3lschool.SchoolExercise.F(ExerciseEnv);
include Haz3lschool.Exercise.F(ExerciseEnv);
2 changes: 2 additions & 0 deletions src/haz3lweb/ExerciseSettings.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ExerciseSettings_base;
let show_instructor = true;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let filename = "haz3l-demo";
let log_key = filename;
let exercises: list(SchoolExercise.spec) = [
let exercises: list(Exercise.spec) = [
Ex_OddlyRecursive.exercise,
Ex_RecursiveFibonacci.exercise,
];
2 changes: 2 additions & 0 deletions src/haz3lweb/ExerciseSettings_instructor.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ExerciseSettings_base;
let show_instructor = true;
2 changes: 2 additions & 0 deletions src/haz3lweb/ExerciseSettings_student.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ExerciseSettings_base;
let show_instructor = false;
19 changes: 11 additions & 8 deletions src/haz3lweb/Export.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type all = {
settings: string,
langDocMessages: string,
scratch: string,
school: string,
exercise: string,
log: string,
};

Expand All @@ -14,7 +14,7 @@ type all = {
type all_f22 = {
settings: string,
scratch: string,
school: string,
exercise: string,
log: string,
};

Expand All @@ -26,11 +26,14 @@ let mk_all = (~instructor_mode) => {
print_endline("LangDocMessages OK");
let scratch = Store.Scratch.export();
print_endline("Scratch OK");
let specs = School.exercises;
let school = Store.School.export(~specs, ~instructor_mode);
print_endline("School OK");
let exercise =
Store.Exercise.export(
~specs=ExerciseSettings.exercises,
~instructor_mode,
);
print_endline("Exercise OK");
let log = Log.export();
{settings, langDocMessages, scratch, school, log};
{settings, langDocMessages, scratch, exercise, log};
};

let export_all = (~instructor_mode) => {
Expand All @@ -45,7 +48,7 @@ let import_all = (data, ~specs) => {
{
settings: all_f22.settings,
scratch: all_f22.scratch,
school: all_f22.school,
exercise: all_f22.exercise,
log: all_f22.log,
langDocMessages: "",
};
Expand All @@ -54,6 +57,6 @@ let import_all = (data, ~specs) => {
Store.LangDocMessages.import(all.langDocMessages);
let instructor_mode = settings.instructor_mode;
Store.Scratch.import(all.scratch);
Store.School.import(all.school, ~specs, ~instructor_mode);
Store.Exercise.import(all.exercise, ~specs, ~instructor_mode);
Log.import(all.log);
};
2 changes: 1 addition & 1 deletion src/haz3lweb/Grading.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Virtual_dom.Vdom;
open Node;

include Haz3lschool.Grading.F(SchoolExercise.ExerciseEnv);
include Haz3lschool.Grading.F(Exercise.ExerciseEnv);

let score_view = ((earned: points, max: points)) => {
div(
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lweb/Log.re
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let is_action_logged: UpdateAction.t => bool =
| MoveToNextHole(_)
| UpdateLangDocMessages(_) => true;

let storage_key = "LOG_" ++ SchoolSettings.log_key;
let storage_key = "LOG_" ++ ExerciseSettings.log_key;
let max_log_string_length = 4_750_000; // based on 5MB limit on localstore in browser

module Entry = {
Expand Down
4 changes: 2 additions & 2 deletions src/haz3lweb/ModelSettings.re
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ let init = {
dynamics: true,
async_evaluation: false,
context_inspector: false,
instructor_mode: SchoolSettings.show_instructor,
instructor_mode: ExerciseSettings.show_instructor,
benchmark: false,
mode: Editors.Scratch,
};

let init_debug = {...init, mode: Editors.DebugLoad};

let fix_instructor_mode = settings =>
if (settings.instructor_mode && !SchoolSettings.show_instructor) {
if (settings.instructor_mode && !ExerciseSettings.show_instructor) {
{...settings, instructor_mode: false};
} else {
settings;
Expand Down
11 changes: 0 additions & 11 deletions src/haz3lweb/School.re

This file was deleted.

2 changes: 0 additions & 2 deletions src/haz3lweb/SchoolSettings.re

This file was deleted.

2 changes: 0 additions & 2 deletions src/haz3lweb/SchoolSettings_instructor.re

This file was deleted.

2 changes: 0 additions & 2 deletions src/haz3lweb/SchoolSettings_student.re

This file was deleted.

2 changes: 1 addition & 1 deletion src/haz3lweb/ScratchSlidesInit.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let filled_slides = [LanguageRefSlide.lang_ref];
let filled_slides = [SerializedExamples.lang_ref];

let empty: ScratchSlide.persistent_state = (
1,
Expand Down
File renamed without changes.
Loading

0 comments on commit 85ad61e

Please sign in to comment.