-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddDifficulty.js
78 lines (72 loc) · 2.06 KB
/
addDifficulty.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
78
var http = require('http');
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'prideboy41',
database: 'typeGameDatabase'
});
var easyChars = ['a','s','d','f','g','h','j','k','l',';','\''];
var easyCharsUp = ['A','S','D','F','G','H','J','K','L',':','\"'];
var harderChars = ['z','x','c','v','b','n','m',',','.','/','q','w','e','r','t','y','u','i','o','p','[',']','\\'];
var harderCharsUp = ['Z','X','C','V','B','N','M','<','>','?','Q','W','E','R','T','Y','U','I','O','P','{','}','|'];
var hardestChars = ['`','1','2','3','4','5','6','7','8','9','0','-','='];
var hardestCharsUp = ['~','!','@','#','$','%','^','&','*','(',')','_','+'];
connection.connect();
connection.query('SELECT * FROM Quotes', function (err, rows, fields) {
if (err) {
console.log(err);
}
else {
var arr = [];
var count = 0;
rows.forEach(function(row){
var difTotal = 0;
var str = row.quote.replace(/\s+/g, '');
for(var i = 0; i < str.length; i++){
var ch = str.charAt(i);
if(easyChars.indexOf(ch) != -1){
difTotal += 1;
}
else if(easyCharsUp.indexOf(ch) != -1){
difTotal += 2;
}
else if(harderChars.indexOf(ch) != -1){
difTotal += 4;
}
else if(harderCharsUp.indexOf(ch) != -1){
difTotal += 6;
}
else if(hardestChars.indexOf(ch) != -1){
difTotal += 8;
}
else if(hardestCharsUp.indexOf(ch) != -1){
difTotal += 10;
}
}
var difficulty = "";
console.log(difTotal);
if(difTotal <= 200){
difficulty = "'easy'";
}
else if(difTotal < 400){
difficulty = "'intermediate'";
}
else{
difficulty = "'hard'";
}
console.log("UPDATE Quotes SET difficulty=" + difficulty + " WHERE id=" + row.id);
connection.query("UPDATE Quotes SET difficulty=" + difficulty + " WHERE id=" + row.id, function(err){
if(err){
console.log(err);
}
else{
console.log("updated " + row.id + " to diff " + row.difficulty);
}
if(++count == rows.length){
connection.end();
}
});
});
}
});