(*© 2012-Present Computational ClassNotes, lossofgenerality.org, Creative Commons License *)
(*https://creativecommons.org/licenses/by-nc-sa/3.0/us/  :  Attribution-NonCommercial-ShareAlike *)

SetOptions[EvaluationNotebook[],Background->LightGray]

Cloud Libraries

CloudGet["https://www.wolframcloud.com/objects/ccn/module/v5.1"];
init[];
Clear[init];

logic1[ctr_,mywords_,abcd_]:=Module[{correct,vv,words,wrong,vars,aa,a,b,c,example,choices,molecule={},wrongmolecule={},c1,c2,c3,c4,letter},


vv=Release@Map[Hold[RandomChoice@{ToUpperCase,ToLowerCase}],RandomSample[Complement[CharacterRange["a","z"],{"l","o", "i","e"}],2]];


correct={};
wrong={{},{},{}};
choices=Join[{correct},wrong];
While[Or@@(#[[1]]===#[[2]]&/@Permutations[choices, {2}]),


letter=RandomSample[Keys[CCNENGLISH`nounsfruits],5];
(*c1 correct*)
c1=RandomChoice@CCNENGLISH`nounsfruits[letter[[1]]];

{c2,c3,c4,c5}={RandomChoice@CCNENGLISH`nounsfruits[letter[[2]]],RandomChoice@CCNENGLISH`nounsfruits[letter[[3]]],RandomChoice@CCNENGLISH`nounsfruits[letter[[4]]],
RandomChoice@CCNENGLISH`nounsfruits[letter[[5]]]};
correct=(Row@{c1["name"],c1["image"]});
wrong=({

Row@{c2["name"],c3["image"]},
Row@{c5["name"],c4["image"]},
Row@{c3["name"],c5["image"]}

});

wrong=RandomSample[wrong,Length@wrong];

choices=Join[{correct},wrong];];


If [mywords=!={}, words=mywords[vars,ctr], words[s_]:=Nothing];


<|

"question labeled"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),

"question"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),


"anime"->(

{(*
ImageResize[myRASTER[#],{450,540}]&/@list*)}

),

"tutorial_anime"->(
{}
),

"example"->(

example=Column@{
Row@{Style["Example Stuff",Orange,FontSize->18,FontWeight->Bold]}
}

),

(*This was added in 4.0 to allow for pdf that is different than exampl*)
"example PDF"->(

(*example*)
{}

(*Column@{
Row@{Style["PDF Stuff",Orange,FontSize->18,FontWeight->Bold]}

}*)

),

"example_anime"->(

{}
),

"solution"->(
{
Row@{Style["Solution",FontSize->18,FontWeight->Bold]},
words["solution"],
correct
}
),

"correct"->(
myFRAME2@correct
),

"wrong"->(
myFRAME2/@wrong
),

"video"->({}),
"molecule"->(molecule), (*used for the question or example*)
"molecule"->(molecule), 
"wrong_molecule"->(wrongmolecule),
"abcd"->({})


|>

];

DATA

CCNENGLISH`nounsfruits=<|


"pineapple"->{
<|"name"->Style["Pineapple",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Pineapple",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Pineapple",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Pineapple",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Pineapple",40],"image"->ImageResize[,200]|>} ,


"apple"->{
<|"name"->Style["Apple",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Apple",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Apple",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Apple",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Apple",40],"image"->ImageResize[,200]|>} ,


"mango"->{
<|"name"->Style["Mango",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Mango",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Mango",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Mango",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Mango",40],"image"->ImageResize[,200]|>} ,

"grapes"->{
<|"name"->Style["Grapes",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Grapes",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Grapes",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Grapes",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Grapes",40],"image"->ImageResize[,200]|>} ,



"banana"->{
<|"name"->Style["Banana",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Banana",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Banana",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Banana",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Banana",40],"image"->ImageResize[,200]|>} ,


"pear"->{
<|"name"->Style["Pear",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Pear",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Pear",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Pear",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Pear",40],"image"->ImageResize[,200]|>} ,



"orange"->{
<|"name"->Style["Orange",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Orange",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Orange",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Orange",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Orange",40],"image"->ImageResize[,200]|>} 


|>;

CloseKernels[];

LaunchKernels[4]

SetSharedVariable[CCNENGLISH`nounsfruits];

JSON

PNG=False;
debugCORRECT=False;
isSERVER="JSON";
myDIRECTORY={NotebookDirectory[],"fruitnames_","SVG"};
myGIFDIRECTORY={NotebookDirectory[],"fruitnames_","GIF"};
myCDFDIRECTORY={NotebookDirectory[],"fruitnames_","cdf"};
myPDFDIRECTORY={NotebookDirectory[],"fruitnames_","pdf"};


myTITLE={" "," "," "};


vars=Table[
ParallelTable[


varilist={

{logic1,{},<|"type"->"1","question"->myDIRECTORY,"tutorial"->myDIRECTORY,"anime"->myGIFDIRECTORY|>}
};


nn=Length@varilist;
varilist=RandomSample[varilist,nn];

(*uncomment these two lines if chained questions*)
(*varilist=Flatten[varilist,1];
nn=Length@varilist;*)
tmp=ConstantArray["",nn];
logics=varilist[[All,1]];
words=varilist[[All,2]];
etc=varilist[[All,3]];

title=<|
1->"",
2->"2. ",
3->"3. ",
4->"4. ",
5->"5. ",
6->"6. "

|>;



Table[tmp[[ii]]=makeVAR[title[ii],logics[[ii]],words[[ii]],If[ii==1,{},( tmp[[ii-1]])[[1]][[2]]],etc[[ii]]]["json"],{ii,1,nn}],

{16}],
{1}];

vars=Flatten[vars,1];

CloseKernels[];

Export[FileNameJoin@{NotebookDirectory[],"cache","cache.json"},vars];

CloseKernels[];