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"; (*Anna i added here slidingPlot for distributions*)

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. For the hypothesis (Subscript[H, 0]) : μ = #a, (Subscript[H, 1]) : μ ≠ #a, and for a sample of a fixed n, why is β smaller if the actual value of μ is #b than if the actual value μ is #c? Is the following statement correct?\",TraditionalForm]"<>"}]"}
|>
,
"2"-><|

"2.1"->{"Column[{ToString[\"2. What is the p-value, if in a two tail hypothesis test (Subscript[Z, STAT]) = #a\",TraditionalForm]"<>"}, Alignment->Left]"}
|>

,
"3"-><|
"3.1"->{"Column[{ToString[\"3. What is your statistical decision if you test the null hypothesis at the #a level of significance in the problem above? Is the following statement correct?\"]}]"}

|>
,

"4"-><|
"4.1"->{"Column[{ToString[\"4. A company that sells a brand of soft drink with a label of #a ml is suspected of cheating its customers. The consumers understand that it is not necessary that every can contain #a ml, but the average should be close to #a ml. They believe that the average amount in the cans is not close to #a ml. A group of concerned consumers has approached a consumer advocate who has found that the bottling process that fills this type of can has a standard deviation of #b ml and the volume of soft drink in the cans will fit a normal distribution. To obtain evidence, a sample of #c cases of #d cans was measured carefully and the mean volume was found to be #e ml. Is the formula below an appropriate alernative hypothesis?\"]"<>"}]"
}
|>
,
"5"-><|
"5.1"->{"Column[{ToString[\"5. A company that sells a brand of soft drink with a label of #a ml is suspected of cheating its customers. The consumers understand that it is not necessary that every can contain #a ml, but the average should be close to #a ml. They believe that the average amount in the cans is not close to #a ml. A group of concerned consumers has approached a consumer advocate who has found that the bottling process that fills this type of can has a standard deviation of #b ml and the volume of soft drink in the cans will fit a normal distribution. To obtain evidence, a sample of #c cases of #d cans was measured carefully and the mean volume was found to be #e ml. Is statistical decision below correct?\"]"<>"}]"}
|>
,
"6"-><|
"6.1"->{"Column[{ToString[\"6. A company that sells a brand of soft drink with a label of #a ml is suspected of cheating its customers. The consumers understand that it is not necessary that every can contain #a ml, but the average should be close to #a ml. They believe that the average amount in the cans is not close to #a ml. A group of concerned consumers has approached a consumer advocate who has found that the bottling process that fills this type of can has a standard deviation of #b ml and the volume of soft drink in the cans will fit a normal distribution. To obtain evidence, a sample of #c cases of #d cans was measured carefully and the mean volume was found to be #e ml. Does this evidence support the claim of the consumers at 5% level of significance? Answer true or false.\"]"<>"}]"}
|>

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



data2="listfghjkl:="<>


ToString[{"",""


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

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



canvas1="\n"<>ToString[Hold[Module[{vars=ertyuiop,text,text2,text3,text4,text5,text6,answers, options,locs,data},


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

{Image[,ImageSize->125]},
{Image[]},   
{"Quiz 3,January 2016"},
{Image[]},
{"id"},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[2]]}}]},
{Image[]},
text2=vars["vars"][[1]][[5]];
{Grid[{{Rasterize@ToExpression@text2}}]},
{Image[]},
{Grid[{{"x2"}}]}, 
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[3]]}}]},
{Image[]},
{Grid[{{Rasterize@" p-value = ","x4"}}]},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[4]]}}]},
{Image[]},
text5=vars["vars"][[3]][[5]];
{Grid[{{Rasterize@ToExpression@text5}}]},
{Image[]},
{Grid[{{"x5"}}]},

