New, updated version of web. Might contain customizations

This commit is contained in:
2019-08-21 15:44:49 +02:00
parent c3850b6e19
commit 47326ed774
11 changed files with 600 additions and 536 deletions

View File

@@ -1,14 +1,12 @@
var hours = 24;
var granularity = '2m';
var granularity = '5m';
var end = 0;
var graphdata = "https://bastart.spoton.cz/data/solar_monitor?range=24h&granularity=2m&end=0h";
var retention = 'monthly';
var graphdata = "https://bastart.spoton.cz/data/solar_monitor?range=24h&granularity=5m&end=0h&retention=monthly";
sol = new Dygraph(
// containing div
document.getElementById("solar"),
// CSV or path to a CSV file.
graphdata
,{
//labels: ['time','V_solar','Isolar', P_solar, P_cons],
axes : {
x : {
drawGrid: true,
@@ -16,80 +14,82 @@ graphdata
},
y : {
drawGrid: false,
drawAxis : true
drawAxis: true,
valueRange: [44.5,55]
},
y2 : {
drawGrid: false,
drawAxis: true,
independentTicks: true
independentTicks: true,
customBars: true,
valueRange: [0,1300]
}
},
rollPeriod: 5,
visibility: [true, false, true, true],
rollPeriod: 3,
interactionModel: {},
connectSeparatedPoints: true,
series:{
'V_solar': {
axis: 'y',
color: '#ffd020',
fillGraph: true,
fillAlpha: 0.4
},
'I_solar': {
axis: 'y',
color: '#ff1100'
},
'P_solar': {
axis: 'y2',
color: '#1111ff',
fillGraph: true,
fillAlpha: 0.4
color: '#ff5500'
},
'P_cons': {
axis: 'y2',
color: '#ff1111',
fillGraph: true,
fillAlpha: 0.4
'V_array': {
axis: 'y',
color: '#666'
}
},
ylabel: '<span style="color:#ffd020;">[V]</span>/<span style="color:#ff1100;">[A]</span>',
y2label: '<span style="color:#111177;">Solar / Consumption [W]</span>',
ylabel: '<span style="color:#666;">Battery [V]</span>',
y2label: '<span style="color:#ff2200;">Power [W]</span>',
labelsDiv: 'solar_labels',
legend: 'always'
legend: 'always',
customBars: true
}
);
function refreshGraph(){
graphdata = "https://bastart.spoton.cz/data/solar_monitor?range=" + hours + "h&granularity=" + granularity + "&end=" + end + "h";
graphdata = "https://bastart.spoton.cz/data/solar_monitor?range=" + hours + "h&granularity=" + granularity + "&end=" + end + "h&retention=" + retention;
sol.updateOptions({'file': graphdata});
//power.updateOptions({'file': graphdata});
}
function setHours(hours_to_set){
hours = hours_to_set;
switch(hours){
case '1':
granularity = '30s';
granularity = '10s';
retention = 'monthly';
break;
case '6':
granularity = '1m';
granularity = '10s';
retention = 'monthly';
break;
case '12':
granularity = '1m';
granularity = '2m';
retention = 'monthly';
break;
case '24':
granularity = '2m';
granularity = '5m';
retention = 'monthly';
break;
case '168':
granularity = '20m';
granularity = '15m';
retention = 'monthly';
break;
case '720':
granularity = '1h';
granularity = '3h';
retention = 'yearly';
break;
case '8760':
granularity = '6h';
retention = 'yearly';
break;
case '87600':
granularity = '24h';
retention = 'yearly';
break;
default:
granularity = '10m';
granularity = '5m';
retention = 'monthly';
}
end = 0;
//document.getElementById('xxx').innerHTML = graphdata;
@@ -118,3 +118,49 @@ function setForth(){
//document.getElementById('xxx').innerHTML = graphdata;
refreshGraph();
}
function getPageContents(callback,url,params) {
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari, SeaMonkey
xmlhttp=new XMLHttpRequest();
}
else{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if(params!=null) {
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
} else {
xmlhttp.open("GET", url, true);
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
callback(xmlhttp.responseText);
}
}
xmlhttp.send(params);
}
counter = 0;
function refreshValues(){
fresh_vals_url = '/data/solar_realtime_data?type=json'
getPageContents(function(result){freshVals=JSON.parse(result);},
fresh_vals_url)
document.getElementById('timestamp').innerHTML = freshVals.time;
document.getElementById('array_voltage').innerHTML = freshVals.V_array;
document.getElementById('array_percent').innerHTML = freshVals.perc_array;
document.getElementById('charge_current').innerHTML = freshVals.ChCurr;
document.getElementById('solar_power').innerHTML = freshVals.Psol;
document.getElementById('pmax_day').innerHTML = freshVals.Pmax_day;
counter = counter + 5000;
if(counter >= 360000){
refreshGraph();
document.getElementById('graph_timestamp').innerHTML = freshVals.time;
counter = 0;
}
}
var intervalVal = setInterval(refreshValues, 5000);