async function startApp() { await printPage(); } async function printPage(){ // Load data console.log("___printPage()___"); // Print HTML let html = ""; html += "

Volvo XC60

\n"; html += "

Schedule Volvo rechanging

\n"; html += "

Schedule per left percentages in battery

\n"; html += "

How much there is battery left in the car?

"; html += "
\n"; html += "\n"; html += "\n"; html += "\n"; html += "\n"; html += "\n"; html += "
\n"; html += "

Active schedulings

\n"; html += "
\n"; document.getElementById('center').innerHTML = html; await updateVolvoSchedules(); } async function updateVolvoSchedules() { let schedules = await readVolvoSchedules(); let totalCount = schedules["schedules"].length; // Create schedule table HTML and do calculations let scheduleTableHtml = ""; scheduleTableHtml += ""; if (totalCount === 0) { scheduleTableHtml += ""; } let totalPrice = 0; for (let key in schedules["schedules"]) { let scheduleDate = schedules["schedules"][key].scheduleDate; let calculatedPrice = parseFloat(schedules["schedules"][key].calculatedPrice); let energyPrice = parseFloat(schedules["schedules"][key].energyPrice); scheduleTableHtml += ""; scheduleTableHtml += ""; scheduleTableHtml += ""; scheduleTableHtml += ""; scheduleTableHtml += "\n"; console.log("\tSchedule : " + scheduleDate); totalPrice = totalPrice + calculatedPrice; } let hours = Math.floor(totalCount/4); let minutes = 15 * (totalCount % 4); let totalCost = (totalPrice/100).toFixed(2); scheduleTableHtml += "\n"; scheduleTableHtml += "
Schedule dateEnergy priceTotal cost (cents)
No schedules found
" + scheduleDate + "" + energyPrice + "" + calculatedPrice.toFixed(3) + "
" + hours + " h " + minutes + " min" + totalCost + " €
"; let html = ""; html += "

There is total of " + hours + " hours and " + minutes + " minutes of changing! Total cost for charging is " + totalCost + " €

"; if (totalCount > 0) { html += "
\n"; html += "\n"; html += "
\n"; } html += scheduleTableHtml; document.getElementById('volvoschedules').innerHTML = html; } async function scheduleWithBatteryChargePercentage() { let element = document.getElementById('batteryleftpercentageelement'); let readyTime = document.getElementById('readytimeelement'); console.log("Scheduling Volvo per battery percentage left " + element.value + " and to be ready at " + readyTime.value + "..."); let response = await createVolvoScheduleByLeftPercentage(element.value, readyTime.value, true); console.log("Response : " + response.message); alert(response.message); await updateVolvoSchedules(); return false; } async function deleteSchedules() { console.log("Deleting Volvo schedules..."); let response = await deleteVolvoSchedules(); console.log("Response : " + response.message); await updateVolvoSchedules(); return false; } async function readVolvoSchedules() { const response = await fetch("/schedule/read/volvo"); const data = await response.json(); console.log("==> fetchSchedules: " + JSON.stringify(data)); return data; } async function createVolvoScheduleByLeftPercentage(leftPercentage, readyTime, activateScheduling) { const response = await fetch('/schedule/create/volvo/leftpercentage', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({leftPercentage: leftPercentage, readyTime: readyTime, activateScheduling: activateScheduling}) }); const data = await response.json(); console.log("==> createVolvoScheduleByLeftPercentage: " + JSON.stringify(data)); return data; } async function deleteVolvoSchedules() { const response = await fetch('/schedule/delete/volvo', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({delete: true}) }); const data = await response.json(); console.log("==> deleteVolvoSchedules: " + JSON.stringify(data)); return data; }