-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.html
208 lines (173 loc) · 5.07 KB
/
check.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="jquery-2.2.4.js"></script>
</head>
<body>
<p class="answer"></p>
<script type="text/javascript">
sample_test();
$.ajax("http://ftt.elsyton.com").then(function(task){
console.log("task", task); //смотрим, что получили
console.log("id", task.id); //проверяем, что получили
var links = [];//содаем массив
for (var i=0;i<task.trees.length;i++) {
var pairs = parse_tree(task.trees[i]);//парсим дерево
links.push(pairs);//ложим в массив
}
//links[0][0] = [99,88]; // для генерации ошибки в результатах
console.log("links", links); //проверяем, что вышло
$.ajax({
url: "http://ftt.elsyton.com",//адрес
data: JSON.stringify({id: task.id, links: links}),//информация
dataType: "json",//формат
headers: {"Content-Type": "application/json"},//заголовок
type: "POST"
}).then(function(check){
console.log("check", check); //смотрим, что получили
//проверяем ответ
if (check.results.indexOf(false)===-1) {
$(".answer").html("<span class='animated bouce' style='color:green'>ok</span");
} else {
$(".answer").html("<span class='animated bouce' style='color:red'>error</span");
}
});
});
function parse_tree(tree) {
var wait = [];
var result = [];
dig_branch(tree, 0);
function dig_branch(item, level) {//начинаем исследовать
if (!item || item===null)
return;
check_pair(item.right);
check_pair(item.left);
dig_branch(item.right, level+1);
dig_branch(item.left, level+1);
function check_pair(branch) {
if (branch && branch!==null) {
if (typeof wait[level] !== 'undefined') {
result.push([ wait[level], branch.id ]);
}
wait[level] = branch.id;
}
}
}
return result;
}
//console.log(check_pair);
//var links = [];
//dig_branch(links, 0, links);
function sample_test() {
var test = {};
test.tree = {
id: 0,
left: {
id: 1,
left: {
id: 5
}
},
right: {
id: 2,
left: {
id: 3,
left: null,
right: null
},
right: {
id: 4
}
}
};
test.result = [[4, 3], [2, 1], [3, 5]];
var pairs = parse_tree(test.tree);
console.log("pairs", pairs);
console.log("pairsR", JSON.stringify(pairs));
console.log("pairsT", JSON.stringify(test.result));
}
</script>
<style type="text/css">
body{
background: #61b6e7;
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
.answer{
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
font-size: 26pt;
margin: auto;
text-align: center;
width: 300px;
height: 26pt;
}
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.bounce {
-webkit-animation-name: bounce;
animation-name: bounce;
-webkit-transform-origin: center bottom;
transform-origin: center bottom;
}
@-webkit-keyframes bounce {
from, 20%, 53%, 80%, to {
-webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
40%, 43% {
-webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
-webkit-transform: translate3d(0, -30px, 0);
transform: translate3d(0, -30px, 0);
}
70% {
-webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
-webkit-transform: translate3d(0, -15px, 0);
transform: translate3d(0, -15px, 0);
}
90% {
-webkit-transform: translate3d(0,-4px,0);
transform: translate3d(0,-4px,0);
}
}
@keyframes bounce {
from, 20%, 53%, 80%, to {
-webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
40%, 43% {
-webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
-webkit-transform: translate3d(0, -30px, 0);
transform: translate3d(0, -30px, 0);
}
70% {
-webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
-webkit-transform: translate3d(0, -15px, 0);
transform: translate3d(0, -15px, 0);
}
90% {
-webkit-transform: translate3d(0,-4px,0);
transform: translate3d(0,-4px,0);
}
}
</style>
</body>
</html>