Skip to content
Permalink
Browse files

by copy restore model solution

this one's good now
  • Loading branch information...
CorySanin committed Jan 21, 2019
1 parent 4e1627e commit c213ba19cc10f169bd1650a361b43ecc610f91f9
Showing with 119 additions and 18 deletions.
  1. +119 −18 AV/PL/paramPassingCopyRestorePRO.js
@@ -3,7 +3,7 @@
$(document).ready(function () {
// Relative offsets
var leftMargin = 25;
var topMargin = 200;
var topMargin = 250;
var currentTopMargin = 0;
var currentFooTopMargin;
var labelMargin = 10;
@@ -116,34 +116,95 @@ $(document).ready(function () {

// Process About button: Pop up a message with an Alert
function about() {
alert(ODSA.AV.aboutstring(interpret(".avTitle"), interpret("av_Authors")));
alert(ODSA.AV.aboutstring('Copy-Restore proficiency exercise', 'Cory Sanin'));
}

// generates the model answer
function modelSolution(modeljsavAV) {
var currentTopMargin = 0;
var topMargin = 0;
var fooVars = {};
var classVars = {};
var mainVars = {};
var cprVars = {};
var labelobj;
var currentLine = fooIndex;
mainSteps = 0;
function unhighlightAll(){
unhighlightElements(classVars);
unhighlightElements(mainVars);
unhighlightElements(fooVars);
}

var pseudo = modeljsavAV.code(codeLines,
{left: leftMargin, top: topMargin, lineNumbers: false}
);
jsavElements.push(pseudo);

//run foo()
for(var arr in initialArrays.fooVars){
fooVars[arr] = modeljsavAV.ds.array(initialArrays.fooVars[arr]);
jsavElements.push(fooVars[arr]);
}
for(arr in initialArrays.classVars){
classVars[arr] = modeljsavAV.ds.array(initialArrays.classVars[arr]);
jsavElements.push(classVars[arr]);
labelobj = modeljsavAV.label(arr,
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin, top: currentTopMargin
}
);
classVars[arr] = modeljsavAV.ds.array(initialArrays.classVars[arr],
{
indexed: initialArrays.classVars[arr].length > 1,relativeTo:labelobj, anchor:"right top",
myAnchor:"left top", left: labelMargin,
top:-1*jsavArrayOffset
}
);
jsavElements.push(classVars[arr], labelobj);
currentTopMargin += lineHeight;
}

jsavElements.push(modeljsavAV.label("main",
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin, top: currentTopMargin
}
));
var fooLabel = modeljsavAV.label("foo",
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin+boxWidth+boxPadding*2, top: currentTopMargin
}
);
jsavElements.push(fooLabel);

currentTopMargin += lineHeight;

var numVars = Object.keys(initialArrays.fooVars).length;

jsavElements.push(modeljsavAV.g.rect(2*leftMargin+pseudo.element[0].clientWidth,
currentTopMargin+topMargin,
boxWidth,
lineHeight*numVars+boxPadding*numVars
));
jsavElements.push(modeljsavAV.g.rect(2*leftMargin+pseudo.element[0].clientWidth+boxWidth+
boxPadding*2,
currentTopMargin+topMargin,
boxWidth,
lineHeight*numVars+boxPadding*numVars
));

for(arr in initialArrays.mainVars){
mainVars[arr] = modeljsavAV.ds.array(initialArrays.mainVars[arr]);
jsavElements.push(mainVars[arr]);
labelobj = modeljsavAV.label(arr,
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin+3, top: currentTopMargin
}
);
mainVars[arr] = modeljsavAV.ds.array(initialArrays.mainVars[arr],
{
indexed: initialArrays.mainVars[arr].length > 1,relativeTo:labelobj, anchor:"right top",
myAnchor:"left top", left: labelMargin,
top:-1*jsavArrayOffset
}
);
jsavElements.push(mainVars[arr], labelobj);
}
for(var arr in initialArrays.cprVars){
if(arr.length > 1){
@@ -154,13 +215,46 @@ $(document).ready(function () {
cprVars[arr] = ((split[0]==='mainVars')?mainVars:classVars)[split[1]];
}
}
for(var arr in initialArrays.fooVars){
labelobj = modeljsavAV.label(arr,
{
relativeTo:pseudo, anchor:"right top", myAnchor:"left top",
left: leftMargin+boxWidth+10*boxPadding, top: currentTopMargin
}
);
fooVars[arr] = modeljsavAV.ds.array(initialArrays.fooVars[arr],
{
indexed: initialArrays.fooVars[arr].length > 1,relativeTo:labelobj, anchor:"right top",
myAnchor:"left top", left: labelMargin,
top:-1*jsavArrayOffset
}
);
jsavElements.push(fooVars[arr], labelobj);

labelobj = modeljsavAV.pointer(arr,fooVars[arr],{
targetIndex: 0,
fixed: true,
left: (leftMargin * -1.75),
top: 8,
anchor: 'left center'
})
labelobj.target(cprVars[arr],{
targetIndex: cprVars[arr+'-index'],
arrowAnchor: ((initialArrays.cprVars[arr].split(':')[0] == 'mainVars')?'right center':'center bottom')
})
jsavElements.push(labelobj);

currentTopMargin += lineHeight;
}
pseudo.setCurrentLine(++currentLine);

modeljsavAV.displayInit();

var contexts = [fooVars,classVars];
currentLineFoo = fooIndex;
while(codeLines[currentLineFoo].indexOf('print') === -1){
unhighlightAll();
pseudo.setCurrentLine(currentLine++);
var split = codeLines[currentLineFoo].trim().split('=');

var rhs = getRightSideValue([fooVars, classVars], codeLines[currentLineFoo++]);
@@ -193,6 +287,8 @@ $(document).ready(function () {

unhighlightAll();

pseudo.setCurrentLine(mainIndex+2);

for(var fooVar in fooVars){
cprVars[fooVar].highlight(cprVars[fooVar+'-index']);
cprVars[fooVar].value(cprVars[fooVar+'-index'],fooVars[fooVar].value(0));
@@ -333,9 +429,7 @@ $(document).ready(function () {

for(var i=0; i<fooPassedIn.length; i++){
fooPassedInValues.push(getValueOfVar([mainVars, classVars], fooPassedIn[i])['value']);
}

for(var i=0; i<fooPassedIn.length; i++){
var target;
var pIndex = 0;
if(fooPassedIn[i] in mainVars){
@@ -348,11 +442,6 @@ $(document).ready(function () {
getIndexFromString(fooPassedIn[i])
)['value']
}
fooLabels[fooVarNames[i]] = av.pointer(fooVarNames[i],target,{
targetIndex: pIndex,
left: lineHeight
})
jsavElements.push(fooLabels[fooVarNames[i]]);
cprVars[fooVarNames[i]] = target;
cprVars[fooVarNames[i] + '-index'] = pIndex;
cprVars[fooVarNames[i] + '-classvar'] = !(fooPassedIn[i] in mainVars);
@@ -363,7 +452,7 @@ $(document).ready(function () {
left: leftMargin+boxWidth+10*boxPadding, top: currentFooTopMargin
}
);
jsavElements.push(fooLabels[fooVarNames[i]])
jsavElements.push(fooLabels[fooVarNames[i]]);
fooVars[fooVarNames[i]] = av.ds.array([fooPassedInValues[i]],
{
indexed: false,relativeTo:fooLabels[fooVarNames[i]], anchor:"right top",
@@ -373,6 +462,18 @@ $(document).ready(function () {
);
jsavElements.push(fooVars[fooVarNames[i]])

fooLabels[fooVarNames[i]] = av.pointer(fooVarNames[i],fooVars[fooVarNames[i]],{
targetIndex: 0,
fixed: true,
left: (leftMargin * -1.75),
top: 8,
anchor: 'left center'
})
fooLabels[fooVarNames[i]].target(target,{
targetIndex: pIndex,
arrowAnchor: ((i==1)?'center bottom':'right center')
})

initialArrays.cprVars[fooVarNames[i]] = ((fooPassedIn[i] in mainVars)?'mainVars':'classVars')+':'+fooPassedIn[i].charAt(0);
initialArrays.cprVars[fooVarNames[i]+'-index'] = pIndex;
initialArrays.fooVars[fooVarNames[i]] = [fooPassedInValues[i]];

0 comments on commit c213ba1

Please sign in to comment.
You can’t perform that action at this time.