-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.html
275 lines (222 loc) · 8.54 KB
/
timer.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="images/fav.png">
<title>C'est parti !</title>
<script src="./js/lib/jquery.js"></script>
<link rel="stylesheet" href="./js/lib/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="./js/bootstrap/css/bootstrap.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/accueil.css" rel="stylesheet">
<link href="css/timer.css" rel="stylesheet">
<link href="css/pseudo.css" rel="stylesheet">
<script type="text/javascript" src="js/timer.js"></script>
<script type="text/javascript" src="js/machine.js"></script>
<script src="./js/bootstrap/js/bootstrap.js" charset="utf-8"></script>
<link rel="stylesheet" href="./js/lib/toastr.css" media="screen" title="no title" charset="utf-8">
<script src="./js/lib/toastr.js" charset="utf-8"></script>
</head>
<body>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header text-center">
<div class="col-lg-12 text-center">
<img src="images/logo.png" alt="" width="200" height="200" />
</div>
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Nos félicitations vous avez obtenu un score de
<span id="score"></span>
</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="name">Votre nom: </label>
<input class="form-control" type="text" name="name" id="name" value="">
</div>
<br>
<div class="form-group">
<label for="name">Laissez un message (facultatif): </label>
<textarea id="feedback" class="form-control" name="feedback" rows="8" cols="40"></textarea>
</div>
<button class="btn" type="button" id="closeOpenKeyboard" name="button"><i class=" fa fa-keyboard-o "></i></button>
</div>
<div class="modal-footer">
<button id="closeModal" type="button" class="btn btn-default" data-dismiss="modal">Valider</button>
</div>
</div>
</div>
</div>
<div class="container">
<div class="jumbotron">
<!-- Chronomètre -->
<div class="col-lg-6">
<span id="chronotime">00:00:00:00</span>
</div>
<div class="col-lg-4" style="font-size:3.5em">
<span id="numberPile">0</span> <span>x <i class="fa fa-battery-full"></i></span>
</div>
<form name="chronoForm">
<script type="text/javascript" src="js/timer.js"></script>
</form>
<!-- Pile -->
<div class="row" style="margin-bottom:6em;">
<div class="col-lg-12">
<h4>Vous avez permis d'alimenter pendant un heure l'équivalent de :</h4>
</div>
<div class="col-lg-3">
<div class="row">
<h5 class="col-lg-8">
<span id="smartphone">0</span>x <i class="fa fa-mobile fa-2x"></i> </h5>
<h5 class="col-lg-4">
ou
</h5>
</div>
</div>
<div class="col-lg-3">
<div class="row">
<h5 class="col-lg-8">
<span id="ampoule">0</span>x <i class="fa fa-lightbulb-o fa-2x"></i> </h5>
<h5 class="col-lg-4">
ou
</h5>
</div>
</div>
<div class="col-lg-3">
<div class="row">
<h5 class="col-lg-8">
<span id="tele">0</span>x <i class="fa fa-television fa-2x"></i> </h5>
<h5 class="col-lg-4">
ou
</h5>
</div>
</div>
<div class="col-lg-3">
<div class="row">
<h5 class="col-lg-8">
<span id="ordi">0</span>x <i class="fa fa-desktop fa-2x"></i> </h5>
</div>
</div>
</div>
<center>
<div id="mydiv" style="margin-bottom:4em;">
<img id="image" src="images/batterie.png">
<h2 id="text"></h2>
</div>
</center>
</p>
<span id="inviScore" style="display:none">0</span>
<script type="text/javascript" src="js/pile.js"></script>
<script type="text/javascript">
$("#closeOpenKeyboard").click(function(event) {
$("#keyboard").toggle();
});
toastr.options = {
"positionClass": "toast-top-center"
}
function setPile(percent) {
var val = Math.floor(100 - percent);
$("#mydiv").css('background', 'linear-gradient(to bottom, white 0%,white ' + val + '%' + ',rgba(64,187,106,1) ' + val + '%)');
document.getElementById("text").innerHTML = Math.floor(percent) + " %";
}
function parHeure(totale, watt) {
return Math.floor(totale / watt)
}
function sendScore(idMachine, name, score, feedback) {
global_time -= 5;
//console.log('http://localhost:3500/insert/result&idMachine='+idMachine+'&feedback='+feedback+'&score='+score+'&nameuser='+name)
$.ajax({
url: 'http://' + ip + ':3000/insert/result?time=' + global_time + '&idMachine=' + idMachine + '&feedback=' + encodeURIComponent(feedback) + '&score=' + score + '&nameuser=' + encodeURIComponent(name),
type: 'GET',
success: function(code_html, statut) {
$("#myModal").modal('hide');
toastr.success('', "Merci d'avoir contribué à WattThePark !");
},
error: function() {
alert("Ca marche pas !")
}
});
}
var nbPile = 0.0
var total = 0.0;
var startTimer = false;
var afkCount = 0;
var maxPile = 2000;
var timeAfkBeforeReturn = 0;
$("#closeModal").click(function(event) {
sendScore(idMachine, $("#name").val(), parseInt($("#inviScore").text()), $("#feedback").val());
$("#myModal").modal('hide');
});
window.setInterval(function() {
if(!startTimer)
timeAfkBeforeReturn++;
if(timeAfkBeforeReturn > 1200) {
window.location = "accueil.html";
}
$.ajax({
url: 'http://'+ip+':'+port+'/watt',
type: 'GET',
success: function(code_html, statut) {
var value = parseFloat(code_html);
if (afkCount > 50) {
startTimer = false;
afkCount = 0;
$("#inviScore").text(nbPile * 500 + ((total - nbPile * maxPile) / maxPile) * 500)
$("#score").text(total);
total = 0;
nbPile = 0
chronoStop();
$("#myModal").modal()
}
if (startTimer) {
total += value;
var percent = ((total - nbPile * maxPile) / maxPile) * 100;
if (percent > 100) {
nbPile++;
}
percent = ((total - nbPile * maxPile) / maxPile) * 100;
setPile(percent);
$("#numberPile").text(nbPile);
$("#smartphone").text(parHeure(total, 10));
$("#ampoule").text(parHeure(total, 60));
$("#tele").text(parHeure(total, 80));
$("#ordi").text(parHeure(total, 250));
if (value == 0.0) {
afkCount++;
} else {
afkCount = 0;
}
}
if (value != 0.0 && !startTimer) {
startTimer = true;
timeAfkBeforeReturn = 0;
chronoStart();
}
//console.log(total);
//$("#number").text(code_html+" W");
},
});
}, 100);
</script>
<!-- Pavé des boutons -->
<div class="boutons">
<p>
<a class="btn btn-lg btn-success" href="./accueil.html" role="button">Quitter</a>
<a class="btn btn-lg btn-success" href="./records.html" role="button">Records</a>
</p>
</div>
</div>
<!-- Pied de page -->
<footer class="footer">
<p>Projet Intensif 2016 - Groupe 7 - Watt The Park </p>
</footer>
</div>
</body>
</html>