{Image[]},
{Image[]},
text3=vars["vars"][[4]][[5]];
{Grid[{{Rasterize@ToExpression@text[[5]]}}]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text3}}]},
{Image[]},
{Grid[{{"x6"}}]},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[6]]}}]},
{Image[]},
text6=vars["vars"][[5]][[5]];
{Grid[{{Rasterize@ToExpression@text6}}]},
{Image[]},
{Grid[{{"x7"}}]},
{Image[]},
{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,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp, vars,text,list,sol,aabbee,k, parta, partb, partc, partd,parte,partf,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[{100,112}]);
b=ToString@RandomInteger[{60,75}];
c=ToString@RandomInteger[{85,95}];
d=ToString@RandomInteger[{79,83}];


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

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

{StringReplace["If all other things are fixed, since #b<#c the β corresponding to the actual value #b is smaller than the β corresponding to the actual value #c.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["If all other things are fixed, the closer the hypothesized mean is to the actual mean, the larger the risk of committing a Type II error will be.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"T\"","\"true\"","\"TRUE\""}},

{StringReplace["The question can not be answered because we do not know the level of significance α.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}}
};



vars={a,b,c,d,ToString[list[[1]],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", 

a=ToString@N[RandomInteger[{10,25}]/10];
b=ToString@0;
c=ToString@0;
d=ToString@0;

vars={a,b,c,d};


sol={1-x/.NSolve[CDF[NormalDistribution[0,1],ToExpression@a]==1- (1-x)/2,{x}, Reals][[1]]}; (*anna*)

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=ToString@0;
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["Reject (Subscript[H, 0])", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],
{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["Accept (Subscript[H, 1])",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["Reject (Subscript[H, 1])",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["Do not reject (Subscript[H, 0])",{ "#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,e}=ToString/@RandomChoice[{{330,329.5},{335,334.5},{340,339.5},{345,344.5},{350,349.5},{355,354.5},{360,359.5}}];
{b,f}=ToString/@RandomChoice[{{2,RandomChoice@(Table[i,{i,70,90,2}])},{3,RandomChoice@(Table[i,{i,150,210,10}])}}];
c=ToString@Which[(ToExpression@b)==2,If[Mod[ToExpression@f,4]==0,4,2],(ToExpression@b)==3,RandomChoice@{2,5,10}];
d=ToString@IntegerPart[ToExpression@ToString@((ToExpression@f)/(ToExpression@c))];


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

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

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

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

{StringReplace["(Subscript[H, 1]) : μ ≠ #a ml",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"T\"","\"true\"","\"TRUE\""}}
};



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", 

{a,b,c,d,pp,e}=partd[[2]];
(* For any String for sol we need to double quote or some confusing bug shows up*)
list=RandomChoice@{

{StringReplace["At α=0.01 reject (Subscript[H, 0]).", { "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],
{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["At α=0.05 do not reject (Subscript[H, 0]).",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["At α=0.01 accept (Subscript[H, 1]).",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["At α=0.01 do not reject (Subscript[H, 0]).",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"T\"","\"true\"","\"TRUE\""}},
{StringReplace["At α=0.05 reject (Subscript[H, 0]).",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"T\"","\"true\"","\"TRUE\""}}
};



vars={a,b,c,d,ToString[list[[1]],InputForm],e};
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]];


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

{StringReplace["It can not be answered because we do not know (Subscript[Z, STAT]).", { "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],
{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["The evidence does not support the consumer's claim.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"False\"","\"false\"","\"FALSE\"","\"F\""}},

{StringReplace["The evidence supports the consumer's claim.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],{"\"T\"","\"true\"","\"TRUE\""}}
};



vars={a,b,c,d,ToString[list[[1]],InputForm],e};
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,err,err2,err3,err4,err5,err6,resF,canvas,vars,sol,sol1,sol2,sol3,sol4,sol5,sol6,μ,σ,g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,n,xbar,d1,d2,x,df,col, body={},text,string,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]];
err2=If[Abs[ToExpression@(a0["x4"])-sol2[[1]]]<0.01, 1, 0];
{a,b,c,d}=ToExpression@vars[[2]];
g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"p_value = "<>ToString[sol2[[1]]], PlotRange->Full,AxesOrigin->{0,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,-a},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"p_value = "<>ToString[sol2[[1]]], PlotRange->Full,AxesOrigin->{0,0},FillingStyle->{Red}];
g3=Plot[PDF[NormalDistribution[μ,σ],x],{x,a,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"p_value = "<>ToString[sol2[[1]]], PlotRange->Full,AxesOrigin->{0,0},FillingStyle->{Red}];


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

col={

Image[,ImageSize->125],
" ",
"F16 QMS 202",
"Practice Questions for Lecture 3\nJanuary 2016",
Image[],
" ",
"Student ID:"<>a0["id"],
" ",
" ",
{a,b,c,d,string}=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;"is Incorrect"],
slidingPLOT[15,a,c,b,d,5.4],
\[SelectionPlaceholder],
" ",
ToExpression@text[[1+2]],

If[err2==1, "Correct", Style["Incorrect",Red]],"Your answers:",Row@{a0["x4"]},"Solutions:",Row@{sol2[[1]]},
Show[g1,g2,g3,ImageSize->400],
\[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;"is Incorrect"],
{e,f,g,h}=ToExpression@vars[[2]];
g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution", PlotRange->Full,AxesOrigin->{0,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,-a1},Filling->Axis,PlotLabel->"Normal Distribution", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green,FillingStyle->{Green}];
g3=Plot[PDF[NormalDistribution[μ,σ],x],{x,a1,7},Filling->Axis,PlotLabel->"Normal Distribution", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green, FillingStyle->{Green}];
(*Show[g1,g2,g3,Graphics[{PointSize[0.02],Point[{e,0},VertexColors->Red]}],ImageSize->400],*)
Show[g1,g2,g3,Graphics[{
PointSize[0.02],Point[{e,0},VertexColors->Blue],
Dashed,Red,Line[{{-a1,0.2},{a1,0.2}}],Text[Style["Do not reject (Subscript[H, 0])",Medium,Bold],{0,0.22}],
Green,Line[{{-7,0.2},{-a1,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{-5,0.22}],
Green,Line[{{a1,0.2},{7,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{5,0.22}],
Black,Line[{{-a1,0},{-a1,0.3}}],
Black,Line[{{a1,0},{a1,0.3}}],
Text[Style["(Subscript[Z, STAT])",Medium,Bold],{e,0.03}]
}],ImageSize->400],
\[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]], 
\[SelectionPlaceholder],

" ",
sol5=(ToExpression@sol)[[5]];
{a,b,c,d,string,e}=ToExpression@vars[[5]];
f=N[(e-a)/(b/Sqrt[c*d])];
a1=(x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-(1-0.01))/2,{x}, Reals][[1]]);
b1=(x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-(1-0.05))/2,{x}, Reals][[1]]);
ToExpression@text[[1+5]],
string,
"Your answers:",a0["x7"],
If[MemberQ[sol5[[1]],a0["x7" ]]==True, err5=1;"is Correct",err5=0;"is Incorrect"],
g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.01", PlotRange->Full,AxesOrigin->{0,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,-a1},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.01", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green,FillingStyle->{Green}];
g3=Plot[PDF[NormalDistribution[μ,σ],x],{x,a1,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.01", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green, FillingStyle->{Green}];
Show[g1,g2,g3,Graphics[{
PointSize[0.02],Point[{f,0},VertexColors->Blue],
Dashed,Red,Line[{{-a1,0.2},{a1,0.2}}],Text[Style["Do not reject (Subscript[H, 0])",Medium,Bold],{0,0.22}],
Green,Line[{{-7,0.2},{-a1,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{-5,0.22}],
Green,Line[{{a1,0.2},{7,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{5,0.22}],
Black,Line[{{-a1,0},{-a1,0.3}}],
Black,Line[{{a1,0},{a1,0.3}}],
Text[Style["(Subscript[Z, STAT])",Medium,Bold],{f,0.03}]
}],ImageSize->400],
g4=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.05", PlotRange->Full,AxesOrigin->{0,0}];

g5=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,-b1},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.05", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green,FillingStyle->{Green}];
g6=Plot[PDF[NormalDistribution[μ,σ],x],{x,b1,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.05", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green, FillingStyle->{Green}];
Show[g4,g5,g6,Graphics[{
PointSize[0.02],Point[{f,0},VertexColors->Blue],
Dashed,Red,Line[{{-b1,0.2},{b1,0.2}}],Text[Style["Do not reject (Subscript[H, 0])",Medium,Bold],{0,0.22}],
Green,Line[{{-7,0.2},{-b1,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{-5,0.22}],
Green,Line[{{b1,0.2},{7,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{5,0.22}],
Black,Line[{{-b1,0},{-b1,0.3}}],
Black,Line[{{b1,0},{b1,0.3}}],
Text[Style["(Subscript[Z, STAT])",Medium,Bold],{f,0.03}]
}],ImageSize->400],

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

 };

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

AppendTo[body,"Q3"];
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["a8YmnpoA"],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,err,err2,err3,err4,err5,err6,resF,canvas,vars,sol,sol1,sol2,sol3,sol4,sol5,sol6,μ,σ,g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,n,xbar,d1,d2,x,df,col, body={},text,string},

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, err=1;"Correct",err=0;"Incorrect"];
sol2=(ToExpression@sol)[[2]];
err2=If[Abs[ToExpression@(a0["x4"])-sol2[[1]]]<0.01, 1, 0];
{a,b,c,d}=ToExpression@vars[[2]];
g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"p_value = "<>ToString[sol2[[1]]], PlotRange->Full,AxesOrigin->{0,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,-a},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"p_value = "<>ToString[sol2[[1]]], PlotRange->Full,AxesOrigin->{0,0},FillingStyle->{Red}];
g3=Plot[PDF[NormalDistribution[μ,σ],x],{x,a,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"p_value = "<>ToString[sol2[[1]]], PlotRange->Full,AxesOrigin->{0,0},FillingStyle->{Red}];

AppendTo[body, err];
AppendTo[body, err2];

col={

Image[,ImageSize->125],
" ",
"F16 QMS 202",
"Practice Questions for Lecture 3\nJanuary 2016",
Image[],
" ",
"Student ID:"<>a0["id"],
" ",
" ",
{a,b,c,d,string}=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;"is Incorrect"],
slidingPLOT[15,a,c,b,d,5.4],
\[SelectionPlaceholder],
" ",
ToExpression@text[[1+2]],

If[err2==1, "Correct", "Incorrect"],"Your answers:",Row@{a0["x4"]},"Solutions:",Row@{sol2[[1]]},
Show[g1,g2,g3,ImageSize->400],
\[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;"is Incorrect"],
{e,f,g,h}=ToExpression@vars[[2]];
g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution", PlotRange->Full,AxesOrigin->{0,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,-a1},Filling->Axis,PlotLabel->"Normal Distribution", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green,FillingStyle->{Green}];
g3=Plot[PDF[NormalDistribution[μ,σ],x],{x,a1,7},Filling->Axis,PlotLabel->"Normal Distribution", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green, FillingStyle->{Green}];
(*Show[g1,g2,g3,Graphics[{PointSize[0.02],Point[{e,0},VertexColors->Red]}],ImageSize->400],*)
Show[g1,g2,g3,Graphics[{
PointSize[0.02],Point[{e,0},VertexColors->Blue],
Dashed,Red,Line[{{-a1,0.2},{a1,0.2}}],Text[Style["Do not reject (Subscript[H, 0])",Medium,Bold],{0,0.22}],
Green,Line[{{-7,0.2},{-a1,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{-5,0.22}],
Green,Line[{{a1,0.2},{7,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{5,0.22}],
Black,Line[{{-a1,0},{-a1,0.3}}],
Black,Line[{{a1,0},{a1,0.3}}],
Text[Style["(Subscript[Z, STAT])",Medium,Bold],{e,0.03}]
}],ImageSize->400],
\[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;"is Incorrect"],

\[SelectionPlaceholder],
" ",
sol5=(ToExpression@sol)[[5]];
{a,b,c,d,string,e}=ToExpression@vars[[5]];
f=N[(e-a)/(b/Sqrt[c*d])];
a1=(x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-(1-0.01))/2,{x}, Reals][[1]]);
b1=(x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-(1-0.05))/2,{x}, Reals][[1]]);
ToExpression@text[[1+5]],
string,
"Your answers:",a0["x7"],
If[MemberQ[sol5[[1]],a0["x7" ]]==True, err5=1;"is Correct",err5=0;"is Incorrect"],
g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.01", PlotRange->Full,AxesOrigin->{0,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,-a1},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.01", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green,FillingStyle->{Green}];
g3=Plot[PDF[NormalDistribution[μ,σ],x],{x,a1,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.01", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green, FillingStyle->{Green}];
Show[g1,g2,g3,Graphics[{
PointSize[0.02],Point[{f,0},VertexColors->Blue],
Dashed,Red,Line[{{-a1,0.2},{a1,0.2}}],Text[Style["Do not reject (Subscript[H, 0])",Medium,Bold],{0,0.22}],
Green,Line[{{-7,0.2},{-a1,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{-5,0.22}],
Green,Line[{{a1,0.2},{7,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{5,0.22}],
Black,Line[{{-a1,0},{-a1,0.3}}],
Black,Line[{{a1,0},{a1,0.3}}],
Text[Style["(Subscript[Z, STAT])",Medium,Bold],{f,0.03}]
}],ImageSize->400],
g4=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.05", PlotRange->Full,AxesOrigin->{0,0}];

g5=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,-b1},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.05", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green,FillingStyle->{Green}];
g6=Plot[PDF[NormalDistribution[μ,σ],x],{x,b1,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"α = 0.05", PlotRange->Full,AxesOrigin->{0,0},PlotStyle->Green, FillingStyle->{Green}];
Show[g4,g5,g6,Graphics[{
PointSize[0.02],Point[{f,0},VertexColors->Blue],
Dashed,Red,Line[{{-b1,0.2},{b1,0.2}}],Text[Style["Do not reject (Subscript[H, 0])",Medium,Bold],{0,0.22}],
Green,Line[{{-7,0.2},{-b1,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{-5,0.22}],
Green,Line[{{b1,0.2},{7,0.2}}],Text[Style["Reject (Subscript[H, 0])",Medium,Bold],{5,0.22}],
Black,Line[{{-b1,0},{-b1,0.3}}],
Black,Line[{{b1,0},{b1,0.3}}],
Text[Style["(Subscript[Z, STAT])",Medium,Bold],{f,0.03}]
}],ImageSize->400],
\[SelectionPlaceholder],
" ",

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

 };

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" -> "",  "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"]}] (*Anna: removed x1*)


], 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" -> "",  "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"]}](*Anna*)


], 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 3\nJanuary 2016",
Image[,ImageSize->5],
Spacer@100,

"Press Start button to start the test"
}]


], FormTheme -> "White"], 

Permissions->"Public"]

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"->"Q3, QMS202, BOZA"|>]
Options[binQ1]

Databin["a8YmnpoA"]

DatabinRemove[Databin["a8YmnpoA"],{1,101}]

ARCHIVE DATA BIN

New Location

ON-Off

ON

$Permissions = "Public";
CloudDeploy[

APIFunction[{},SetPermissions[CloudObject[MouseOver], "Public"]&],Permissions->"Public"]

Off

$Permissions = "Public";
CloudDeploy[

APIFunction[{},SetPermissions[CloudObject[MouseOver], "Private"]&],Permissions->"Public"]

Statistics Report

f[date_]:=Module[{grades,mean},grades=Values[Databin["9UnJLEno"]][[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, Quiz1\nProf Tasic\n"<>date,ImageSize->400]]

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