-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounter.html
More file actions
188 lines (155 loc) · 3.74 KB
/
counter.html
File metadata and controls
188 lines (155 loc) · 3.74 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Counter</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<style>
body {
font-family: "Lucida Console";
color: white;
background-color:black;
}
.fly {
display: block;
position: absolute;
top: 100px;
left:40px;
color: #090;
opacity: 1;
}
.minus {
left: 300px;
color: #990;
}
.buttons {
display: none;
}
.center {
position: relative;
display: block;
border: 4px black solid;
width: 360px;
height: 200px;
background-color: black;
margin: auto;
margin-top:5%;
}
.buttons button {
font-family: "Lucida Console";
width: calc(50% - 5px);
height: 50px;
}
.current {
display: block;
width: 100%;
height: 50px;
/*background-color: green;*/
text-align: center;
color: white;
font-size: 45px;
}
</style>
<script>
sessions = [];
function getTime(){
return new Date().getTime();
}
function lastSess(){
return sessions[sessions.length - 1];
}
function getSTT(){
total = 0;
for(i = 0; i < sessions.length; i++){
if(sessions[i][1] === undefined || sessions[i][1].length == 0) continue;
for(sEi = 0; sEi < sessions[i][0].length; sEi++){
if(sessions[i][1][sEi] === undefined) continue;
total += sessions[i][1][sEi] - sessions[i][0][sEi];
}
}
return total;
}
stopped = true;
$(function() {
$(window).keypress(function(e) {
var ev = e || window.event;
var key = ev.keyCode || ev.which;
//depart
if(key == 100){
addFlyUp(true);
if((lastSess()[0].length - lastSess()[1].length) <= 0){
stopped = true;
}else{
lastSess()[1].push(getTime());
}
}
//arrive
if(key == 97){
addFlyUp();
if(stopped){
stopped = false;
sessions.push([[],[]]);
}
lastSess()[0].push(getTime());
}
//stop
if(key == 115){
stopped = true;
}
lengthDiff = lastSess()[0].length - lastSess()[1].length;
if(lengthDiff <= 0){
stopped = true;
}
$(".info .current").html((stopped) ? "0" : lengthDiff);
$(".allData").html("Total waiting time[s]: ");
$(".allData").append(getSTT()/1000);
});
});
setInterval(function(){
//$(".allData").html("getSessionTotalTime()");
// $(".allData").append(getSTT());
},100);
function addFlyUp(minus){
minus = minus || 0;
if(minus){
appendT = '<div class="fly minus">-1</div>';
}else{
appendT = '<div class="fly">+1</div>';
}
$('.center').append(appendT);
el = $('.fly').last();
el.animate({
opacity: 0.001,
top: "1px"
}, 1500, function(){
if($('.fly').length > 15){
$('.fly:first').remove();
}
});
}
console.log('you found your way to help...\nso.\npress A on keyboard if a vehicle arrived and stopped at the junction on a lane\npress D if its departed\npress S if you miscounted and new vehicles arrived in duetime\nthis is only for one lane counting, manually\nhave a good time.\nbye.');
</script>
<div class="center">
<div class="buttons">
<button>Arrived</button>
<button>Departed</button>
</div>
<div class="logo">
<pre>
_ __ _ __
| | / / | | / /
| |/ / _ __ | |/ /
| \| '_ \| \
| |\ \ | | | |\ \
\_| \_/_| |_\_| \_/
waiting time counter
</pre>
</div>
<div class="info">
<div class="current">0</div>
<div class="allData"></div>
</div>
</div>
</body>
</html>