LIBS

libLIST=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libLIST.m"]<>"\n";
libNAMES=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libNAMES.m"]<>"\n";
libIO=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libIO.m"]<>"\n";
libERR=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libERR.m"]<>"\n";
libGUI=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libGUI.m"]<>"\n";
libML=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libML.m"]<>"\n";
libMISC=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libMISC.m"]<>"\n";
libGraphics=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libGraphics.m"]<>"\n";

libLIST=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libLIST.m"]<>"\n";
libNAMES=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libNAMES.m"]<>"\n";
libIO=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libIO.m"]<>"\n";
libERR=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libERR.m"]<>"\n";
libGUI=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libGUI.m"]<>"\n";
libML=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libML.m"]<>"\n";
libMISC=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libMISC.m"]<>"\n";
libGraphics=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libGraphics.m"]<>"\n";

Module Area

data1="\n"<>"textfghjkl:="<>ToString[<|

(*fghjkl. removed*)


"0"-><|
"1.1"->{"Column[{ToString[\" \"]"<>"}]"}
|>
,
(* let's use key as the option *)
"1"-><|
"1.1"->{"Column[{ToString[\"1. If the index NS denotes the non-science majors and the index S denotes the science majors the null hypothesis for testing is?\",TraditionalForm]"<>"}]"}
|>
,
"2"-><|

"2.1"->{"Column[{ToString[\"2. What is the value of the test statistic?\",TraditionalForm]"<>"}, Alignment->Left]"}
|>

,
"3"-><|
"3.1"->{"Column[{ToString[\"3. What is the critical value for the test at the alpha= 0.05 level of significance?\"]}]"}

|>
,

"4"-><|
"4.1"->{"Column[{ToString[\"4. Which of the following represents the correct conclusion at alpha=0.05 ?\",TraditionalForm]"<>"}]"
}
|>
,
"5"-><|
"5.1"->{"Column[{ToString[\"5. Which of the following represents the relevant alternative hypothesis?\"]"<>"}]"}
|>
,
"6"-><|
"6.1"->{"Column[{ToString[\"6. Which of the following represents the result of the relevant hypothesis test at alpha=0.05 level of significance?\"]"<>"}]"}
|>

|>,InputForm]<>";\n ";



data2="listfghjkl:="<>


ToString[{"",""


},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];



canvas1="\n"<>ToString[Hold[Module[{vars=ertyuiop,t,text,text1,text2,text3,text4,text5,text6,text7,text8,text9,text10,text11,text12,answers, options,locs,data},


text=vars["text"];
Grid[{

{Image[,ImageSize->125]},
{Image[]},   
{"Quiz 5,Feb 2016"},
{Image[]},
{"id"},
{Image[]},
{Image[]},
{Style["Use the following scenario for problems 1-4",Bold,21]},
{Image[]},
(*question 1 *)
text1=vars["vars"][[1]][[6]];
{Grid[{{Rasterize@ToExpression@text1}}]},
{Grid[{{Rasterize@makeTextTable[{{"None-Science Major","Science Major"},{"n = 13","n = 10"},{"(S^2) = 210.2","(S^2) = 36.5"}}]}}]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[2]]}}]},
{Image[]},
text2=vars["vars"][[1]][[5]];
{Grid[{{Rasterize@ToExpression@text2}}]},
{Image[]},
{Grid[{{"x2"}}]}, 
{Image[]},
{Image[]},
(*question 2*)
(*text8=vars["vars"][[2]][[6]];
t=vars["vars"][[2]][[3]];
text11=vars["vars"][[2]][[7]];
{Grid[{{Rasterize@ToExpression@text8}}]},
(*{Grid[{{Rasterize@Grid[Partition[ToExpression/@t,6],Frame->True]}}]},*)
{Grid[{{Rasterize@ToExpression@text11}}]},
{Image[]},*)
{Grid[{{Rasterize@ToExpression@text[[3]]}}]},
{Image[]},
text7=vars["vars"][[2]][[5]];
{Grid[{{Rasterize@ToExpression@text7}}]},
{Image[]},
{Grid[{{"x4"}}]},
{Image[]},
{Image[]},
(*question 3*)
{Grid[{{Rasterize@ToExpression@text[[4]]}}]},
{Image[]},
text5=vars["vars"][[3]][[5]];
{Grid[{{Rasterize@ToExpression@text5}}]},
{Image[]},
{Grid[{{"x5"}}]},

{Image[]},
{Image[]},
(*question 4*)
text3=vars["vars"][[4]][[5]];
{Grid[{{Rasterize@ToExpression@text[[5]]}}]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text3}}]},
{Image[]},
{Grid[{{"x6"}}]},
{Image[]},
{Image[]},
{Style["Use the following scenario for problems 5-6",Bold,21]},
{Image[]},
(*question 5*)
text12=vars["vars"][[5]][[8]];
{Grid[{{Rasterize@ToExpression@text12}}]},
{Grid[{{Rasterize@ToExpression@text[[6]]}}]},
{Image[]},
text6=vars["vars"][[5]][[5]];
{Grid[{{Rasterize@ToExpression@text6}}]},
{Image[]},
{Grid[{{"x7"}}]},
{Image[]},
{Image[]},
(*question 6*)
(*text9=vars["vars"][[6]][[7]];
{Grid[{{Rasterize@ToExpression@text9}}]},
{Image[]},*)
{Grid[{{Rasterize@ToExpression@text[[7]]}}]},

