Skip to content

Commit 8f1012c

Browse files
committed
gerando template proofweb
1 parent dc863c9 commit 8f1012c

File tree

3 files changed

+112
-6
lines changed

3 files changed

+112
-6
lines changed

config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var students = [
2-
"Aluno 1", "Aluno 2"
2+
"username1", "username2"
33
];
44

55
var num_students = students.length;

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<title>Adicionar Exercícios</title>
66
<link rel="stylesheet" type="text/css" href="base.css" />
77
<script src="jquery-1.7.1.min.js"></script>
8+
<script src="test.js"></script>
89
<script src="config.js"></script>
910
<script src="query.js"></script>
1011
</head>

query.js

+110-5
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,123 @@ function form_value() {
2929
};
3030
}
3131

32+
function proofweb(e) {
33+
return e.replace(/&/g, "/\\").replace(/\|/g, "\\/").replace(/!/g, "~");
34+
}
35+
36+
function natural_ded(atoms, ex, n) {
37+
38+
var m = ["Require Import ProofWeb.",
39+
"(* TEMPLATE DA TEORIA DE DEDUÇÃO NATURAL: *)",
40+
"Parameter "].join('\n\n');
41+
42+
m += atoms.join(' ');
43+
44+
m += ": Prop.\n\n";
45+
46+
var k = 0;
47+
48+
for(i in ex.premises) {
49+
m += "Hypothesis P" + k + " : ";
50+
m += proofweb(ex.premises[i]) + ".\n\n";
51+
k = k + 1;
52+
}
53+
54+
m += "Theorem T" + n + " : " + proofweb(ex.conclusion) + ".\n\n";
55+
56+
m += ["Proof.",
57+
"(* Prova aqui *)",
58+
"Qed."].join("\n\n");
59+
60+
return m;
61+
}
62+
63+
function semantic(atoms, ex, n) {
64+
65+
var m = ["Require Import Semantics.",
66+
"(* Exemplo de VERIFICAÇÂO DE UM CONTRA-MODELO: *)",
67+
"Parameter "].join('\n\n');
68+
69+
m += atoms.join(' ');
70+
71+
m += ": Prop.\n\n";
72+
73+
var k = 0;
74+
75+
for(i in atoms) {
76+
m += "(* Hypothesis P" + k + " : (v ?? ";
77+
m += atoms[i] + "). *)\n\n";
78+
k = k + 1;
79+
}
80+
81+
var r = ex.premises.map(function (d) { return proofweb(d); });
82+
83+
var p = ' ( ' + r.join(' /\\ ') + ' ) -> ' + proofweb(ex.conclusion);
84+
85+
m += "Theorem T" + n + " : (v ||-/- " + p + ".\n\n";
86+
87+
m += ["Proof.",
88+
"(* Prova aqui *)",
89+
"Qed."].join("\n\n");
90+
91+
return m;
92+
}
93+
94+
function shuffle(array) {
95+
var tmp, current, top = array.length;
96+
97+
if(top) while(--top) {
98+
current = Math.floor(Math.random() * (top + 1));
99+
tmp = array[current];
100+
array[current] = array[top];
101+
array[top] = tmp;
102+
}
103+
104+
return array;
105+
}
106+
107+
function combine(res) {
108+
var a = shuffle(res.exercises.valid.concat(res.exercises.invalid));
109+
110+
console.log(a);
111+
112+
var r = {};
113+
114+
$.each(students, function(i, val) {
115+
r[val] = { nd: [], sem: [] };
116+
117+
var l = r[val];
118+
119+
var j;
120+
121+
for (j = 0; j < res.request.num_exercises / num_students; j++) {
122+
console.log(i + " " + j);
123+
l.nd[j] = natural_ded(res.request.atoms, a[i*j], j);
124+
l.sem[j] = semantic(res.request.atoms, a[i*j], j);
125+
}
126+
});
127+
128+
return r;
129+
};
130+
131+
132+
//console.log(natural_ded(s.request.atoms, s.exercises.valid[0], 0));
133+
//console.log(semantic(s.request.atoms, s.exercises.valid[0], 0));
134+
32135
function select(nome) {
33136
$('#side .tab').hide();
34137
$('#side .tab#c_' + nome).show();
35138
$('#menu .selected').removeClass('selected');
36139
$('#menu #' + nome).addClass('selected');
37140
}
38141

142+
var test;
143+
39144
$(document).ready(function () {
40145

41146
$("a#send").click(function (ev) {
42147
$('a#send').toggle();
43148

44-
console.log(form_value());
45-
46149
$.ajax({
47150
url:"generate.php",
48151
type: "POST",
@@ -53,9 +156,11 @@ $(document).ready(function () {
53156
alert("Erro ao enviar os dados: " + status);
54157
},
55158
success: function(data) {
56-
console.log($('#c_detalhes'));
57159
$('#c_detalhes').show().html('<pre>' + JSON.stringify(data, null, 4));
58-
console.log(data);
160+
$('#c_exerc').show().html('<pre>' + JSON.stringify(combine(data), null, 4));
161+
162+
test = data;
163+
59164
$('a#send').toggle();
60165
$('#menu').show();
61166
$('#menu #exerc').trigger('click');
@@ -81,4 +186,4 @@ $(document).ready(function () {
81186
.trigger('blur');
82187

83188

84-
});
189+
});

0 commit comments

Comments
 (0)