-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
159 lines (148 loc) · 4.53 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Line Chart Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
<style>
#tableContainer {
max-height: 200px;
overflow-y: auto;
text-align: center;
}
#myTable {
width: 100%;
}
#myTable th {
position: sticky;
top: 0;
background-color: #fff;
}
#myTable th,
#myTable td {
padding: 8px;
border: 1px solid black;
}
</style>
</head>
<body>
<div style="text-align: center; padding-top: 10px; font-size: small">
<h1 id="symbol"></h1>
</div>
<canvas id="myChart" width="600" height="400"></canvas>
<div style="text-align: center; padding-top: 20px; font-size: small">
<h1 id="clock"></h1>
</div>
<div id="tableContainer">
<table id="myTable">
<thead>
<tr>
<th>Symbol</th>
<th>Price</th>
<th>Timestamp</th>
<th>Predicted Price</th>
<th>Predicted Timestamp</th>
</tr>
</thead>
<tbody>
<!-- Table rows will be dynamically added here using JavaScript -->
</tbody>
</table>
</div>
<script></script>
<script>
const chart = new Chart(document.getElementById("myChart"), {
type: "line",
data: {
labels: [],
datasets: [
{
label: "Price",
data: [],
borderColor: "red",
fill: false,
},
{
label: "Prediction Price",
data: [],
borderColor: "blue",
fill: false,
},
],
},
options: {
title: {
display: true,
text: "Arima Predictions",
},
scales: {
x: {
type: "linear",
title: {
display: true,
text: "Time",
},
},
y: {
type: "linear",
title: {
display: true,
text: "Price",
},
},
},
},
});
function updateChart() {
fetch("http://localhost:3000/api/tradesWithArimaPredictions")
.then((response) => response.json())
.catch((err) => {
console.log(err);
const titleContainer = document.getElementById("symbol");
titleContainer.innerHTML = "no data to display";
const tableContainer = document.getElementById("tableContainer");
tableContainer.style.display = "none";
})
.then((res) => {
res.map((item) => {
const timestamp = new Date(item.predictionTimestamp);
// dividing by 1000 to convert it from milliseconds to seconds.
chart.data.labels.push(timestamp.getTime() / 1000);
chart.data.datasets[0].data.push(item.price);
chart.data.datasets[1].data.push(item.predictionPrice);
const clock = document.getElementById("clock");
clock.innerHTML = new Date(
Date.parse(item.timestamp)
).toLocaleString();
const symbol = document.getElementById("symbol");
symbol.innerHTML = `ARIMA prediction: ${item.symbol}`;
// Table
const table = document.getElementById("myTable");
const row = table.insertRow(-1);
const symbolCell = row.insertCell(0);
const priceCell = row.insertCell(1);
const timestampCell = row.insertCell(2);
const predictionPriceCell = row.insertCell(3);
const predictionTimestampCell = row.insertCell(4);
symbolCell.innerHTML = item.symbol;
priceCell.innerHTML = item.price;
timestampCell.innerHTML = new Date(
item.timestamp
).toLocaleString();
predictionPriceCell.innerHTML = item.predictionPrice;
predictionTimestampCell.innerHTML = new Date(
item.predictionTimestamp
).toLocaleString();
});
chart.update();
});
}
updateChart();
const interval = setInterval(() => {
chart.data.labels = [];
chart.data.datasets[0].data = [];
chart.data.datasets[1].data = [];
updateChart();
}, 5000);
</script>
</body>
</html>