-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathquestionDatabaseUpdater.js
77 lines (67 loc) · 2.19 KB
/
questionDatabaseUpdater.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use strict";
const fs = require("fs"),
sqlite = require("sqlite3").verbose();
let questionArr = [];
const db = new sqlite.Database("questionDatabase.db", function(err) {});
Object.defineProperty(Array.prototype, "caseInsensitiveIncludes", {
"value": function(value) {
for (let i = 0 ; i < this.length ; i++) {
if (this[i].toLowerCase() === value.toLowerCase()) {
return true;
}
}
return false;
}
});
db.serialize(function() {
db.all(`SELECT * FROM questions`, [], function(err, result) {
if (err) {
console.log(err);
} else {
questionArr = result;
questionArr.forEach(function(element, index) {
questionArr[index].json = JSON.parse(element.json);
questionArr[index].verification = JSON.parse(element.verification);
});
doSomethingFunction();
questionArr.forEach(function(element) {
db.run(`UPDATE questions SET json = '${JSON.stringify(element.json).replace(/'/g,"''")}', status = '${element.status}', verification = '${JSON.stringify(element.verification).replace(/'/g,"''")}' WHERE id = ${element.id}`, function(err) {
if (err) {
console.log(err);
}
});
});
}
});
});
const allCards = JSON.parse(fs.readFileSync("allCards.json", "utf8"));
const convertAllTemplates = function(questionObj, allCards) {
const convertedQuestion = JSON.parse(JSON.stringify(questionObj.json))
convertedQuestion.cardLists = [];
for (let i = 0 ; i < convertedQuestion.cardGenerators.length ; i++) {
if (typeof convertedQuestion.cardGenerators[i][0] === "object") {
convertedQuestion.cardLists[i] = templateConvert(convertedQuestion.cardGenerators[i], allCards);
} else {
convertedQuestion.cardLists[i] = convertedQuestion.cardGenerators[i]
}
}
delete convertedQuestion.cardGenerators;
questionObj.json = convertedQuestion;
};
let total = 0;
const doSomethingFunction = function() {
const allResults = {};
questionArr.forEach(function(questionObj) {
for (let generator of questionObj.json.cardGenerators) {
if (typeof generator[0] === "string") {
continue;
}
for (let rule of generator) {
if (rule.orGroup !== null && rule.orGroup >= 100) {
console.log(questionObj.json.id)
console.log(rule.orGroup)
}
}
}
});
};