{Image[]},
text4=vars["vars"][[6]][[5]];
{Grid[{{Rasterize@ToExpression@text4}}]},
{Image[]},
{Grid[{{"x8"}}]},
{Image[]}

},Spacings->{0,3}]


]],InputForm]<>"\n ";





variation1=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{key,p,x,a,b,c,d,e,f,g,h,i,j,m,n,r,r2,y,z,a1,b1,c1,d1,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,pp2,sd, vars,text,list,list0,list1,list01,list02,list2,sol,aabbee,k, parta, partb, partc, partd,parte,partf,partg,parth,parti,question,list12,teste,sol2,sol3,t,t2},


question=RandomChoice[textfghjkl["0"]];

(*a*)

key=RandomChoice[Keys[textfghjkl["1"]]];
text=RandomChoice[textfghjkl["1"][key]];


Which[key=="1.1", 
a=ToString@(RandomInteger[{160,210}]);
b=ToString@RandomInteger[{100,110}];
c=ToString@RandomInteger[{20,26}];
d=ToString@(ToExpression@b+RandomInteger[{3,7}]);


list0=StringReplace["A professor in the math department of a faculty claims that there is much more variability in the final exam scores of students taking the introductory calculus course who are not majoring in sciences than for students taking the course who are majoring in sciences. Random samples of 13 non-science majors and 10 science majors are taken from the professor's class roster in his large lecture, and the following results are computed based on the final exam scores. Is there evidence to support professor's claim? ", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}];
(* For any String for sol we need to double quote or some confusing bug shows up*)
list=RandomChoice@{

{StringReplace["((Subscript[σ, S])^2) ≠ ((Subscript[σ, NS])^2).", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],
{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["((Subscript[σ, S])^2) < ((Subscript[σ, NS])^2)",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["((Subscript[σ, S])^2) > ((Subscript[σ, NS])^2)",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["((Subscript[σ, S])^2) = ((Subscript[σ, NS])^2)",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"T\"","\"true\"","\"TRUE\""}}
};



vars={a,b,c,d,ToString[list[[1]],InputForm],ToString[list0,InputForm]};
sol={list[[2]]};

parta={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],vars,sol} ;

];



key=RandomChoice[Keys[textfghjkl["2"]]];
text=RandomChoice[textfghjkl["2"][key]];

Which[key=="2.1", 

a1=ToString@(N[RandomInteger[{6000,6200}]/1000]);
f=ToExpression@a1-0.09;
g=ToExpression@a1+0.09;
c=ToString/@(RandomSample[Range[f*1000,g*1000],18]/1000);
a=ToString@Mean[ToExpression/@c];
b=ToString@(N[Floor[(ToExpression@a - 0.01)*100]/100]);
sd=StandardDeviation[ToExpression/@c];
d=ToString@(N[(ToExpression@a-ToExpression@b)/(sd/Sqrt[18])]);

list01=StringReplace["", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}];

list02=StringReplace["", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}];

(*list0={list01,list02};*)

