feat: rollback prediction endpoint
Browse files
public/js/infographic/stock_prediction/inference.js
CHANGED
|
@@ -5,8 +5,8 @@ const predict = async () => {
|
|
| 5 |
loadingSpinner.classList.remove('d-none')
|
| 6 |
loadingSpinner.classList.add('show')
|
| 7 |
|
| 8 |
-
|
| 9 |
-
const apiUrl = '/prediction'
|
| 10 |
|
| 11 |
try {
|
| 12 |
const response = await fetch(apiUrl, {
|
|
@@ -17,7 +17,8 @@ const predict = async () => {
|
|
| 17 |
},
|
| 18 |
body: JSON.stringify({
|
| 19 |
days: parseInt(days),
|
| 20 |
-
issuer: `${stock_name}`
|
|
|
|
| 21 |
})
|
| 22 |
})
|
| 23 |
|
|
|
|
| 5 |
loadingSpinner.classList.remove('d-none')
|
| 6 |
loadingSpinner.classList.add('show')
|
| 7 |
|
| 8 |
+
const apiUrl = 'https://qywok-cryptocurrency-prediction.hf.space/crypto/prediction'
|
| 9 |
+
// const apiUrl = '/prediction'
|
| 10 |
|
| 11 |
try {
|
| 12 |
const response = await fetch(apiUrl, {
|
|
|
|
| 17 |
},
|
| 18 |
body: JSON.stringify({
|
| 19 |
days: parseInt(days),
|
| 20 |
+
// issuer: `${stock_name}`
|
| 21 |
+
currency: `${stock_name}`
|
| 22 |
})
|
| 23 |
})
|
| 24 |
|
public/js/infographic/stock_prediction/update_pred_chart.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
| 1 |
const updatePredictionChart = (response) => {
|
| 2 |
-
const actualDates = response.actuals.map(entry => entry.date)
|
| 3 |
-
const actualPrices = response.actuals.map(entry => entry.price)
|
| 4 |
|
| 5 |
-
const
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
const labels = [...actualDates, ...predictionDates]
|
| 9 |
const actualData = [...actualPrices, ...Array(predictionPrices.length).fill(null)]
|
|
|
|
| 1 |
const updatePredictionChart = (response) => {
|
| 2 |
+
// const actualDates = response.actuals.map(entry => entry.date)
|
| 3 |
+
// const actualPrices = response.actuals.map(entry => entry.price)
|
| 4 |
|
| 5 |
+
const actualDates = response.data.predictions
|
| 6 |
+
.actuals.map(entry => entry.date)
|
| 7 |
+
const actualPrices = response.data.predictions
|
| 8 |
+
.actuals.map(entry => entry.price)
|
| 9 |
+
|
| 10 |
+
// const predictionDates = response.predictions.map(entry => entry.date)
|
| 11 |
+
// const predictionPrices = response.predictions.map(entry => entry.price)
|
| 12 |
+
|
| 13 |
+
const predictionDates = response.data.predictions
|
| 14 |
+
.predictions.map(entry => entry.date)
|
| 15 |
+
const predictionPrices = response.data.predictions
|
| 16 |
+
.predictions.map(entry => entry.price)
|
| 17 |
|
| 18 |
const labels = [...actualDates, ...predictionDates]
|
| 19 |
const actualData = [...actualPrices, ...Array(predictionPrices.length).fill(null)]
|
public_dist/js/infographic/stock_prediction/inference.js
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
const predict=async()=>{const
|
|
|
|
| 1 |
+
const predict=async()=>{const o=document.getElementById("predictionDays").value,e=document.getElementById("loadingSpinner");e.classList.remove("d-none"),e.classList.add("show");const a="https://qywok-cryptocurrency-prediction.hf.space/crypto/prediction";try{const t=await fetch(a,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({days:parseInt(o),currency:`${stock_name}`})});if(!t.ok)throw new Error("Network response was not ok");const n=await t.json();updatePredictionChart(n)}catch(t){console.error("Error fetching data:",t),alert("Terjadi kesalahan saat memproses prediksi. Silakan coba lagi.")}finally{e.classList.remove("show"),e.classList.add("d-none")}};
|
public_dist/js/infographic/stock_prediction/update_pred_chart.js
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
const updatePredictionChart=a=>{const n=a.actuals.map(t=>t.date),r=a.actuals.map(t=>t.price),s=a.predictions.map(t=>t.date),
|
|
|
|
| 1 |
+
const updatePredictionChart=a=>{const n=a.data.predictions.actuals.map(t=>t.date),r=a.data.predictions.actuals.map(t=>t.price),s=a.data.predictions.predictions.map(t=>t.date),i=a.data.predictions.predictions.map(t=>t.price),o=[...n,...s],l=[...r,...Array(i.length).fill(null)],d=[...Array(r.length).fill(null),...i];if(predictionChart)predictionChart.data.labels=o,predictionChart.data.datasets[0].data=l,predictionChart.data.datasets[1].data=d,predictionChart.update();else{const t=document.getElementById("predictionChart").getContext("2d");let c={labels:o,datasets:[{label:"Data Historiskal",data:l,borderColor:"rgba(75, 192, 192, 1)",backgroundColor:"rgba(75, 192, 192, 0.2)",borderWidth:2,fill:!1,tension:.1,pointRadius:2,pointHoverRadius:5},{label:"Prediksi",data:d,borderColor:"rgba(255, 99, 132, 1)",backgroundColor:"rgba(255, 99, 132, 0.2)",borderWidth:2,borderDash:[5,5],fill:!1,tension:.1,pointRadius:3,pointHoverRadius:6}]},f={title:{display:!0,text:`${stock_name} - Prediksi Harga Saham`,color:"#ffffff",font:{size:16,weight:"bold"}},legend:{labels:{color:"#ffffff",usePointStyle:!0,padding:20}},tooltip:{mode:"index",intersect:!1,backgroundColor:"rgba(26, 26, 46, 0.9)",titleColor:"#ffffff",bodyColor:"#ffffff",borderColor:"#00d4aa",borderWidth:1,callbacks:{label:function(e){return e.dataset.label+": Rp "+e.parsed.y.toLocaleString("id-ID")}}}},p={x:{type:"category",title:{display:!0,text:"Tanggal",color:"#ffffff"},grid:{color:"rgba(255, 255, 255, 0.1)"},ticks:{color:"#a0a0a0"}},y:{beginAtZero:!1,title:{display:!0,text:"Harga (Rp)",color:"#ffffff"},grid:{color:"rgba(255, 255, 255, 0.1)"},ticks:{color:"#a0a0a0",callback:function(e){return"Rp "+e.toLocaleString("id-ID")}}}};predictionChart=new Chart(t,{type:"line",data:c,options:{responsive:!0,maintainAspectRatio:!1,plugins:f,scales:p,interaction:{mode:"nearest",axis:"x",intersect:!1},elements:{point:{hoverBorderWidth:3}}}})}};
|