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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
| function endExercise() {
var results = new Array();
var sum = 0;
var tasks = $(".Task");
var l = tasks.length;
for (var i = 0; i < l; i++) {
var task = $(tasks[i]);
var result = 0;
if (task.hasClass("rightAnswerUsed")) {
results.push(0);
sum += 0;
continue;
}
@Html.Raw(TasksFactory.EndExerciseScripts)
//decrase by hint weight
var penalty = 0;
var usedHints = $(".Hint[data-parent=" + task.attr("id") + "] [data-used=true]");
var usedHintsLength = usedHints.length;
for (var j = 0; j < usedHintsLength; j++) {
penalty += parseInt($(usedHints[j]).attr("data-hintweight"));
}
result = result * (100 - penalty) / 100;
if (result < 0) {
result = 0;
}
results.push(result);
sum += result;
}
var data = {
Id: "@Model.Id",
Path: @Html.Raw(JsonConvert.SerializeObject(Model.Path)),
Values: results,
TimeWork: minutes * 60 + seconds,
UserId: "@efforPrincipal.User.Id",
Type: @((int)Model.Type),
BeginDate: "@DateTime.Now"
};
var db = openDatabase("EfforAndroid", "1.0", "EfforMobile", 2 * 1024 * 1024);
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS results (userId TEXT, exerciseId TEXT, exercisePath TEXT, data TEXT)');
tx.executeSql('SELECT * FROM results WHERE userId = ? AND exerciseId = ? AND exercisePath = ?', [data.UserId, data.Id, data.Path], function(tx,r) {
if (r.rows.length == 0) {
tx.executeSql('INSERT INTO results (userId, exerciseId, exercisePath, data) VALUES (?,?,?,?)', [data.UserId, data.Id, data.Path, JSON.stringify(data)]);
} else {
tx.executeSql('UPDATE results SET data = ? WHERE userId = ? AND exerciseId = ? AND exercisePath = ?', [JSON.stringify(data), data.UserId, data.Id, data.Path]);
}
});
});
var right = 0;
for (var i = 0; i < results.length; i++) {
if (results[i] == 100) {
right++;
}
}
var noAnswer = $(".Task").length - $(".Task.answered").length;
$.ajax({
url: "@Url.Action("Save")",
type: "POST",
traditional: true,
beforeSend: function () { $.mobile.showPageLoadingMsg(); },
complete: function () { $.mobile.hidePageLoadingMsg(); },
data: data,
success: function (average) {
$("#resultValue").html(average + "%");
$("#resultTime").html(minutes + ":" + ((seconds < 10) ? "0" + seconds : seconds));
$("#resultNoAnswer").html(noAnswer);
$("#resultRight").html(right);
$("#resultWrong").html(@Model.Tasks.Length - right - noAnswer);
$.mobile.navigate("#results");
},
error: function () {
var db = openDatabase("EfforAndroid", "1.0", "EfforMobile", 2 * 1024 * 1024);
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS results (userId TEXT, exerciseId TEXT, exercisePath TEXT, data TEXT)');
tx.executeSql('SELECT * FROM results WHERE userId = ? AND exerciseId = ? AND exercisePath = ?', [data.UserId, data.Id, data.Path], function(tx,r) {
if (r.rows.length == 0) {
tx.executeSql('INSERT INTO results (userId, exerciseId, exercisePath, data) VALUES (?,?,?,?)', [data.UserId, data.Id, data.Path, JSON.stringify(data)]);
} else {
tx.executeSql('UPDATE results SET data = ? WHERE userId = ? AND exerciseId = ? AND exercisePath = ?', [JSON.stringify(data), data.UserId, data.Id, data.Path]);
}
});
});
alert("Error saving results");
window.location = "@Url.Action("Index")";
}
});
} |