(* For any String for sol we need to double quote or some confusing bug shows up*)
list=RandomChoice@{

{StringReplace["σ", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],
{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["π",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["(OverBar[X])",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["μ",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"T\"","\"true\"","\"TRUE\""}}
};



vars={a,b,c,d,ToString[list[[1]],InputForm],ToString[list01,InputForm],ToString[list02,InputForm]};
sol={list[[2]]};

partb={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],vars,sol} ;
];


key=RandomChoice[Keys[textfghjkl["3"]]];
text=RandomChoice[textfghjkl["3"][key]];

Which[key=="3.1", 
a=ToString@RandomChoice[{0.01,0.001,0.005}];
b=partb[[2]][[2]];
c=ToString@0;
d=ToString@0;


(* For any String for sol we need to double quote or some confusing bug shows up*)
list=RandomChoice@{

{StringReplace[" (Subscript[H, 0]) : μ ≥ #b and (Subscript[H, 1]) : μ < #b.", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],
{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["(Subscript[H, 0]) : (OverBar[X]) ≥ #b and (Subscript[H, 1]) : (OverBar[X]) < #b.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["(Subscript[H, 0]) : (OverBar[X]) = #b and (Subscript[H, 1]) : (OverBar[X]) ≠ #b.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["(Subscript[H, 0]) : μ ≤ #b and (Subscript[H, 1]) : μ > #b.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"T\"","\"true\"","\"TRUE\""}}
};



vars={a,b,c,d,ToString[list[[1]],InputForm]};
sol={list[[2]]};

partc={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],vars,sol} ;
];



key=RandomChoice[Keys[textfghjkl["4"]]];
text=RandomChoice[textfghjkl["4"][key]];

Which[key=="4.1", 

{a,b}=ToString/@RandomChoice[{{0.05,1.74},{0.1,1.33}}];


(* For any String for sol we need to double quote or some confusing bug shows up*)
list=RandomChoice@{

{StringReplace["There is no evidence of a difference in the population variances between science majors and non-science majors.", { "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],
{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["There is enough evidence to conclude that the variance in final exam scores of non-science majors is greater than the variance in final exam scores of science majors.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"T\"","\"true\"","\"TRUE\""}},

{StringReplace["The population variances between science majors and non-science majors are the same..",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},
{StringReplace["There is enough evidence to conclude that the variance in final exam scores of non-science majors is smaller than the variance in final exam scores of science majors.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}}
};

c=partb[[2]][[2]]; (*it is μ, I need it for plot in send*)
d=partb[[2]][[4]];
e=partb[[2]][[6]];


vars={a,b,c,d,ToString[list[[1]],InputForm],e};
sol={list[[2]]};

partd={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],vars,sol} ;

];

key=RandomChoice[Keys[textfghjkl["5"]]];
text=RandomChoice[textfghjkl["5"][key]];



Which[key=="5.1", 

b=partb[[2]][[2]];
d=partb[[2]][[4]];

sol2=NSolve[CDF[StudentTDistribution[17],ToExpression@d]==1- (ToExpression@x),{x}, Reals];
t=x/.sol2[[1]];
a=ToString@(N[Ceiling[N[IntegerPart[t*10000]/100]+1]/100]);
c=ToString@(0.5*ToExpression@a );
e=ToString@(0.5*ToExpression@c );

(* For any String for sol we need to double quote or some confusing bug shows up*)
list2=StringReplace["The data below presents the summary statistics for the starting annual salaries (in thousands of dollars) for individuals entering the public accounting and financial planning professions. Test whether the mean starting annual salaries for individuals entering the public accounting professions is higher than that of financial planning, assuming that the two population variances are the same.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}];

list0=RandomChoice@{

{StringReplace["(Subscript[H, 1]) : \!\(\*SubscriptBox[\(μ\), \(\(1\)\(\\ \\ \)\)]\)- \!\(\*SubscriptBox[\(μ\), \(\(2\)\(\\ \\ \)\)]\)< 0", { "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],
{"\"False\"","\"false\"","\"FALSE\"","\"F\""},a},

{StringReplace["(Subscript[H, 1]) : \!\(\*SubscriptBox[\(μ\), \(\(1\)\(\\ \\ \)\)]\)- \!\(\*SubscriptBox[\(μ\), \(\(2\)\(\\ \\ \)\)]\)= 0",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""},c},

{StringReplace["(Subscript[H, 1]) : \!\(\*SubscriptBox[\(μ\), \(\(1\)\(\\ \\ \)\)]\)- \!\(\*SubscriptBox[\(μ\), \(\(2\)\(\\ \\ \)\)]\)≠ 0",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""},e},

{StringReplace["(Subscript[H, 1]) : \!\(\*SubscriptBox[\(μ\), \(\(1\)\(\\ \\ \)\)]\)- \!\(\*SubscriptBox[\(μ\), \(\(2\)\(\\ \\ \)\)]\)> 0",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"T\"","\"true\"","\"TRUE\""},a}
};

list=list0[[1;;2]];
f=list0[[3]];

vars={a,b,c,d,ToString[list[[1]],InputForm],e,f,ToString[list2,InputForm]};
sol={list[[2]]};

parte={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],vars,sol} ;


];

key=RandomChoice[Keys[textfghjkl["6"]]];
text=RandomChoice[textfghjkl["6"][key]];


Which[key=="6.1", 

(*{a,b,c,d,pp,e}=partd[[2]];*)
a=ToString@(RandomSample[Range[80,88],1][[1]]);
{b,c}=ToString/@({100,RandomSample[Range[90,96],1][[1]]});

d=ToString@(N[(ToExpression@a )/100]);
e=ToString@0;


list1=StringReplace["OK",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}];

(* For any String for sol we need to double quote or some confusing bug shows up*)
list=RandomChoice@{

{StringReplace["The alternative hypothesis is rejected.", { "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],
{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["The null hypothesis is rejected.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},
{StringReplace["The null hypothesis is not rejected.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["Insufficient information exists on which to make a decision.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"T\"","\"true\"","\"TRUE\""}}
};



vars={a,b,c,d,ToString[list[[1]],InputForm],e,ToString[list1,InputForm]};
sol={list[[2]]};

partf={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],vars,sol} ;
];

vars=ToString[<|"text"->{question, parta[[1]],partb[[1]],partc[[1]],partd[[1]],parte[[1]],partf[[1]]},"vars"->{ parta[[2]],partb[[2]],partc[[2]],partd[[2]],parte[[2]],partf[[2]]}, "sol"->{ parta[[3]],partb[[3]],partc[[3]],partd[[3]],parte[[3]],partf[[3]]}|>,InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{question, parta[[1]],partb[[1]],partc[[1]],partd[[1]],parte[[1]],partf[[1]]},{ parta[[2]],partb[[2]],partc[[2]],partd[[2]],parte[[2]],partf[[2]]}, { parta[[3]],partb[[3]],partc[[3]],partd[[3]],parte[[3]],partf[[3]]}}


(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution1=data1<>data2<>ToString[Hold[Module[{x, a,b,c,d,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,varse,varsf,g,h,pp,teste,bb1,list123,pos1,t11,t12,t21,t22,s1,s2,sum1,sum2,k},





varsa=vars[[1]];
varsb=vars[[2]];



(*
{aa,bb,cc,dd,ee,gg,pp}=varsa;
sol=Solve[ToExpression[bb]*x-ToExpression[cc]*(x-ToExpression[dd])==ToExpression[ee]-ToExpression[gg]*x,x];
*)


body={
{"",""

}, 
{Null ,Null} 
};


Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint1=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},  


body={ 
{""
},
{Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

Cloud Area

(* all err functions need to be called here since the Send is entirely happens in one unit *)
send[a0_]:=Module[{a,a1,b,b1,c,d,e,f,g,h,sol0,canvas0,err0,err,err2,err3,err4,err5,err6,err7,err8,err9,err10,resF,canvas,vars,sol,sol1,sol2,sol3,sol4,sol5,sol6,sol7,sol8,sol9,sol10,μ,σ,g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,h1,n,xbar,d1,d2,x,df,col, body={},text,string,string2,url,err1},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
ToExpression@libGraphics;
body={a0["id"]};

μ=0;σ=1;
{canvas,text,vars,sol}=ReleaseHold[ToExpression[a0["q"],InputForm]];
sol1=(ToExpression@sol)[[1]]; 
err=If[MemberQ[sol1[[1]],a0["x2" ]]==True, err1=1;"Correct",err1=0;"Incorrect"];

sol2=(ToExpression@sol)[[2]];
err=If[MemberQ[sol2[[1]],a0["x4" ]]==True, err2=1;"Correct",err2=0;"Incorrect"];

AppendTo[body, err1];
AppendTo[body, err2];

col={

Image[,ImageSize->125],
" ",
"F16 QMS 202",
"Practice Questions for Lecture 5\nFeb 2016",
Image[],
" ",
"Student ID:"<>a0["id"],
" ",
" ",
{a,b,c,d,string,string2}=ToExpression@vars[[1]];
ToExpression@text[[1+1]],
string,
"Your answers:",a0["x2"],
If[MemberQ[sol1[[1]],a0["x2" ]]==True, err=1;"is Correct",err=0;Style["is Incorrect",Red]],
\[SelectionPlaceholder],
" ",
Style["Use the following scenario for problems 2-5",Bold],
" ",
{a,b,c,d,string,e,f}=ToExpression@vars[[2]];
e,
Grid[Partition[ToExpression/@c,6],Frame->True],
f,
ToExpression@text[[1+2]],
string,
"Your answers:",a0["x4"],
If[MemberQ[sol2[[1]],a0["x4" ]]==True, err2=1;"is Correct",err2=0;Style["is Incorrect",Red]],

\[SelectionPlaceholder],

" ",

sol3=(ToExpression@sol)[[3]];
{a,b,c,d,string}=ToExpression@vars[[3]];
a1=(x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-(1-a))/2,{x}, Reals][[1]]);
ToExpression@text[[1+3]],
string,
"Your answers:",a0["x5"],
If[MemberQ[sol3[[1]],a0["x5" ]]==True, err3=1;"is Correct",err3=0;Style["is Incorrect",Red]],
\[SelectionPlaceholder],

" ",

sol4=(ToExpression@sol)[[4]];
{a,b,c,d,string,e}=ToExpression@vars[[4]];
ToExpression@text[[1+4]],
string,
"Your answers:",a0["x6"],
If[MemberQ[sol4[[1]],a0["x6" ]]==True, err4=1;"is Correct",err4=0;Style["is Incorrect",Red]], 

(*g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"t Distribution\n"<>"(Subscript[H, 0]) : μ ⩽ "<>ToString[c]<>"\n(Subscript[H, 1]) : μ > "<>ToString[c]<>"\n", PlotRange->Full,AxesOrigin->{0,0},Ticks->{{ToExpression@b},{None}}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,ToExpression@b,7},Filling->Axis,PlotLabel->"Normal Distribution", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green, FillingStyle->{Green}];
Show[g1,g2,Graphics[{
Dashed,Red,Line[{{-7,0.2},{ToExpression@b,0.2}}],Text[Style["Do not reject (Subscript[H, 0])",Medium,Bold],{-3,0.22}],
Green,Line[{{ToExpression@b,0.2},{7,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{5,0.22}],
Black,Line[{{ToExpression@b,0},{ToExpression@b,0.22}}],
Text[Style["(Subscript[t, STAT]) > "<>ToString@b,Medium,Bold],{5,0.1}],
Text[Style["(Subscript[t, STAT]) < "<>ToString@b,Medium,Bold],{-3,0.1}]
}],ImageSize->400],*)
\[SelectionPlaceholder],

" ",
sol5=(ToExpression@sol)[[5]];
{a,b,c,d,string,e,f,string2}=ToExpression@vars[[5]];
ToExpression@text[[1+5]],
string,
"Your answers:",a0["x7"],
If[MemberQ[sol5[[1]],a0["x7" ]]==True, err5=1;"is Correct",err5=0;Style["is Incorrect",Red]],

(*g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->Column[{Style["t Distribution",Bold],Grid[{{"(Subscript[t, STAT]) = \!\(\*FractionBox[\(\(\\ \)\(\*OverscriptBox[\(X\), \(_\)]\(-\)\(μ\)\(\\ \)\)\), FractionBox[\(S\), SqrtBox[\(n\)]]]\) = "<>ToString[d],"df = n-1"}},Frame->All],""},Alignment->Center], PlotRange->Full,AxesOrigin->{0,0},Ticks->{{ToExpression@d},None}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,ToExpression@d,7},Filling->Axis, PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Directive[Black,Dashed], FillingStyle->{Orange}];

h1=NSolve[CDF[StudentTDistribution[17],ToExpression@d]==1- (ToExpression@x),{x}, Reals];
h=x/.h1[[1]];

Show[g1,g2,Graphics[{
Dashed,
Black,Line[{{ToExpression@d,0},{ToExpression@d,0.28}}],
Text[Style["p-value = "<>ToString@h,Small,Bold],{5,0.09}],
Arrow[BezierCurve[{{5,0.08},{5,0.05},{ToExpression@d+1,0.01}}]],
Red,Text[Style["p-value > α\n⇓\nDo not reject (Subscript[H, 0])",Medium,Bold],{-5,0.28}],
Green,Text[Style["p-value < α\n⇓\nReject (Subscript[H, 0])",Medium,Bold],{5,0.28}]
}],ImageSize->400],*)
\[SelectionPlaceholder],
" ",
Style["Use the following scenario for problems 6-9",Bold],
" ",
sol6=(ToExpression@sol)[[6]];
{a,b,c,d,string,e,f}=ToExpression@vars[[6]];
f,
ToExpression@text[[1+6]],
string,
"Your answers:",a0["x8"],
If[MemberQ[sol6[[1]],a0["x8" ]]==True, err6=1;"is Correct",err6=0;Style["is Incorrect",Red]],
" "

 };
AppendTo[body,err3];
AppendTo[body,err4];
AppendTo[body,err5];
AppendTo[body,err6];

AppendTo[body,"Q5"];
AppendTo[body,"QMS202"];
AppendTo[body,"BOZA"];


url=CloudExport[Column@col,"PNG",Permissions->"Public"][[1]];

AppendTo[body,ToString@url];
resF=URLFetch["http://compclassnotes.com/trsm/qms202/api/ccnl/result","Parameters"->{"results"->(ToString@body)},"ReadTimeout"->10,"ConnectTimeout"->50,"Method"->"POST"];

 DatabinAdd[Databin["aqi3szEv"],body];

HTTPRedirect@url
];


(* all err functions need to be called here since the Send is entirely happens in one unit *)
sendLOCAL[a0_]:=Module[{a,a1,b,b1,c,d,e,f,g,h,sol0,canvas0,err0,err,err1,err2,err3,err4,err5,err6,err7,err8,err9,err10,resF,canvas,vars,sol,sol1,sol2,sol3,sol4,sol5,sol6,sol7,sol8,sol9,sol10,μ,σ,g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,h1,n,xbar,d1,d2,x,df,col, body={},text,string,string2},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
ToExpression@libGraphics;
body={a0["id"]};

μ=0;σ=1;
{canvas,text,vars,sol}=ReleaseHold[ToExpression[a0["q"],InputForm]];
sol1=(ToExpression@sol)[[1]]; 
err=If[MemberQ[sol1[[1]],a0["x2" ]]==True, err1=1;"Correct",err1=0;"Incorrect"];
sol2=(ToExpression@sol)[[2]];
err=If[MemberQ[sol2[[1]],a0["x4" ]]==True, err2=1;"Correct",err2=0;"Incorrect"];
(*err2=If[Abs[ToExpression@(a0["x4"])-sol2[[1]]]<0.01, 1, 0];*)

AppendTo[body, err1];
AppendTo[body, err2];

col={

Image[,ImageSize->125],
" ",
"F16 QMS 202",
"Practice Questions for Lecture 5\nJanuary 2016",
Image[],
" ",
"Student ID:"<>a0["id"],
" ",
" ",
{a,b,c,d,string,string2}=ToExpression@vars[[1]];
ToExpression@text[[1+1]],
string,
"Your answers:",a0["x2"],
If[MemberQ[sol1[[1]],a0["x2" ]]==True, err=1;"is Correct",err=0;Style["is Incorrect",Red]],
\[SelectionPlaceholder],
"",
Style["Use the following scenario for problems 2-5",Bold],
" ",
{a,b,c,d,string,e,f}=ToExpression@vars[[2]];
e,
Grid[Partition[ToExpression/@c,6],Frame->True],
f,
ToExpression@text[[1+2]],
string,
"Your answers:",a0["x4"],
If[MemberQ[sol2[[1]],a0["x4" ]]==True, err2=1;"is Correct",err2=0;Style["is Incorrect",Red]],
\[SelectionPlaceholder],
" ",

sol3=(ToExpression@sol)[[3]];
{a,b,c,d,string}=ToExpression@vars[[3]];
a1=(x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-(1-a))/2,{x}, Reals][[1]]);
ToExpression@text[[1+3]],
string,
"Your answers:",a0["x5"],
If[MemberQ[sol3[[1]],a0["x5" ]]==True, err3=1;"is Correct",err3=0;Style["is Incorrect",Red]],
\[SelectionPlaceholder],
" ",

sol4=(ToExpression@sol)[[4]];
{a,b,c,d,string,e}=ToExpression@vars[[4]];
ToExpression@text[[1+4]],
string,
"Your answers:",a0["x6"],
If[MemberQ[sol4[[1]],a0["x6" ]]==True, err4=1;"is Correct",err4=0;Style["is Incorrect",Red]],

(*g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"t Distribution\n"<>"(Subscript[H, 0]) : μ ⩽ "<>ToString[c]<>"\n(Subscript[H, 1]) : μ > "<>ToString[c]<>"\n", PlotRange->Full,AxesOrigin->{0,0},Ticks->{{ToExpression@b},{None}}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,ToExpression@b,7},Filling->Axis,PlotLabel->"Normal Distribution", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green, FillingStyle->{Green}];
Show[g1,g2,Graphics[{
Dashed,Red,Line[{{-7,0.2},{ToExpression@b,0.2}}],Text[Style["Do not reject (Subscript[H, 0])",Medium,Bold],{-3,0.22}],
Green,Line[{{ToExpression@b,0.2},{7,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{5,0.22}],
Black,Line[{{ToExpression@b,0},{ToExpression@b,0.22}}],
Text[Style["(Subscript[t, STAT]) > "<>ToString@b,Medium,Bold],{5,0.1}],
Text[Style["(Subscript[t, STAT]) < "<>ToString@b,Medium,Bold],{-3,0.1}]
}],ImageSize->400],*)
\[SelectionPlaceholder],
" ",
sol5=(ToExpression@sol)[[5]];
{a,b,c,d,string,e,f,string2}=ToExpression@vars[[5]];
ToExpression@text[[1+5]],
string,
"Your answers:",a0["x7"],
If[MemberQ[sol5[[1]],a0["x7" ]]==True, err5=1;"is Correct",err5=0;Style["is Incorrect",Red]],


(*g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->Column[{Style["t Distribution",Bold],Grid[{{"(Subscript[t, STAT]) = \!\(\*FractionBox[\(\(\\ \)\(\*OverscriptBox[\(X\), \(_\)]\(-\)\(μ\)\(\\ \)\)\), FractionBox[\(S\), SqrtBox[\(n\)]]]\) = "<>ToString[d],"df = n-1"}},Frame->All],""},Alignment->Center], PlotRange->Full,AxesOrigin->{0,0},Ticks->{{ToExpression@d},None}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,ToExpression@d,7},Filling->Axis, PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Directive[Black,Dashed], FillingStyle->{Orange}];

h1=NSolve[CDF[StudentTDistribution[17],ToExpression@d]==1- (ToExpression@x),{x}, Reals];
h=x/.h1[[1]];

Show[g1,g2,Graphics[{
Dashed,
Black,Line[{{ToExpression@d,0},{ToExpression@d,0.28}}],
Text[Style["p-value = "<>ToString@h,Small,Bold],{5,0.09}],
Arrow[BezierCurve[{{5,0.08},{5,0.05},{ToExpression@d+1,0.01}}]],
Red,Text[Style["p-value > α\n⇓\nDo not reject (Subscript[H, 0])",Medium,Bold],{-5,0.28}],
Green,Text[Style["p-value < α\n⇓\nReject (Subscript[H, 0])",Medium,Bold],{5,0.28}]
}],ImageSize->400],*)

\[SelectionPlaceholder],
" ",
Style["Use the following scenario for problems 6-9",Bold],
" ",

sol6=(ToExpression@sol)[[6]];
{a,b,c,d,string,e,f}=ToExpression@vars[[6]];
f,
ToExpression@text[[1+6]],
string,
"Your answers:",a0["x8"],
If[MemberQ[sol6[[1]],a0["x8" ]]==True, err6=1;"is Correct",err6=0;Style["is Incorrect",Red]],
" "

 };

AppendTo[body,err3];
AppendTo[body,err4];
AppendTo[body,err5];
AppendTo[body,err6];



local`body=Column@{body,col}
];





genFormLOCAL[]:=Module[{a,sol0,canvas0,err,resF,canvas,vars,sol,f,ans,text},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
f[]:=(ToString[ReleaseHold[ToExpression[StringReplace[variation1,{"canvasZ"->canvas1,"fghjkl"->ToString[1]}]]],InputForm]); (* InputForm must be here or some problems occurs in ToExpression@variation *)
ans={
{"x2",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F", "Help" -> ""|>,
{"x4",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"x5",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"x6",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"x7",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"x8",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>, 
{"id",""}-><|"Interpreter"->"String","Help" -> "","Hint"->"Enter Student ID"|>,
"q"->"String"};

FormFunction[ans,sendLOCAL,  AppearanceRules-><|"SubmitLabel" -> "Send Answers"|>,

FormLayoutFunction->Function[


(* we need to use sol in send[] in order to see if the student input is correct or not?*)

{canvas,text,vars,sol}=ReleaseHold[ToExpression[Setting@#["q"][[1]][[1]][[2]][[1]]]];

ReleaseHold[ToExpression[canvas,InputForm]/.{"x2"->#["x2"],"x4"->#["x4"],"x5"->#["x5"],"x6"->#["x6"],"x7"->#["x7"],"x8"->#["x8"],"id"->#["id"]}] 


], FormTheme -> "Blue"]["q"->f[]]






];

genForm[a0_]:=Module[{a,sol0,canvas0,err,resF,canvas,vars,sol,f,ans,text},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
f[]:=(ToString[ReleaseHold[ToExpression[StringReplace[variation1,{"canvasZ"->canvas1,"fghjkl"->ToString[1]}]]],InputForm]); (* InputForm must be here or some problems occurs in ToExpression@variation *)
ans={

{"x2",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F", "Help" -> ""|>,
{"x4",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"x5",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"x6",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"x7",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"x8",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"id",""}-><|"Interpreter"->"String","Help" -> "","Hint"->"Enter Student ID"|>,
"q"->"String"};

HTTPRedirect@CloudDeploy[FormFunction[ans,send,  AppearanceRules-><|"SubmitLabel" -> "Send Answers"|>,

FormLayoutFunction->Function[


(* we need to use sol in send[] in order to see if the student input is correct or not?*)

{canvas,text,vars,sol}=ReleaseHold[ToExpression[Setting@#["q"][[1]][[1]][[2]][[1]]]];

ReleaseHold[ToExpression[canvas,InputForm]/.{"x2"->#["x2"],"x4"->#["x4"],"x5"->#["x5"],"x6"->#["x6"],"x7"->#["x7"],"x8"->#["x8"],"id"->#["id"]}]


], FormTheme -> "Blue"]["q"->f[]], 

Permissions->"Public"][[1]]







];

Deploy Area

DeleteFile[c];
c=CloudDeploy[FormFunction[{},
genForm,  AppearanceRules-><|"SubmitLabel" -> "Start"|>,

FormLayoutFunction->Function[


(* we need to use sol in send[] in order to see if the student input is correct or not?*)

Column[{Image[,ImageSize->125],
Spacer@100,
"F16 QMS 202",
"Practice Questions for Lecture 5\nFeb 2016",
Image[,ImageSize->5],
Spacer@100,

"Press Start button to start the test"
}]


], FormTheme -> "White"], 

Permissions->"Public"]

Last version OKed by Anna:

LOCAL TEST AREA

The local form is slow, take a second to refresh the input fields. Also the Send Answer Button might not chave colour properly.

genFormLOCAL[]

local`body

DATA BIN  AREA

$Permissions = "Public"

Date of Creation

DateString[]

binQ1=CreateDatabin[<|"Name"->"Q4, QMS202, BOZA"|>]
Options[binQ1]

Databin["aqi3szEv"]

DatabinRemove[Databin["aqi3szEv"],{1,10}]

ARCHIVE DATA BIN

New Location

ON

$Permissions = "Public";
on[]:=Module[{},CloudSymbol["Q4QMS202"]=1;SetPermissions[CloudObject[MouseOver], "Public"]];
CloudDeploy[

APIFunction[{},on[]&],Permissions->"Public"]

Off

$Permissions = "Public";
off[]:=Module[{},CloudSymbol["Q4QMS202"]=0;SetPermissions[CloudObject[MouseOver], "Private"]];
CloudDeploy[

APIFunction[{},off[]&],Permissions->"Public"]

CloudDeploy[
APIFunction[{},CloudSymbol["Q4QMS202"]&],Permissions->"Public"]

Statistics Report

f[date_]:=Module[{grades,mean},grades=Values[Databin["aqi3szEv"]][[All,2;;7]];

If[grades!={},
grades=Table[If[NumberQ[#]&/@grades[[i]]=={True,True,True,True,True,True},grades[[i]],Nothing], {i,1,Length@grades}],grades={{0,0,0,0,0,0}}];
mean=Mean@grades;
PieChart3D[N@mean, ChartLabels->Range[6],LabelingFunction->"VerticalCallout",PlotLabel->"QMS202, Quiz4\nProf Tasic\n"<>date,ImageSize->400]]

InputForm[CloudDeploy[Delayed[f[DateString[]]], Permissions->"Public"][[1]]]