mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Added old dataformat processing
This commit is contained in:
parent
6143cecc30
commit
913277eb4a
1 changed files with 109 additions and 9 deletions
118
main.js
118
main.js
|
@ -743,6 +743,101 @@ function ReadNetDB(cwith, useNetDB) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns a question database from the given data.
|
||||||
|
* Parameter should be raw read file in string with "\n"-s
|
||||||
|
* TODO: ??? -s are not listed as errors, tho works correctly
|
||||||
|
* */
|
||||||
|
function ParseRawData(data) {
|
||||||
|
|
||||||
|
const d = data.split("\n");
|
||||||
|
const r = new QuestionDB();
|
||||||
|
var logs = [];
|
||||||
|
var currSubj = ""; // the current subjects name
|
||||||
|
var ExpectedIdentifier = ['+', '?'];
|
||||||
|
let currQuestion = new Question();
|
||||||
|
|
||||||
|
var i = -1;
|
||||||
|
while (i < d.length) {
|
||||||
|
let currIdentifier;
|
||||||
|
let skipped = 0;
|
||||||
|
do {
|
||||||
|
if (skipped >= 1)
|
||||||
|
logs.push(i + ": " + d[i]);
|
||||||
|
i++;
|
||||||
|
if (i >= d.length) {
|
||||||
|
if (currQuestion.IsComplete())
|
||||||
|
r.AddQuestion(currSubj, currQuestion);
|
||||||
|
return {
|
||||||
|
result: r,
|
||||||
|
logs: logs
|
||||||
|
};
|
||||||
|
}
|
||||||
|
currIdentifier = d[i][0];
|
||||||
|
skipped++;
|
||||||
|
} while (!ExpectedIdentifier.includes(currIdentifier) && i < d.length);
|
||||||
|
|
||||||
|
let currData = d[i].substring(1).trim();
|
||||||
|
|
||||||
|
if (currIdentifier == '+') {
|
||||||
|
if (currQuestion.IsComplete())
|
||||||
|
r.AddQuestion(currSubj, currQuestion);
|
||||||
|
currQuestion = new Question();
|
||||||
|
currSubj = currData;
|
||||||
|
ExpectedIdentifier = ['?'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currIdentifier == '?') {
|
||||||
|
if (currQuestion.IsComplete()) {
|
||||||
|
r.AddQuestion(currSubj, currQuestion);
|
||||||
|
currQuestion = new Question();
|
||||||
|
}
|
||||||
|
// overwriting is allowed here, bcus:
|
||||||
|
// ?????!>
|
||||||
|
currQuestion.Q = currData;
|
||||||
|
ExpectedIdentifier = ['!', '?'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currIdentifier == '!') {
|
||||||
|
// if dont have question continue
|
||||||
|
if (!currQuestion.HasQuestion())
|
||||||
|
throw "No question! (A)";
|
||||||
|
// dont allow overwriting
|
||||||
|
// ?!!!!
|
||||||
|
if (!currQuestion.HasAnswer()) {
|
||||||
|
currData = currData.replace("A helyes válaszok: ", "");
|
||||||
|
currData = currData.replace("A helyes válasz: ", "");
|
||||||
|
|
||||||
|
currQuestion.A = currData;
|
||||||
|
}
|
||||||
|
ExpectedIdentifier = ['?', '>', '+'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currIdentifier == '>') {
|
||||||
|
// if dont have question or answer continue
|
||||||
|
if (!currQuestion.HasQuestion())
|
||||||
|
throw "No question! (I)";
|
||||||
|
if (!currQuestion.HasAnswer())
|
||||||
|
throw "No asnwer! (I)";
|
||||||
|
// dont allow overwriting
|
||||||
|
// ?!>>>
|
||||||
|
if (!currQuestion.HasImage()) {
|
||||||
|
currQuestion.I = JSON.parse(currData);
|
||||||
|
}
|
||||||
|
ExpectedIdentifier = ['?', '+'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
result: r,
|
||||||
|
logs: logs
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function Load(cwith) {
|
function Load(cwith) {
|
||||||
var useNetDB = GM_getValue("useNetDB");
|
var useNetDB = GM_getValue("useNetDB");
|
||||||
if (useNetDB != undefined && (useNetDB == 0 || useNetDB == 1))
|
if (useNetDB != undefined && (useNetDB == 0 || useNetDB == 1))
|
||||||
|
@ -765,7 +860,13 @@ function LoadMOTD(resource) {
|
||||||
function NLoad(resource, cwith) {
|
function NLoad(resource, cwith) {
|
||||||
var count = -1;
|
var count = -1;
|
||||||
try {
|
try {
|
||||||
var d = JSON.parse(resource);
|
var d = {};
|
||||||
|
try {
|
||||||
|
d = JSON.parse(resource);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Old data, trying with old methods....");
|
||||||
|
d = ParseRawData(resource).result;
|
||||||
|
}
|
||||||
var r = new QuestionDB();
|
var r = new QuestionDB();
|
||||||
var rt = [];
|
var rt = [];
|
||||||
var allCount = -1;
|
var allCount = -1;
|
||||||
|
@ -1125,6 +1226,8 @@ function GetQuiz() {
|
||||||
|
|
||||||
//: }}}
|
//: }}}
|
||||||
|
|
||||||
|
//: Helpers {{{
|
||||||
|
|
||||||
function SimplifyImages(imgs) {
|
function SimplifyImages(imgs) {
|
||||||
var questionImages = []; // the array for the image names in question
|
var questionImages = []; // the array for the image names in question
|
||||||
for (var i = 0; i < imgs.length; i++) // going through all image
|
for (var i = 0; i < imgs.length; i++) // going through all image
|
||||||
|
@ -1139,10 +1242,6 @@ function SimplifyImages(imgs) {
|
||||||
return questionImages;
|
return questionImages;
|
||||||
}
|
}
|
||||||
|
|
||||||
//: }}}
|
|
||||||
|
|
||||||
//: Minor logic stuff {{{
|
|
||||||
|
|
||||||
// adds image names to image nodes
|
// adds image names to image nodes
|
||||||
function AddImageNamesToImages(imgs) {
|
function AddImageNamesToImages(imgs) {
|
||||||
for (var i = 0; i < imgs.length; i++) // going through all image
|
for (var i = 0; i < imgs.length; i++) // going through all image
|
||||||
|
@ -1235,7 +1334,6 @@ function RemoveLetterMarking(inp) {
|
||||||
|
|
||||||
// highlights the possible solutions to the current question
|
// highlights the possible solutions to the current question
|
||||||
function HighLightAnswer(results, currQuestionNumber) {
|
function HighLightAnswer(results, currQuestionNumber) {
|
||||||
// TODO
|
|
||||||
try {
|
try {
|
||||||
if (results.length > 0) // if there are items in the result
|
if (results.length > 0) // if there are items in the result
|
||||||
{
|
{
|
||||||
|
@ -1272,6 +1370,8 @@ function HighLightAnswer(results, currQuestionNumber) {
|
||||||
|
|
||||||
//: }}}
|
//: }}}
|
||||||
|
|
||||||
|
//: }}}
|
||||||
|
|
||||||
//: Minor UI stuff {{{
|
//: Minor UI stuff {{{
|
||||||
|
|
||||||
// shows a message with "msg" text, "matchPercent" tip and transp, and "timeout" time
|
// shows a message with "msg" text, "matchPercent" tip and transp, and "timeout" time
|
||||||
|
@ -1886,7 +1986,7 @@ function ShowHelp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//: }}}
|
//: }}}
|
||||||
//
|
|
||||||
// I am not too proud to cry that He and he
|
// I am not too proud to cry that He and he
|
||||||
// Will never never go out of my mind.
|
// Will never never go out of my mind.
|
||||||
// All his bones crying, and poor in all but pain,
|
// All his bones crying, and poor in all but pain,
|
||||||
|
@ -1902,10 +2002,10 @@ function ShowHelp() {
|
||||||
// Out of his eyes I saw the last light glide.
|
// Out of his eyes I saw the last light glide.
|
||||||
// Here among the liught of the lording sky
|
// Here among the liught of the lording sky
|
||||||
// An old man is with me where I go
|
// An old man is with me where I go
|
||||||
//
|
|
||||||
// Walking in the meadows of his son's eye
|
// Walking in the meadows of his son's eye
|
||||||
// Too proud to cry, too frail to check the tears,
|
// Too proud to cry, too frail to check the tears,
|
||||||
// And caught between two nights, blindness and death.
|
// And caught between two nights, blindness and death.
|
||||||
//
|
|
||||||
// O deepest wound of all that he should die
|
// O deepest wound of all that he should die
|
||||||
// On that darkest day.
|
// On that darkest day.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue