Update templates/index.html
Browse files- templates/index.html +71 -177
templates/index.html
CHANGED
|
@@ -1,177 +1,71 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 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 |
-
$.ajax({
|
| 73 |
-
url: 'https://api-pluang.pluang.com/api/v3/asset/gold/pricing?daysLimit=30', // Ganti dengan URL API yang sesuai
|
| 74 |
-
type: 'GET',
|
| 75 |
-
success: function(data) {
|
| 76 |
-
var dates = data.data.history.map(function(item) {
|
| 77 |
-
return item.updated_at.split('T')[0]; // Ambil hanya tanggal
|
| 78 |
-
});
|
| 79 |
-
sellPrices = data.data.history.map(function(item) {
|
| 80 |
-
return item.sell;
|
| 81 |
-
});
|
| 82 |
-
|
| 83 |
-
// Balikkan urutan data (dari data pertama ke terakhir)
|
| 84 |
-
dates.reverse();
|
| 85 |
-
sellPrices.reverse();
|
| 86 |
-
|
| 87 |
-
// Tampilkan grafik harga sell
|
| 88 |
-
var ctx = document.getElementById('sell-chart').getContext('2d');
|
| 89 |
-
var sellChart = new Chart(ctx, {
|
| 90 |
-
type: 'line',
|
| 91 |
-
data: {
|
| 92 |
-
labels: dates, // Tanggal
|
| 93 |
-
datasets: [{
|
| 94 |
-
label: 'Harga Sell Emas',
|
| 95 |
-
data: sellPrices, // Harga sell
|
| 96 |
-
borderColor: 'rgba(75, 192, 192, 1)',
|
| 97 |
-
borderWidth: 2,
|
| 98 |
-
fill: false
|
| 99 |
-
}]
|
| 100 |
-
},
|
| 101 |
-
options: {
|
| 102 |
-
responsive: true,
|
| 103 |
-
scales: {
|
| 104 |
-
y: {
|
| 105 |
-
beginAtZero: false
|
| 106 |
-
}
|
| 107 |
-
}
|
| 108 |
-
}
|
| 109 |
-
});
|
| 110 |
-
},
|
| 111 |
-
error: function(error) {
|
| 112 |
-
alert('Terjadi kesalahan saat memanggil API untuk grafik: ' + error.responseJSON.error);
|
| 113 |
-
}
|
| 114 |
-
});
|
| 115 |
-
});
|
| 116 |
-
|
| 117 |
-
// Fungsi untuk mengambil data dari grafik dan mengirimkan ke Flask
|
| 118 |
-
function getDataFromChart() {
|
| 119 |
-
// Ambil 3 harga terakhir dari data grafik
|
| 120 |
-
var lastThreeDays = sellPrices.slice(-3);
|
| 121 |
-
|
| 122 |
-
return {
|
| 123 |
-
features: lastThreeDays
|
| 124 |
-
};
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
// Fungsi untuk memanggil endpoint Flask dengan data dari grafik
|
| 128 |
-
$('#auto-predict-btn').click(function() {
|
| 129 |
-
var inputData = getDataFromChart();
|
| 130 |
-
console.log(inputData);
|
| 131 |
-
|
| 132 |
-
$.ajax({
|
| 133 |
-
url: '/auto-predict',
|
| 134 |
-
type: 'POST',
|
| 135 |
-
contentType: 'application/json',
|
| 136 |
-
data: JSON.stringify(inputData),
|
| 137 |
-
success: function(data) {
|
| 138 |
-
$('#auto-last-price').text(`Harga Emas Terakhir: ${data.last_price}`);
|
| 139 |
-
$('#auto-predicted-price').text(`Prediksi Harga Emas: ${data.predicted_value}`);
|
| 140 |
-
$('#auto-percentage-change').text(`Perubahan: ${data.percentage_change}`);
|
| 141 |
-
},
|
| 142 |
-
error: function(error) {
|
| 143 |
-
alert('Terjadi kesalahan: ' + error.responseJSON.error);
|
| 144 |
-
}
|
| 145 |
-
});
|
| 146 |
-
});
|
| 147 |
-
|
| 148 |
-
// Fungsi untuk menangani prediksi berdasarkan input pengguna
|
| 149 |
-
$('#input-form').submit(function(event) {
|
| 150 |
-
event.preventDefault();
|
| 151 |
-
|
| 152 |
-
var sell_1 = parseFloat($('#sell-1').val()); // Mengonversi input menjadi angka
|
| 153 |
-
var sell_2 = parseFloat($('#sell-2').val()); // Mengonversi input menjadi angka
|
| 154 |
-
var sell_3 = parseFloat($('#sell-3').val()); // Mengonversi input menjadi angka
|
| 155 |
-
var last_price = sell_1; // Anda bisa sesuaikan jika ingin mengambil nilai lainnya
|
| 156 |
-
|
| 157 |
-
$.ajax({
|
| 158 |
-
url: '/predict',
|
| 159 |
-
type: 'POST',
|
| 160 |
-
contentType: 'application/json',
|
| 161 |
-
data: JSON.stringify({
|
| 162 |
-
features: [sell_1, sell_2, sell_3],
|
| 163 |
-
last_price: [last_price]
|
| 164 |
-
}),
|
| 165 |
-
success: function(data) {
|
| 166 |
-
$('#input-predicted-price').text(`Prediksi Harga Emas: ${data.predicted_value}`);
|
| 167 |
-
$('#input-percentage-change').text(`Perubahan: ${data.percentage_change}`);
|
| 168 |
-
},
|
| 169 |
-
error: function(error) {
|
| 170 |
-
alert('Terjadi kesalahan: ' + error.responseJSON.error);
|
| 171 |
-
}
|
| 172 |
-
});
|
| 173 |
-
});
|
| 174 |
-
|
| 175 |
-
</script>
|
| 176 |
-
</body>
|
| 177 |
-
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Stock Price Prediction</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
font-family: Arial, sans-serif;
|
| 10 |
+
background-color: #f4f4f9;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
display: flex;
|
| 14 |
+
justify-content: center;
|
| 15 |
+
align-items: center;
|
| 16 |
+
height: 100vh;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.container {
|
| 20 |
+
background-color: #fff;
|
| 21 |
+
padding: 20px;
|
| 22 |
+
border-radius: 8px;
|
| 23 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
| 24 |
+
width: 400px;
|
| 25 |
+
text-align: center;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
.container h1 {
|
| 29 |
+
margin-bottom: 20px;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.result {
|
| 33 |
+
font-size: 18px;
|
| 34 |
+
margin-top: 20px;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.result p {
|
| 38 |
+
margin: 10px 0;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.button {
|
| 42 |
+
background-color: #007BFF;
|
| 43 |
+
color: white;
|
| 44 |
+
padding: 10px 20px;
|
| 45 |
+
border: none;
|
| 46 |
+
border-radius: 5px;
|
| 47 |
+
cursor: pointer;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.button:hover {
|
| 51 |
+
background-color: #0056b3;
|
| 52 |
+
}
|
| 53 |
+
</style>
|
| 54 |
+
</head>
|
| 55 |
+
<body>
|
| 56 |
+
<div class="container">
|
| 57 |
+
<h1>Prediksi Harga Saham ADARO</h1>
|
| 58 |
+
<form method="GET" action="/predict">
|
| 59 |
+
<button type="submit" class="button">Dapatkan prediksi</button>
|
| 60 |
+
</form>
|
| 61 |
+
|
| 62 |
+
{% if stock %}
|
| 63 |
+
<div class="result">
|
| 64 |
+
<p><strong>Harga hari ini:</strong> Rp.{{ price_today }}</p>
|
| 65 |
+
<p><strong>Prediksi harga besok:</strong> Rp.{{ predicted_price }}</p>
|
| 66 |
+
<p><strong>Perubahan (%):</strong> {{ change_percent }}%</p>
|
| 67 |
+
</div>
|
| 68 |
+
{% endif %}
|
| 69 |
+
</div>
|
| 70 |
+
</body>
|
| 71 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|