{% extends 'base.html' %}
{% block custom_scripts %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.6.1/socket.io.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
function getdata() {
	$.get('/getdata', function(data) {
		$("#ttemp").text(parseFloat(data.tank).toFixed(1) + " °C");
		$("#intemp").text(parseFloat(data.intemp).toFixed(1) + " °C");
		$("#dhwsetpoint").text(parseFloat(data.dhw).toFixed(1) + " °C");
		$("#hcurve").text(parseFloat(data.hcurve).toFixed(1) + " °C");
		$("#setpoint").text(parseFloat(data.setpoint).toFixed(1) + " °C");
		$("#mode").text(data.mode)
		$("#flimiton").text(data.flimiton)
switch(data.flimiton) {
		case "0":
		    if($("#flrelay").text() != "WYŁ") {
		        $("#flrelay").text("WYŁ")
			    }
			break;
		case "1":
		    if($("#flrelay").text() != "WŁ") {
		        $("#flrelay").text("WŁ")
			    }
			break;
			    }
switch(data.mode){
		case "quiet":
		    if($("#mode").text() != "CICHY") {
			$("#mode").text("CICHY")
			    }
			break;
		case "eco":
		    if($("#mode").text() != "EKO") {
			$("#mode").text("EKO")
			    }
			break;
		 case "turbo":
		    if($("#mode").text() != "TURBO") {
			$("#mode").text("TURBO")
			    }
			break;
	    default:
	    }

		})
	$.get('/getparams', function(data) {
		$("#archerror").text(data.archerror)
		$("#twi").text(data.twitwo[0]+" °C")
		$("#two").text(data.twitwo[1]+" °C")
        $("#thi").text(data.thitho[0]+" °C")
        $("#tho").text(data.thitho[1]+" °C")
        $("#pdset").text(data.pdps[0]+" bar")
        $("#pdact").text(data.pdps[1]+" bar")
		$("#psset").text(data.pdps[2]+" bar")
        $("#psact").text(data.pdps[3]+" bar")
		$("#tsatpsset").text(data.tsatpd[0]+" °C")
		$("#tsatpsact").text(data.tsatpd[1]+" °C")
		$("#tsatpdset").text(data.tsatpd[0]+" °C")
		$("#tsatpdact").text(data.tsatpd[1]+" °C")
		$("#eevlevel").text(data.eevlevel+" °")
        $("#deltat").text((data.twitwo[1]-data.twitwo[0]).toFixed(1)+" °C")
        $("#fact").text(data.compinfo[0]+" Hz")
        $("#fset").text(data.compinfo[1]+" Hz")
        $("#ccurr").text(data.compinfo[2]+" A")
        $("#cvolt").text(data.compinfo[3]+" V")
        $("#ctemp").text(data.compinfo[4]+" °C")
        $("#fan1").text(data.fans[0]+" RPM")
		$("#fan2").text(data.fans[1]+" RPM")
		$("#tao").text(data.tao+" °C")
		$("#td").text(data.tdts[0]+" °C")
		$("#ts").text(data.tdts[1]+" °C")
		$("#pump").text(data.pump)
		$("#chkwhpd").text(parseFloat(data.chkwhpd).toFixed(1) + " kWh");
		$("#dhwkwhpd").text(parseFloat(data.dhwkwhpd).toFixed(1) + " kWh");
			let dailykwh = parseFloat(data.chkwhpd) + parseFloat(data.dhwkwhpd);
		$("#dailykwh").text(dailykwh.toFixed(1) + " kWh");
		$("#threeway").text(data.threeway)
		$("#flrelay").text(data.flrelay)
		
		// Pobranie wymaganych temperatur
		let ts = parseFloat(data.tdts[1]); // Ts
		let tsat_suction = parseFloat(data.tsatpd[1]); // T_sat Ps
		let td = parseFloat(data.tdts[0]); // Td
		let tsat_discharge = parseFloat(data.tsatpd[1]); // T_sat Pd

		// Obliczenia superheat i subcooling z wartościami bezwzględnymi
		let superheat = Math.abs(ts - tsat_suction).toFixed(1);
		let subcooling = Math.abs(tsat_discharge - td).toFixed(1);

		// Aktualizacja tabeli
		$("#superheat").text(superheat + " °C");
		$("#subcooling").text(subcooling + " °C");
switch(data.threeway) {
	    case "CH":
			if($("#threeway").text() != "C.O") {
			    $("#threeway").text("C.O")
				}
			break;
	    case "DHW":
			if($("#threeway").text() != "C.W.U") {
			    $("#threeway").text("C.W.U")
			}
			break;
	    default:
		}
switch(data.pump) {
	    case "ON":
			if($("#pump").text() != "WŁ") {
			    $("#pump").text("WŁ")
				}
			break;
	    case "OFF":
			if($("#pump").text() != "WYŁ") {
			    $("#pump").text("WYŁ")
			}
			break;
	    default:
		}
	    });
	}
//setInterval(getdata, 2000);
</script>
{% endblock %}
{% block page_body %}

<div class="row justify-content-center">
        <div class="col text-center p-3 h2" data-i18n="par.chdhw">Parametry CO i CWU</div>
</div>

<div class="row justify-content-center">
	<div class="col col-md-8 col-lg-5">
<table class="table table-striped table-hover" >
    <thead class="table-success">
        <tr>
            <th>#</th>
            <th data-i18n="par.param">Parametr</th>
	    <th data-i18n="par.val">Wartość</th>
        </tr>
    </thead>
    <tbody class="table-group-divider">
        <tr><td>01</td><td data-i18n="par.curintemp">Aktualna w domu</td><td id="intemp"></td></tr>
        <tr><td>02</td><td data-i18n="par.chsetpoint">Zadana w domu</td><td id="setpoint"></td></tr>
        <tr><td>03</td><td data-i18n="par.chhcurve">Zadana CO</td><td id="hcurve"></td></tr>
        <tr><td>04</td><td data-i18n="par.curdhw">Aktualna CWU</td><td id="ttemp"></td></tr>
        <tr><td>05</td><td data-i18n="par.setdhw">Zadana CWU</td><td id="dhwsetpoint"></td></tr>
    </tbody>
</table>
	</div>
</div>

<div class="row justify-content-center">
        <div class="col text-center p-3 h2" data-i18n="par.unit">Parametry jednostki</div>
</div>

<div class="row justify-content-center">
        <div class="col col-md-8 col-lg-5">

<table class="table table-striped table-hover">
    <thead class="table-success">
        <tr>
            <th class="col-num">#</th>
            <th class="col-param" data-i18n="par.param">Parametr</th>
            <th class="col-value" data-i18n="par.val">Wartość</th>
			<th class="col-code" data-i18n="par.code">Kod</th>
        </tr>
    </thead>
    <tbody class="table-group-divider">
        
        <tr><td>01</td><td data-i18n="par.twi">Twi - Temp. wody na wlocie wymiennika</td><td id="twi"><td>A53</td></td></tr>
        <tr><td>02</td><td data-i18n="par.two">Two - Temp. wody na wylocie wymiennika</td><td id="two"><td>A54</td></td></tr>
		<tr><td>03</td><td data-i18n="par.twitwo">ΔTwoTwi - Różnica pomiędzy Two i Twi</td><td id="deltat"><td>-</td></td></tr>
        <tr><td>04</td><td data-i18n="par.thi">Thi - Temp. czynnika na wlocie wymiennika</td><td id="thi"><td>A55</td></td></tr>
        <tr><td>05</td><td data-i18n="par.tho">Tho - Temp. czynnika na wylocie wymiennika</td><td id="tho"><td>A56</td></td></tr>
		<tr><td>06</td><td data-i18n="par.ts">Ts - Temp. strony ssącej sprężarki</td><td id="ts"><td>B56</td></td></tr>
		<tr><td>07</td><td data-i18n="par.td">Td - Temp. strony tłocznej sprężarki</td><td id="td"><td>B55</td></td></tr>
		<tr><td>08</td><td data-i18n="par.psact">Ps act - Ciś. akt. strony ssącej sprężarki</td><td id="psact"><td>B52</td></td></tr>
		<tr><td>09</td><td data-i18n="par.psset">Ps set - Ciś. zad. strony ssącej sprężarki</td><td id="psset"><td>B51</td></td></tr>
        <tr><td>10</td><td data-i18n="par.pdact">Pd act - Ciś. akt. strony tłocznej sprężarki</td><td id="pdact"><td>B4E</td></td></tr>
		<tr><td>11</td><td data-i18n="par.pdset">Pd set - Ciś. zad. strony tłocznej sprężarki</td><td id="pdset"><td>B4D</td></td></tr>
		<tr><td>12</td><td data-i18n="par.tsatpsact">T Sat Ps Act - Temp. aktualna nasycenia Ps</td><td id="tsatpsact"><td>B54</td></td></tr>
		<tr><td>13</td><td data-i18n="par.tsatpsset">T Sat Ps Set - Temp. zadana nasycenia Ps</td><td id="tsatpsset"><td>B53</td></td></tr>
		<tr><td>14</td><td data-i18n="par.tsatpdact">T Sat Pd Act - Temp. aktualna nasycenia Pd</td><td id="tsatpdact"><td>B50</td></td></tr>
		<tr><td>15</td><td data-i18n="par.tsatpdset">T Sat Pd Set - Temp. zadana nasycenia Pd</td><td id="tsatpdset"><td>B4F</td></td></tr>
		<tr><td>16</td><td data-i18n="par.eev">EEV - Elektroniczny zawór rozprężny</td><td id="eevlevel"></td><td>B4C</td></tr>
		<tr><td>17</td><td data-i18n="par.tao">Tao - Temperatura otoczenia</td><td id="tao"><td>B57</td></td></tr>
        <tr><td>18</td><td data-i18n="par.fact">F act - Aktualna częstotliwość sprężarki</td><td id="fact"><td>B49</td></td></tr>
        <tr><td>19</td><td data-i18n="par.fset">F set - Zadana częstotliwość sprężarki</td><td id="fset"><td>B58</td></td></tr>
		<tr><td>20</td><td data-i18n="par.flimit">F limit - Ograniczenie częstotliowści</td><td id="flrelay"><td>-</td></td></tr>
        <tr><td>21</td><td data-i18n="par.ccur">C curr - Prąd sprężarki</td><td id="ccurr"><td>B5B</td></td></tr>
        <tr><td>22</td><td data-i18n="par.cvolt">C volt - Napięcie sprężarki</td><td id="cvolt"><td>B5C</td></td></tr>
        <tr><td>23</td><td data-i18n="par.ctemp">C temp - Temperatura sprężarki</td><td id="ctemp"><td>B5A</td></td></tr>
        <tr><td>24</td><td data-i18n="par.fan1">Fan 1 - Prędkość wentylatora -1-</td><td id="fan1"><td>B4A</td></td></tr>
        <tr><td>25</td><td data-i18n="par.fan2">Fan 2 - Prędkość wentylatora -2-</td><td id="fan2"><td>B4B</td></td></tr>
        <tr><td>26</td><td data-i18n="par.pump">Pump - Status pompy obiegowej</td><td id="pump"><td>A05</td></td></tr>
        <tr><td>27</td><td data-i18n="par.threeway">Threeway - Status zaworu 3-drożnego</td><td id="threeway"><td>A53</td></td></tr>
		<tr><td>28</td><td data-i18n="par.mode">Mode - Tryb pracy jednostki</td><td id="mode"><td>B40</td></td></tr>
        <tr><td>29</td><td data-i18n="par.archerror">Archerror - Ostatnio zapisane błędy</td><td id="archerror"><td>A5B</td></td></tr>
   
    </tbody>
</table>
        </div>
</div>

<div class="row justify-content-center">
	<div class="col text-center p-3 h2" data-i18n="par.supsub">Przegrzanie/Dochłodzenie czynnika</div>
</div>
<div class="row justify-content-center">
        <div class="col col-md-8 col-lg-5">

<table class="table table-striped table-hover">
    <thead class="table-success">
        <tr>
            <th class="col-num">#</th>
            <th class="col-param" data-i18n="par.param">Parametr</th>
            <th class="col-value" data-i18n="par.val">Wartość</th>
        </tr>
    </thead>
    <tbody class="table-group-divider">
        <tr><td>01</td><td data-i18n="par.superheat">Przegrzanie</td><td id="superheat"></td></tr>
        <tr><td>02</td><td data-i18n="par.subcooling">Dochłodzenie</td><td id="subcooling"></td></tr>
	</tbody>
</table>
	</div>
</div>

<div class="row justify-content-center">
        <div class="col text-center p-3 h2" data-i18n="par.energy">Zużycie energii</div>
</div>
<div class="row justify-content-center">
        <div class="col col-md-8 col-lg-5">

<table class="table table-striped table-hover">
    <thead class="table-success">
        <tr>
            <th class="col-num">#</th>
            <th class="col-param" data-i18n="par.param">Parametr</th>
            <th class="col-value" data-i18n="par.val">Wartość</th>
        </tr>
    </thead>
    <tbody class="table-group-divider">
        <tr><td>01</td><td data-i18n="par.chec">Zużycie CO</td><td id="chkwhpd"></td></tr>
        <tr><td>02</td><td data-i18n="par.dhwec">Zużycie CWU</td><td id="dhwkwhpd"></td></tr>
        <tr><td>03</td><td data-i18n="par.ec">Łączne zużycie</td><td id="dailykwh"></td></tr>
	</tbody>
</table>
	</div>
</div>
<script src="{{ url_for('static', filename='socket.js') }}"></script>
{% endblock %}

