Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Marielle committed Mar 6, 2024
2 parents 5c5d74c + e7bb3cc commit 090069a
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 76 deletions.
2 changes: 1 addition & 1 deletion ext/codecast/7.4/index.js

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions pemFioi/assortElements-1.0.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
function AssortElements(params) {
let { paper, elemW, elemH, elements, dropZones, attr, dropCallback, ordered, displayHelper } = params;
let { paper, elemW, elemH, elements, dropZones, attr, dropCallback, ordered, ghostBackOpacity, drawElement, displayHelper } = params;
let zoneIDs = [];
let elementsObject = {};

this.dragAndDrop;
this.test = 3;
drawElement = drawElement || defaultDrawElement;
let self = this;
init();

Expand Down Expand Up @@ -37,17 +38,22 @@ function AssortElements(params) {
}
},
actionIfDropped : function(srcCont, srcPos, dstCont, dstPos, dropType) {
let id = this.getObjects(srcCont)[srcPos];
// console.log(id)
if(!ordered && zoneIDs.includes(dstCont)){
let currObj = this.getObjects(dstCont);
for(var pos = 0; pos <= dstPos; pos++){
if(currObj[pos] == null){
if(srcCont == dstCont){
return DragAndDropSystem.action(dstCont,pos - 1,'replace');
}

return DragAndDropSystem.action(dstCont,pos,'replace');
}
}
}else if(dstCont == null){
return DragAndDropSystem.action(id,0,'replace');
}else if(!zoneIDs.includes(dstCont)){
return false
}
return true
},
Expand All @@ -67,6 +73,9 @@ function AssortElements(params) {
let cx = elem.pos.x + w/2;
let cy = elem.pos.y + h/2;
let background = (attr.srcCont) ? paper.rect(-w/2,-h/2,w,h).attr(attr.srcCont) : null;
if(ghostBackOpacity){
background = drawElement(elem,0,0).attr("opacity",ghostBackOpacity);
}
self.dragAndDrop.addContainer({
ident: id, cx, cy,
widthPlace : w,
Expand Down Expand Up @@ -125,7 +134,7 @@ function AssortElements(params) {
}
};

function drawElement(elem,cx,cy) {
function defaultDrawElement(elem,cx,cy) {
let w = elemW, h = elemH;
let x = cx - w/2;
let y = cy - h/2;
Expand Down
5 changes: 4 additions & 1 deletion pemFioi/graph-mouse-1.4.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ function VertexDragAndConnect(settings) {
}

this.startHandler = function(x, y, event) {
// console.log("startHandler")
if(self.unselectAllEdges){
self.unselectAllEdges();
}
Expand Down Expand Up @@ -2827,11 +2828,13 @@ function GraphEditor(settings) {
});
};

this.writeContent = function(id) {
this.writeContent = function(id,cont) {
// console.log(id);
var info = graph.getVertexInfo(id);
var oldContent = info.content || "";
var newContent = (self.textEditor) ? self.textEditor.val().trim() : "";
if(cont)
newContent = cont;

var raphElement = visualGraph.getRaphaelsFromID(id);
if(oldContent !== newContent){
Expand Down
75 changes: 55 additions & 20 deletions pemFioi/quickpi/blocklyQuickPi_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -3657,7 +3657,7 @@ var getContext = function (display, infos, curLevel) {
if (area < 218700)
{
context.compactLayout = true;
}
}

if (context.sensorDivisions) {
context.sensorDivisions.remove();
Expand Down Expand Up @@ -3801,6 +3801,9 @@ var getContext = function (display, infos, curLevel) {
geometry = squareSize(paper.width, paper.height, nSensors, 2);
else
geometry = squareSize(paper.width, paper.height, nSensors, 1);

// console.log(geometry)
var cellW = paper.width / geometry.rows;

context.sensorSize = geometry.size * .10;

Expand All @@ -3822,7 +3825,7 @@ var getContext = function (display, infos, curLevel) {
});

for (var row = 0; row < geometry.rows; row++) {
var x = paper.width / geometry.rows * row;
var x = cellW * row;
var y1 = y + geometry.size / 4;
var y2 = y + geometry.size * 3 / 4;
var cells = 1;
Expand Down Expand Up @@ -3902,8 +3905,9 @@ var getContext = function (display, infos, curLevel) {
sensor.drawInfo = {
x: x,
y: y,
width: (paper.width / geometry.rows) * cells,
height: geometry.size
width: cellW * cells,
height: geometry.size,
// cellW: cellW
}

drawSensor(sensor);
Expand Down Expand Up @@ -6487,6 +6491,13 @@ var getContext = function (display, infos, curLevel) {
state1y = imgy;
stateanchor = 'start';
}
if(sensor.type == "buzzer"){
var sizeRatio = imgw/sensor.drawInfo.width;
if(sizeRatio > 0.75){
imgw = 0.75*sensor.drawInfo.width;
imgh = imgw;
}
}


var portx = state1x;
Expand All @@ -6504,6 +6515,9 @@ var getContext = function (display, infos, curLevel) {
var statesize = sensor.drawInfo.height * 0.10;

var namesize = sensor.drawInfo.height * 0.15;

var maxNameSize = 25;
var maxStateSize = 20;



Expand All @@ -6512,17 +6526,18 @@ var getContext = function (display, infos, curLevel) {

drawPortText = false;

if (!sensor.focusrect || isElementRemoved(sensor.focusrect))
if (!sensor.focusrect || isElementRemoved(sensor.focusrect)){
sensor.focusrect = paper.rect(imgx, imgy, imgw, imgh);
}

sensor.focusrect.attr({
"fill": "468DDF",
"fill-opacity": 0,
"opacity": 0,
"x": imgx,
"y": imgy,
"width": imgw,
"height": imgh,
"fill": "468DDF",
"fill-opacity": 0,
"opacity": 0,
"x": imgx,
"y": imgy,
"width": imgw,
"height": imgh,
});

if (context.autoGrading) {
Expand Down Expand Up @@ -6551,6 +6566,9 @@ var getContext = function (display, infos, curLevel) {
namesize = portsize;
nameanchor = "start";
}
namesize = Math.min(namesize,maxNameSize);
statesize = Math.min(statesize,maxStateSize);



if (sensor.type == "led") {
Expand Down Expand Up @@ -6635,8 +6653,7 @@ var getContext = function (display, infos, curLevel) {
findSensorDefinition(sensor).setLiveState(sensor, sensor.state, function(x) {});
}

} else if (sensor.type == "buzzer") {

} else if (sensor.type == "buzzer") {
if(typeof sensor.state == 'number' &&
sensor.state != 0 &&
sensor.state != 1) {
Expand All @@ -6653,10 +6670,11 @@ var getContext = function (display, infos, curLevel) {
}


var muteBtnSize = sensor.drawInfo.width * 0.15;
// var muteBtnSize = sensor.drawInfo.width * 0.15;
var muteBtnSize = imgw * 0.3;
sensor.muteBtn = paper.text(
imgx + imgw,
imgy + (imgh / 2),
imgx + imgw*0.8,
imgy + imgh*0.8,
buzzerSound.isMuted(sensor.name) ? "\uf6a9" : "\uf028"
);
sensor.muteBtn.node.style.fontWeight = "bold";
Expand All @@ -6667,8 +6685,11 @@ var getContext = function (display, infos, curLevel) {
"font-size": muteBtnSize + "px",
fill: buzzerSound.isMuted(sensor.name) ? "lightgray" : "#468DDF",
"font-family": '"Font Awesome 5 Free"',
'text-anchor': 'start'
});
'text-anchor': 'start',
"cursor": "pointer"
});
var bbox = sensor.muteBtn.getBBox();

sensor.muteBtn.click(function () {
if(buzzerSound.isMuted(sensor.name)) {
buzzerSound.unmute(sensor.name)
Expand All @@ -6677,6 +6698,7 @@ var getContext = function (display, infos, curLevel) {
}
drawSensor(sensor);
});
sensor.muteBtn.toFront();
}


Expand Down Expand Up @@ -8271,13 +8293,23 @@ var getContext = function (display, infos, curLevel) {
sensor.nameText = paper.text(namex, namey, sensor.name );
sensor.nameText.attr({ "font-size": namesize + "px", 'text-anchor': nameanchor, fill: "#7B7B7B" });
sensor.nameText.node.style = "-moz-user-select: none; -webkit-user-select: none;";
var bbox = sensor.nameText.getBBox();
if(bbox.width > sensor.drawInfo.width - 20){
namesize = namesize*(sensor.drawInfo.width - 20)/bbox.width;
namey += namesize*(1 - (sensor.drawInfo.width - 20)/bbox.width);
sensor.nameText.attr({
"font-size":namesize,
y: namey });
}
}
}


if (!donotmovefocusrect) {
// This needs to be in front of everything
sensor.focusrect.toFront();
if(sensor.muteBtn)
sensor.muteBtn.toFront();
}

saveSensorStateIfNotRunning(sensor);
Expand Down Expand Up @@ -10652,6 +10684,9 @@ function hideSlider(sensor) {
}


if (sensor.focusrect && sensor.focusrect.paper && sensor.focusrect.paper.canvas)
if (sensor.focusrect && sensor.focusrect.paper && sensor.focusrect.paper.canvas){
sensor.focusrect.toFront();
if(sensor.muteBtn)
sensor.muteBtn.toFront();
}
};
64 changes: 25 additions & 39 deletions pemFioi/quiz2/grader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@
function scoreCalculator(score_settings, nb_total) {

var nb_valid = 0;
var nb_mistakes = 0;
var nb_answers = 0;

return {

addAnswer: function(answer_score) {
nb_answers += 1;
if(typeof answer_score === 'boolean') {
nb_valid += answer_score ? 1 : 0;
nb_mistakes += answer_score ? 0 : 1;
} else {
answer_score = parseFloat(answer_score) || 0;
nb_valid += answer_score;
nb_mistakes += answer_score > 0 ? 0 : 1;
nb_valid += parseFloat(answer_score) || 0;
}
},

getScore: function() {
if(score_settings) {
var score = (nb_valid * score_settings.maxScore
+ nb_mistakes * score_settings.minScore
+ (nb_total - nb_valid - nb_mistakes) * score_settings.noScore) / nb_total;
var score = (nb_valid / nb_total * (score_settings.maxScore - score_settings.minScore)
+ score_settings.minScore
+ (nb_total - nb_answers) / nb_total * score_settings.noScore);
} else {
var score = nb_valid / nb_total;
}
Expand Down Expand Up @@ -78,7 +76,7 @@
}


function gradeAnswerArray(given_answer, correct_answer, messages) {
function gradeAnswerArray(given_answer, correct_answer, messages, strict) {
var res = {
score: 0,
feedback: {
Expand All @@ -92,12 +90,22 @@
var user_incorrect_answers_amount = 0;

for(var i=0; i<given_answer.length; i++) {
var correct = correct_answer.indexOf(given_answer[i]) !== -1;
if(correct) {
user_correct_answers_amount++;
if(strict) {
var correct = correct_answer[i] === given_answer[i];
if(correct) {
user_correct_answers_amount++;
} else {
user_incorrect_answers_amount++;
}
res.feedback.mistakes.push(correct ? null : given_answer[i]);
} else {
user_incorrect_answers_amount++;
res.feedback.mistakes.push(given_answer[i]);
var correct = correct_answer.indexOf(given_answer[i]) !== -1;
if(correct) {
user_correct_answers_amount++;
} else {
user_incorrect_answers_amount++;
res.feedback.mistakes.push(given_answer[i]);
}
}
}
var correct_answers_amount = correct_answer.length;
Expand All @@ -112,7 +120,7 @@
}
break;
case "percentage_of_correct":
if(correct_answers_amount > 0 && user_incorrect_answers_amount == 0) {
if(correct_answers_amount > 0) {
res.score = user_correct_answers_amount / correct_answers_amount;
}
break;
Expand All @@ -136,30 +144,11 @@
}
res.score = Math.max(0, res.score);
res.score = Math.min(1, res.score);
res.feedback.partial = res.score < 1 && user_correct_answers_amount > 0;
return res;
}


function gradeAnswerArrayStrict(given_answer, correct_answer, messages) {
var res = {
score: true,
feedback: {
correct_answer: correct_answer,
mistakes: [],
messages: messages
}
}
for(var i=0; i<given_answer.length; i++) {
var correct = correct_answer[i] === given_answer[i];
res.score = res.score && correct;
res.feedback.mistakes.push(correct ? null : given_answer[i]);
}
if(given_answer.length != correct_answer.length) {
res.score = false;
}
return res;
}

function gradeAnswerTwoDimArray(given_answer, correct_answer, messages) {
var res = {
score: true,
Expand Down Expand Up @@ -238,10 +227,7 @@
if(grader.twoDimArray) {
return gradeAnswerTwoDimArray(answer, grader.value, grader.messages || []);
}
if(grader.strict) {
return gradeAnswerArrayStrict(answer, grader.value, grader.messages || []);
}
return gradeAnswerArray(answer, grader.value, grader.messages || []);
return gradeAnswerArray(answer, grader.value, grader.messages || [], !!grader.strict);
},


Expand Down
2 changes: 2 additions & 0 deletions pemFioi/quiz2/questions/choice.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@
},

displayFeedback: function(feedback) {
feedback.partial && Quiz.common.toggleAlertMessage(parent, lang.translate("wrong_partial"), 'error');

var correct = feedback.mistakes.length == 0;
if((Quiz.params.show_solutions == 'all') || (Quiz.params.show_solutions == 'correct_only' && correct)) {
parent.find('solution').show();
Expand Down
Loading

0 comments on commit 090069a

Please sign in to comment.