-
Notifications
You must be signed in to change notification settings - Fork 1
/
wallet.html
446 lines (389 loc) · 13.6 KB
/
wallet.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<!DOCTYPE html>
<html lang="en">
<head>
<!--
<title>STOCK-SYS</title>
<h1>STOCK-SYS</h1>
-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="assets/js/highstock.js"></script>
<script src="assets/js/exporting.js"></script>
<script src="assets/js/export-data.js"></script>
</head>
<!-- <script src="js/jquery-2.2.3.min.js"></script>-->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>-->
<title>Material Design HTML Template-SHARED ON BOOTSTRAPMB.COM</title>
<base href="">
<!-- load Google fonts -->
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons%7CPlayfair+Display:400,400i,700%7CRoboto+Condensed:400,700"
rel="stylesheet">
<!-- Crypto Styles -->
<link id="crypto-stylesheet" rel="stylesheet" href="assets/css/night-gold-orange.css">
<!-- page specific CSS -->
<script lang="javascript">
var username = "";
var preferlist = [];
var ws;
var series = new Array();
var points_buffer = new Array();
function check_user() {
username = window.location.href.split("=")[1];
if (username == "") {
document.getElementById("current_user").innerHTML = "Not logged in. Sign up first or browse all stocks.";
// username = "";
} else {
document.getElementById("current_user").innerHTML = "User: " + username;
console.log("username: ", username);
if ("WebSocket" in window) {
ws = new WebSocket("ws://localhost:9999");
}
var stock_count = 0;
get_preferlist();
console.log("There are ", stock_count, " stocks.")
}
}
function get_preferlist() {
msg = "6".concat("--", username);
console.log("msg:", msg);
ws.onopen = function () {
ws.send(msg);
console.log(msg, " sent.")
}
ws.onmessage = function (evt) {
var received_msg = evt.data;
//data is a list!!
//you need to decode
console.log("数据已接收...", received_msg);
if (received_msg != null) {
preferlist = received_msg.replace("[", "").replace("]", "").split(',');
console.log("preferlist: ", preferlist);
document.getElementById("corner_mark").innerHTML = preferlist.length;
if (preferlist[0] == "" && preferlist.length == 1) {
exit();
}
for (var i=0; i<preferlist.length; i++) {
series.push({
name: preferlist[i],
data: []
})
}
console.log("series", series);
get_points();
}
}
ws.onclose = function () {
// 关闭 websocket
alert("Websocket has been closed.");
};
}
function to(arg) {
//go to the indicated page
//send user name when loging out
if (arg == "login.html" && username != "") {
var msg = "8".concat("--", username);
console.log("msg: ", msg);
ws.send(msg);
console.log(msg, " sent.")
ws.onmessage = function (evt) {
console.log("recieved data: ", evt.data)
if (evt.data == "True") {
//log out successfully
window.location.href = arg;
} else {
alert("Something wrong when logging out!")
return false;
}
}
} else {
window.location.href = "".concat(arg, "?user=", username);
}
}
function get_point(stock_num) {
var stock = preferlist[stock_num];
var point = new Array(2);
point[0] = new Date().getTime();
// var str = point[0].getTime().Format("yyyy-M-d-hh-mm-ss");
var str = String(point[0]);
var msg = "4".concat("--", str.slice(0,str.length-3), "--", stock);
ws.send(msg);
console.log(msg, " sent.")
ws.onmessage = function (evt) {
var received_msg = evt.data;
console.log(received_msg, " recieved.");
point[1] = parseFloat(received_msg);
return point;
}
}
function convertDateFromString(dateString) {
if (dateString) {
var arr1 = dateString.split("-");
var date = new Date(arr1[0], arr1[1], arr1[2], arr1[3], arr1[4], arr1[5]).getTime();
return date;
}
}
function get_points() {
for (var n = 0; n < preferlist.length;n++) {
var stock = preferlist[n];
console.log("stock", stock);
var points = new Array();
var msg = "3".concat("--", stock);
ws.send(msg);
console.log(msg, " sent.")
var index = 0;
ws.onmessage = function (evt) {
var received_msg = evt.data;
// console.log(received_msg, " recieved.");
var tmp = received_msg.replace("[", "").replace("]", "").split(",");
for (var i = 0; i < tmp.length; i++) {
if (series[index]["data"].length == tmp.length) {
index += 1;
}
series[index]["data"][i] = new Array(2);
console.log(tmp[i].split(':', 2)[0]);
series[index]["data"][i][0] = convertDateFromString(tmp[i].split(':', 2)[0]);
series[index]["data"][i][1] = parseFloat(tmp[i].split(':', 2)[1]);
console.log("point[", i, "]:", series[index]["data"][i]);
if (i == tmp.length - 1) {
console.log("stock_name:", preferlist[n], "series: ", series, "Points.length: ", series[index]["data"].length);
if (series.length == preferlist.length) {
console.log("The show must be going on.");
show();
} else {
continue;
}
}
}
}
}
}
var stock_series = [];
function show() {
var chart = {
type: 'spline',
// animation: Highcharts.svg, // don't animate in IE < IE 10.
marginRight: 10,
events: {
load: function () {
// set up the updating of the chart each second
var t = new Array();
for (var i = 0; i < this.series.length; i++) {
t.push(this.series[i]);
}
// var series = this.series[0];
setInterval(function () {
for (var j = 0; j < t.length; j++) {
// var tmp = get_point(j);
// console.log("tmp: ", tmp);
// var x = (new Date()).getTime(),
// y = Math.random() * 100;
t[j].addPoint(get_point(j), true, true);
// console.log(x, y)
}
}, 1000);
}
}
};
var title = {
text: 'My Stocks'
};
var xAxis = {
type: 'datetime',
tickPixelInterval: 150
};
var yAxis = {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
};
var tooltip = {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
};
var plotOptions = {
area: {
pointStart: 1940,
marker: {
enabled: false,
symbol: 'circle',
radius: 2,
states: {
hover: {
enabled: true
}
}
}
}
};
var legend = {
enabled: true
};
var exporting = {
enabled: true
};
// for (var i = 0; i < preferlist.length; i++) {
// var series = [{
// name: preferlist[i],
// data: (function () {
// // generate an array of random data
// var data = [], time = (new Date()).getTime(), j;
// for (j = 0; j <= points_buffer[i].length; j += 1) {
// console.log(points_buffer, points_buffer)
// data.push({
// x: points_buffer[i][j][0],
// y: points_buffer[i][j][1]
// });
// }
// return data;
// }())
// }];
// }
// var series= [{
// name: 'Random data',
// data: (function () {
// // generate an array of random data
// var data = [],time = (new Date()).getTime(),i;
// for (i = -19; i <= 0; i += 1) {
// data.push({
// x: time + i * 1000,
// y: Math.random()
// });
// }
// return data;
// }())
// }];
var json = {};
json.chart = chart;
json.title = title;
json.tooltip = tooltip;
json.xAxis = xAxis;
json.yAxis = yAxis;
json.legend = legend;
json.exporting = exporting;
json.series = series;
json.plotOptions = plotOptions;
Highcharts.setOptions({
global: {
useUTC: false
}
});
$('#container').highcharts(json);
};
</script>
</head>
<body class="mdc-typography pace-on mdc-theme--background crypro-theme-gradient" onload="check_user()">
<div class="crypto-loader"></div>
<div class="crypto-wrapper">
<div class="crypto-sidenav">
<nav class="crypto-navigation">
<ul class="crypto-navigation__list">
<li class="crypto-navigation__list-item mdc-ripple-surface "> </li>
<li class="crypto-navigation__list-item mdc-ripple-surface ">
<a onclick="return to('wallet.html')" style="cursor:pointer">
<i class="material-icons crypto-navigation__list-item__icon" aria-hidden="true">account_balance_wallet</i>
<span id="corner_mark" class="crypto-navigation__list-item__badge"></span>
<span class="crypto-navigation__list-item__label mdc-theme--on-surface mdc-typography--overline">
MY STOCK
</span>
</a>
</li>
<li class="crypto-navigation__list-item mdc-ripple-surface crypto-navigation__list-item--active"> <a
onclick="return to('reports.html')" style="cursor:pointer"> <em
class="material-icons crypto-navigation__list-item__icon" aria-hidden="true">bar_chart</em> <span
class="crypto-navigation__list-item__label mdc-theme--on-surface mdc-typography--overline"> All stocks
</span></a></li>
<li class="crypto-navigation__list-item mdc-ripple-surface "> </li>
<li class="crypto-navigation__list-item mdc-ripple-surface "> </li>
<li class="crypto-navigation__list-item mdc-ripple-surface ">
<a onclick="return to('login.html')" style="cursor:pointer">
<i class="material-icons crypto-navigation__list-item__icon" aria-hidden="true">power_settings_new</i>
<span class="crypto-navigation__list-item__label mdc-theme--on-surface mdc-typography--overline">
Logout
</span>
</a>
</li>
</ul>
</nav>
</div>
<main class="crypto-main">
<div class="crypto-main__content mdc-theme--text-primary-on-background">
<!-- start of ticker -->
<div class="crypto-marquee__wrapper">
<div class="crypto-marquee marquee3k" data-speed="0.40" data-pausable="true"> </div>
</div>
<!-- end of ticker -->
<div class="mdc-layout-grid">
<div class="mdc-layout-grid__inner">
<div
class="mdc-layout-grid__cell--span-3-desktop mdc-layout-grid__cell--span-8-tablet mdc-layout-grid__cell--span-4-phone">
<div class="crypto-widget">
<h2 class="crypto-widget__heading mdc-typography--overline mdc-theme--primary">
<span class="crypto-widget__heading-text">My stock</span>
<span id="current_user" class="crypto-widget__heading-border"></span>
</h2>
<div id="container" style="width: 800px; height: 800px; margin: 0 auto"></div>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
<div class="crypto-menu-switches">
<div class="crypto-menu-switches--handle">
<i class="material-icons">settings</i>
</div>
<!-- RTL switch -->
<div class="switch-wrapper mdc-theme--on-primary">
<div class="mdc-switch crypto-rtl-switch-selector">
<div class="mdc-switch__track"></div>
<div class="mdc-switch__thumb-underlay">
<div class="mdc-switch__thumb">
<input type="checkbox" id="rtl-switch" class="mdc-switch__native-control" role="switch"
aria-checked="false">
</div>
</div>
</div>
<label for="rtl-switch">RTL</label>
</div>
<!-- theme switch -->
<div class="switch-wrapper mdc-theme--on-primary">
<div class="mdc-switch crypto-theme-switch-selector">
<div class="mdc-switch__track"></div>
<div class="mdc-switch__thumb-underlay">
<div class="mdc-switch__thumb">
<input type="checkbox" id="crypto-theme-switch" class="mdc-switch__native-control" role="switch"
aria-checked="false">
</div>
</div>
</div>
<label for="crypto-theme-switch">Switch theme</label>
</div>
</div>
<!-- initialise material components js -->
<script src="assets/js/material-components-web.min.js"></script>
<script>mdc.autoInit()</script>
<!-- initialise marquee js -->
<script src="assets/js/marquee3k.js"></script>
<script>Marquee3k.init()</script>
<!-- layout js -->
<script data-pace-options='{ "ajax": false, "restartOnRequestAfter": false }' src="assets/js/pace.min.js"></script>
<script src="assets/js/apexcharts.min.js"></script>
<!-- switcher js -->
<script src="assets/js/partials/switcher.js"></script>
<!-- page specific JS -->
<script src="assets/js/pages/wallet.js"></script>
</body>
</html>