meterN 0.8

Talks about metering
Locked
ambramia
Posts: 25
Joined: Thu Apr 21, 2016 11:33 am

Re: meterN 0.8

Post by ambramia » Thu May 12, 2016 2:15 pm

Hi jeanmarc, I have the same problem as paolomasse and I tested your posted code, it works but not completely, by clicking on the day goes in the exact detailed meter only for (in my case):
Consumi, produzione, Immissioni, prelievi, autoconsumo, bolletta e risparmio
while for:
Prelievi F1, Prelievi F23, Autocons F1, Autocons F23
clicking on the day goes in the first meter (Consumi in my case)
same problem in the index page in the last 15 days same meter.
Now is working your last posted code for readings.php
Please can you see here
http://ambramia.sytes.net:8080/metern/
many thanks
Antonio

jeanmarc
Posts: 1917
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 0.8

Post by jeanmarc » Thu May 12, 2016 2:43 pm

Hmm i see, it's because your meters names contain spaces and dot.. Is this one ok as detailed.php ?

Code: Select all

<?php
include('styles/globalheader.php');
include('config/config_main.php');

$dir    = 'data/csv/';
$output = glob($dir . '*.csv');
sort($output);
$contalogs = count($output);

$ollog  = $output[0];
$lstlog = $output[$contalogs - 1];

$startdate = (substr($ollog, -12, 4)) . ',' . (substr($ollog, -8, 2)) . '-1,' . (substr($ollog, -6, 2));
$stopdate  = (substr($lstlog, -12, 4)) . ',' . (substr($lstlog, -8, 2)) . '-1,' . (substr($lstlog, -6, 2));
echo "
<script>
  $(function() {
	$('#datepickid' ).datepicker({ dateFormat: 'dd/mm/yy' ,minDate: new Date($startdate), maxDate: new Date($stopdate)});
	$('#oneDayBack').click(function() {
		var new_dateb = $('#datepickid').datepicker('getDate');
		new_dateb.setDate(new_dateb.getDate() - 1);
		$('#datepickid').datepicker('setDate', new_dateb);
	});
	$('#oneDayFwd').click(function() {
		var new_datef = $('#datepickid').datepicker('getDate');
		new_datef.setDate(new_datef.getDate() + 1);
		$('#datepickid').datepicker('setDate', new_datef);
	});
    });
</script>";

$regexp = "/[0-9]{1,2}+\/[0-9]{1,2}+\/[0-9]{4}/";
if (!empty($_POST['date1']) && preg_match($regexp, $_POST['date1'])) {
    $date1 = $_POST['date1'];
} else {
    $date1 = (substr($lstlog, -6, 2)) . '/' . (substr($lstlog, -8, 2)) . '/' . (substr($lstlog, -12, 4));
}
if (!empty($_GET['date2']) && is_numeric($_GET['date2'])) {
    $date2 = $_GET['date2'];
    $ts    = strftime("%s", floor($date2 / 1000));
    $date1 = date('d/m/Y', $ts);
}

$grid  = array();
$selec = false;

for ($i = 1; $i <= $NUMMETER; $i++) {
    include("config/config_met$i.php");
	if (!empty(htmlspecialchars($_POST["${'METNAME'.$i}"])) && is_string($_POST["${'METNAME'.$i}"]))  {
        $check[$i] = 'on';
        $selec     = true;
	} elseif (!empty(htmlspecialchars($_GET["${'METNAME'.$i}"])) && is_string($_GET["${'METNAME'.$i}"]))  {	
		$check[$i] = 'on';
        $selec     = true;
    } else {
        $check[$i] = 'off';
    }
    if (${'TYPE' . $i} == 'Elect' && ${'PROD' . $i} != 0 && !isset($grid[${'PHASE' . $i}])) {
        $grid[${'PHASE' . $i}] = ${'PHASE' . $i};
    }
}

sort($grid);
$cnt   = count($grid);
$sscnt = 0;
$efcnt = 0;

for ($i = 0; $i < $cnt; $i++) {
    if (!empty($_POST["ss$i"])) {
        $ss[$i] = $_POST["ss$i"];
        $selec  = true;
        if ($ss[$i] != 0) {
            $selfsuff[$sscnt] = $ss[$i];
            $sscnt++;
        }
    } else {
        $ss[$i] = 0;
    }
    if (!empty($_POST["ef$i"])) {
        $ef[$i] = $_POST["ef$i"];
        $selec  = true;
        if ($ef[$i] != 0) {
            $energf[$efcnt] = $ef[$i];
            $efcnt++;
        }
    } else {
        $ef[$i] = 0;
    }
}

if (!$selec) { //Nothing selected
    $check[1] = 'on';
}

$titledate = substr($date1, 0, 10);
$csvdate1  = (substr($date1, 6, 4)) . (substr($date1, 3, 2)) . (substr($date1, 0, 2)) . ".csv";
?>
<script type="text/javascript">

$(document).ready(function()
{
Highcharts.setOptions({
global: {
useUTC: false
},
lang: {
decimalPoint: '<?php
echo $DPOINT;
?>',
thousandsSep: '<?php
echo "$THSEP',
drillUpText: '$lgDRILLUP',
loading: '$lgLOAD',
printChart: '$lgPRINT',
resetZoom: '$lgRESETZ'
";
?>
}
});

var Mychart, options = {
chart: {
backgroundColor: null,
zoomType: 'xy',
resetZoomButton: {
                position: {
                    align: 'right',
                    verticalAlign: 'top'
                }
},
loading: {
 labelStyle: { top: '45%' },
 style: { backgroundColor: null }
},
spaceRight:20
},
credits: {enabled: false},
<?php
echo "
subtitle: { text: '$lgDETAILSUBTITLE' },
xAxis: {
type: 'datetime',
minRange: 300000,
dateTimeLabelFormats: {minute: '%H:%M'}
},
yAxis: [";
$yaxislist = array();
for ($i = 1; $i <= $NUMMETER; $i++) {
    if ($check[$i] == 'on') {
        if (!in_array(${'UNIT' . $i}, $yaxislist)) {
            array_push($yaxislist, ${'UNIT' . $i});
        }
    }
}
if ($sscnt > 0) {
    array_push($yaxislist, '%');
}
if ($efcnt > 0 && !in_array('Wh', $yaxislist)) {
    array_push($yaxislist, 'Wh');
}
$conta = count($yaxislist);
$conta--;
for ($i = 0; $i <= $conta; $i++) {
    echo "{
  labels: { formatter: function() { return this.value +'$yaxislist[$i]';}},
  title: { text: '$yaxislist[$i]'},
  gridLineColor: '#BDBDBD'
  }";
    if ($i != $conta) {
        echo ',';
    }
}
echo "],
tooltip: {
formatter: function() {
";
for ($i = 1; $i <= $NUMMETER; $i++) {
    settype(${'PRECI' . $i}, 'integer');
    if ($i == 1) {
        echo "if";
    } else {
        echo " else if";
    }
    echo "(this.series.name=='${'METNAME'.$i}') {
return '<b>' + Highcharts.numberFormat(this.y,'${'PRECI'.$i}') + ' ${'UNIT'.$i} </b>'";
    if (${'TYPE' . $i} == 'Elect') {
        echo " + '~' + Highcharts.numberFormat(this.y*12,'0') + 'W $lgAVG'";
    }
    echo "+ '<br>' + Highcharts.dateFormat('%H:%M', this.x)
}";
}
for ($i = 0; $i < $sscnt; $i++) {
    echo " else if (this.series.name=='$lgSELFS$selfsuff[$i]') {
return '<b>' + Highcharts.dateFormat('%H:%M', this.x) + ': ' + Highcharts.numberFormat(this.y,'1') + '%</b>'
}";
}
for ($i = 0; $i < $efcnt; $i++) {
    echo " else if (this.series.name=='$lgENERGYF$energf[$i]') {
return '<b>' + Highcharts.dateFormat('%H:%M', this.x) + ': ' + Highcharts.numberFormat(this.y,'0') + 'Wh</b>'
}";
}
echo "else {return '<b>' + Highcharts.numberFormat(this.y,'1') + '</b><br/>' + Highcharts.dateFormat('%H:%M', this.x)
}
}
},
legend: {
layout: 'horizontal',
align: 'center',
floating: false,
backgroundColor: '#FFFFFF'
},
plotOptions: {
 areaspline: {
 fillOpacity: 0.3
 }
},
exporting: {
filename: 'meterN-chart',
width: 1200
},
series: []
};
"; // End of echo

// transmit the value to proceed them via _GET
echo "
var date1 = '$csvdate1'
";
for ($i = 1; $i <= $NUMMETER; $i++) {
    echo "var check$i = '$check[$i]'
";
}

for ($i = 0; $i < $cnt; $i++) {
    echo "var ss$i = '$ss[$i]'
	 var ef$i = '$ef[$i]'
	 
";
}

echo "
Mychart= Highcharts.chart('container',options);
Mychart.showLoading();
  $.getJSON('programs/programdetailed.php', {date1: date1";
for ($i = 0; $i < $cnt; $i++) {
    echo ",ss$i:ss$i,ef$i:ef$i";
}
for ($i = 1; $i <= $NUMMETER; $i++) {
    echo ",check$i:check$i";
}
echo "}, function(JSONResponse) 
{
options.series = JSONResponse.data;
Mychart= Highcharts.chart('container',options);
Mychart.setTitle({text: JSONResponse.title});
Mychart.hideLoading();
});
 
});
</script>

<div align='center'>
<div id='container' style='width: 100%; height: 400px'></div>
<br>
<table border=1 cellspacing=0 cellpadding=0 width='30%' align='center'>
<tr><td> 
<form method='POST' action='detailed.php' name='chooseDateForm' id='chooseDateForm' action='#'>
$lgCHOOSEDATE :&nbsp;
<button id='oneDayBack'> < </button>
<input name='date1' id='datepickid' value='$date1' size=8 maxlength=10>
<button id='oneDayFwd'> > </button>";

$housecons = false;
$houseprod = false;
for ($i = 1; $i <= $NUMMETER; $i++) {
    include("config/config_met$i.php");
    if (${'TYPE' . $i} == 'Elect') {
        if (${'PROD' . $i} == 2) {
            $housecons = true;
        } elseif (${'PROD' . $i} == 1) {
            $houseprod = true;
        }
        if (!isset($grid[${'PHASE' . $i}]) && ${'PROD' . $i} != 0) {
            $grid[${'PHASE' . $i}] = ${'PHASE' . $i}; // grid value on ph n
        }
    }
	echo "<tr><td><input type='checkbox' name='${'METNAME'.$i}' value='on'";
    if ($check[$i] == 'on') {
        echo ' checked';
    }
    echo ">${'METNAME'.$i}</td></tr>";
}
if ($housecons == true && $houseprod == true) {
    echo "<tr><td>&nbsp;</td></tr>";
    for ($i = 0; $i < $cnt; $i++) {
        echo "<tr><td><input type='checkbox' name='ss$i' value='$grid[$i]'";
        if ($ss[$i] != 0) {
            echo ' checked';
        }
        echo ">$lgSELFSUFF$grid[$i] <img src='images/info10.png' width='10' height='10' border='0' title='$lg5MINFO'> </td></tr>";
        echo "<tr><td><input type='checkbox' name='ef$i' value='$grid[$i]'";
        if ($ef[$i] != 0) {
            echo ' checked';
        }
        echo ">$lgENERGYFL$grid[$i] <img src='images/info10.png' width='10' height='10' border='0' title='$lg5MINFO'> </td></tr>";
    }
}
echo "<tr><td align=center><br>&nbsp;<input type='submit' value='   $lgOK   '></td></tr>
</table>
</form>
<br>";
include("styles/" . $user_style . "/footer.php");
?>

ambramia
Posts: 25
Joined: Thu Apr 21, 2016 11:33 am

Re: meterN 0.8

Post by ambramia » Thu May 12, 2016 3:18 pm

when i clicking for detail, after change in detailed.php file, only a blank page :shock:
I returned whith working detailed.php file, there is something wrong?

can I ask you change if possible :oops: ?
For my meter "bolletta" and "risparmio" there are six decimals, in readings is not very nice to see, the number is too long, you can do so to see only two decimal places and going on with the mouse see all six decimal.
The same also in the index page. I hope you understand me :D

jeanmarc
Posts: 1917
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 0.8

Post by jeanmarc » Fri May 13, 2016 10:59 am

This one should be ok and allow meter with space and dot :

Code: Select all

<?php
include('styles/globalheader.php');
include('config/config_main.php');

$dir    = 'data/csv/';
$output = glob($dir . '*.csv');
sort($output);
$contalogs = count($output);

$ollog  = $output[0];
$lstlog = $output[$contalogs - 1];

$startdate = (substr($ollog, -12, 4)) . ',' . (substr($ollog, -8, 2)) . '-1,' . (substr($ollog, -6, 2));
$stopdate  = (substr($lstlog, -12, 4)) . ',' . (substr($lstlog, -8, 2)) . '-1,' . (substr($lstlog, -6, 2));
echo "
<script>
  $(function() {
	$('#datepickid' ).datepicker({ dateFormat: 'dd/mm/yy' ,minDate: new Date($startdate), maxDate: new Date($stopdate)});
	$('#oneDayBack').click(function() {
		var new_dateb = $('#datepickid').datepicker('getDate');
		new_dateb.setDate(new_dateb.getDate() - 1);
		$('#datepickid').datepicker('setDate', new_dateb);
	});
	$('#oneDayFwd').click(function() {
		var new_datef = $('#datepickid').datepicker('getDate');
		new_datef.setDate(new_datef.getDate() + 1);
		$('#datepickid').datepicker('setDate', new_datef);
	});
    });
</script>";

$regexp = "/[0-9]{1,2}+\/[0-9]{1,2}+\/[0-9]{4}/";
if (!empty($_POST['date1']) && preg_match($regexp, $_POST['date1'])) {
    $date1 = $_POST['date1'];
} else {
    $date1 = (substr($lstlog, -6, 2)) . '/' . (substr($lstlog, -8, 2)) . '/' . (substr($lstlog, -12, 4));
}
if (!empty($_GET['date2']) && is_numeric($_GET['date2'])) {
    $date2 = $_GET['date2'];
    $ts    = strftime("%s", floor($date2 / 1000));
    $date1 = date('d/m/Y', $ts);
}

$grid  = array();
$selec = false;
$unallowedchar  = array('.', ' '); // passing form

for ($i = 1; $i <= $NUMMETER; $i++) {
    include("config/config_met$i.php");
	$formmetn[$i] = str_replace($unallowedchar, '', ${'METNAME'.$i});
	if (isset($_POST["$formmetn[$i]"]))  {
        $check[$i] = 'on';
        $selec     = true;
	} elseif (isset($_GET["$formmetn[$i]"]))  {	
		$check[$i] = 'on';
        $selec     = true;
    } else {
        $check[$i] = 'off';
    }
    if (${'TYPE' . $i} == 'Elect' && ${'PROD' . $i} != 0 && !isset($grid[${'PHASE' . $i}])) {
        $grid[${'PHASE' . $i}] = ${'PHASE' . $i};
    }
}

sort($grid);
$cnt   = count($grid);
$sscnt = 0;
$efcnt = 0;

for ($i = 0; $i < $cnt; $i++) {
    if (!empty($_POST["ss$i"])) {
        $ss[$i] = $_POST["ss$i"];
        $selec  = true;
        if ($ss[$i] != 0) {
            $selfsuff[$sscnt] = $ss[$i];
            $sscnt++;
        }
    } else {
        $ss[$i] = 0;
    }
    if (!empty($_POST["ef$i"])) {
        $ef[$i] = $_POST["ef$i"];
        $selec  = true;
        if ($ef[$i] != 0) {
            $energf[$efcnt] = $ef[$i];
            $efcnt++;
        }
    } else {
        $ef[$i] = 0;
    }
}

if (!$selec) { //Nothing selected
    $check[1] = 'on';
}

$titledate = substr($date1, 0, 10);
$csvdate1  = (substr($date1, 6, 4)) . (substr($date1, 3, 2)) . (substr($date1, 0, 2)) . ".csv";
?>
<script type="text/javascript">

$(document).ready(function()
{
Highcharts.setOptions({
global: {
useUTC: false
},
lang: {
decimalPoint: '<?php
echo $DPOINT;
?>',
thousandsSep: '<?php
echo "$THSEP',
drillUpText: '$lgDRILLUP',
loading: '$lgLOAD',
printChart: '$lgPRINT',
resetZoom: '$lgRESETZ'
";
?>
}
});

var Mychart, options = {
chart: {
backgroundColor: null,
zoomType: 'xy',
resetZoomButton: {
                position: {
                    align: 'right',
                    verticalAlign: 'top'
                }
},
loading: {
 labelStyle: { top: '45%' },
 style: { backgroundColor: null }
},
spaceRight:20
},
credits: {enabled: false},
<?php
echo "
subtitle: { text: '$lgDETAILSUBTITLE' },
xAxis: {
type: 'datetime',
minRange: 300000,
dateTimeLabelFormats: {minute: '%H:%M'}
},
yAxis: [";
$yaxislist = array();
for ($i = 1; $i <= $NUMMETER; $i++) {
    if ($check[$i] == 'on') {
        if (!in_array(${'UNIT' . $i}, $yaxislist)) {
            array_push($yaxislist, ${'UNIT' . $i});
        }
    }
}
if ($sscnt > 0) {
    array_push($yaxislist, '%');
}
if ($efcnt > 0 && !in_array('Wh', $yaxislist)) {
    array_push($yaxislist, 'Wh');
}
$conta = count($yaxislist);
$conta--;
for ($i = 0; $i <= $conta; $i++) {
    echo "{
  labels: { formatter: function() { return this.value +'$yaxislist[$i]';}},
  title: { text: '$yaxislist[$i]'},
  gridLineColor: '#BDBDBD'
  }";
    if ($i != $conta) {
        echo ',';
    }
}
echo "],
tooltip: {
formatter: function() {
";
for ($i = 1; $i <= $NUMMETER; $i++) {
    settype(${'PRECI' . $i}, 'integer');
    if ($i == 1) {
        echo "if";
    } else {
        echo " else if";
    }
    echo "(this.series.name=='${'METNAME'.$i}') {
return '<b>' + Highcharts.numberFormat(this.y,'${'PRECI'.$i}') + ' ${'UNIT'.$i} </b>'";
    if (${'TYPE' . $i} == 'Elect') {
        echo " + '~' + Highcharts.numberFormat(this.y*12,'0') + 'W $lgAVG'";
    }
    echo "+ '<br>' + Highcharts.dateFormat('%H:%M', this.x)
}";
}
for ($i = 0; $i < $sscnt; $i++) {
    echo " else if (this.series.name=='$lgSELFS$selfsuff[$i]') {
return '<b>' + Highcharts.dateFormat('%H:%M', this.x) + ': ' + Highcharts.numberFormat(this.y,'1') + '%</b>'
}";
}
for ($i = 0; $i < $efcnt; $i++) {
    echo " else if (this.series.name=='$lgENERGYF$energf[$i]') {
return '<b>' + Highcharts.dateFormat('%H:%M', this.x) + ': ' + Highcharts.numberFormat(this.y,'0') + 'Wh</b>'
}";
}
echo "else {return '<b>' + Highcharts.numberFormat(this.y,'1') + '</b><br/>' + Highcharts.dateFormat('%H:%M', this.x)
}
}
},
legend: {
layout: 'horizontal',
align: 'center',
floating: false,
backgroundColor: '#FFFFFF'
},
plotOptions: {
 areaspline: {
 fillOpacity: 0.3
 }
},
exporting: {
filename: 'meterN-chart',
width: 1200
},
series: []
};
"; // End of echo

// transmit the value to proceed them via _GET
echo "
var date1 = '$csvdate1'
";
for ($i = 1; $i <= $NUMMETER; $i++) {
    echo "var check$i = '$check[$i]'
";
}

for ($i = 0; $i < $cnt; $i++) {
    echo "var ss$i = '$ss[$i]'
	 var ef$i = '$ef[$i]'
	 
";
}

echo "
Mychart= Highcharts.chart('container',options);
Mychart.showLoading();
  $.getJSON('programs/programdetailed.php', {date1: date1";
for ($i = 0; $i < $cnt; $i++) {
    echo ",ss$i:ss$i,ef$i:ef$i";
}
for ($i = 1; $i <= $NUMMETER; $i++) {
    echo ",check$i:check$i";
}
echo "}, function(JSONResponse) 
{
options.series = JSONResponse.data;
Mychart= Highcharts.chart('container',options);
Mychart.setTitle({text: JSONResponse.title});
Mychart.hideLoading();
});
 
});
</script>

<div align='center'>
<div id='container' style='width: 100%; height: 400px'></div>
<br>
<table border=1 cellspacing=0 cellpadding=0 width='30%' align='center'>
<tr><td> 
<form method='POST' action='detailed.php' name='chooseDateForm' id='chooseDateForm' action='#'>
$lgCHOOSEDATE :&nbsp;
<button id='oneDayBack'> < </button>
<input name='date1' id='datepickid' value='$date1' size=8 maxlength=10>
<button id='oneDayFwd'> > </button>";

$housecons = false;
$houseprod = false;
for ($i = 1; $i <= $NUMMETER; $i++) {
    include("config/config_met$i.php");
    if (${'TYPE' . $i} == 'Elect') {
        if (${'PROD' . $i} == 2) {
            $housecons = true;
        } elseif (${'PROD' . $i} == 1) {
            $houseprod = true;
        }
        if (!isset($grid[${'PHASE' . $i}]) && ${'PROD' . $i} != 0) {
            $grid[${'PHASE' . $i}] = ${'PHASE' . $i}; // grid value on ph n
        }
    }
	echo "<tr><td><input type='checkbox' name='${'METNAME'.$i}' value='on'";
    if ($check[$i] == 'on') {
        echo ' checked';
    }
    echo ">${'METNAME'.$i}</td></tr>";
}
if ($housecons == true && $houseprod == true) {
    echo "<tr><td>&nbsp;</td></tr>";
    for ($i = 0; $i < $cnt; $i++) {
        echo "<tr><td><input type='checkbox' name='ss$i' value='$grid[$i]'";
        if ($ss[$i] != 0) {
            echo ' checked';
        }
        echo ">$lgSELFSUFF$grid[$i] <img src='images/info10.png' width='10' height='10' border='0' title='$lg5MINFO'> </td></tr>";
        echo "<tr><td><input type='checkbox' name='ef$i' value='$grid[$i]'";
        if ($ef[$i] != 0) {
            echo ' checked';
        }
        echo ">$lgENERGYFL$grid[$i] <img src='images/info10.png' width='10' height='10' border='0' title='$lg5MINFO'> </td></tr>";
    }
}
echo "<tr><td align=center><br>&nbsp;<input type='submit' value='   $lgOK   '></td></tr>
</table>
</form>
<br>";
include("styles/" . $user_style . "/footer.php");
?>

ambramia
Posts: 25
Joined: Thu Apr 21, 2016 11:33 am

Re: meterN 0.8

Post by ambramia » Fri May 13, 2016 11:20 am

Hi Jeanmarc, i put code posted for readings.php and detailed.php but the problem is the same.
Now metern is working with your last code posted, if you want can see......
By chance something should be changed in /var/www/metern/programs/programreadings.php? :oops: :oops: :oops:

edit:
I returned to the working version. the change breaks the graph in metern sorry

jeanmarc
Posts: 1917
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 0.8

Post by jeanmarc » Fri May 13, 2016 12:54 pm

@ambramia:
For readings, for your decimal problem you may change the meter precision.
@*: There is issues with meters names that contains spaces and dot. I am working on it..

jeanmarc
Posts: 1917
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 0.8

Post by jeanmarc » Fri May 13, 2016 2:13 pm

Ok, now it should be ok for 'detailled'. You can use spaces and dots.
I have to change last 15 days, i'll check if there is issues elsewhere.

Code: Select all

<?php
include('styles/globalheader.php');
include('config/config_main.php');

$dir    = 'data/csv/';
$output = glob($dir . '*.csv');
sort($output);
$contalogs = count($output);

$ollog  = $output[0];
$lstlog = $output[$contalogs - 1];

$startdate = (substr($ollog, -12, 4)) . ',' . (substr($ollog, -8, 2)) . '-1,' . (substr($ollog, -6, 2));
$stopdate  = (substr($lstlog, -12, 4)) . ',' . (substr($lstlog, -8, 2)) . '-1,' . (substr($lstlog, -6, 2));
echo "
<script>
  $(function() {
	$('#datepickid' ).datepicker({ dateFormat: 'dd/mm/yy' ,minDate: new Date($startdate), maxDate: new Date($stopdate)});
	$('#oneDayBack').click(function() {
		var new_dateb = $('#datepickid').datepicker('getDate');
		new_dateb.setDate(new_dateb.getDate() - 1);
		$('#datepickid').datepicker('setDate', new_dateb);
	});
	$('#oneDayFwd').click(function() {
		var new_datef = $('#datepickid').datepicker('getDate');
		new_datef.setDate(new_datef.getDate() + 1);
		$('#datepickid').datepicker('setDate', new_datef);
	});
    });
</script>";

$regexp = "/[0-9]{1,2}+\/[0-9]{1,2}+\/[0-9]{4}/";
if (!empty($_POST['date1']) && preg_match($regexp, $_POST['date1'])) {
    $date1 = $_POST['date1'];
} else {
    $date1 = (substr($lstlog, -6, 2)) . '/' . (substr($lstlog, -8, 2)) . '/' . (substr($lstlog, -12, 4));
}
if (!empty($_GET['date2']) && is_numeric($_GET['date2'])) {
    $date2 = $_GET['date2'];
    $ts    = strftime("%s", floor($date2 / 1000));
    $date1 = date('d/m/Y', $ts);
}

$grid  = array();
$selec = false;
$unallowedchar  = array('.', ' '); 

for ($i = 1; $i <= $NUMMETER; $i++) {
    include("config/config_met$i.php");
	$formmetn[$i] = str_replace($unallowedchar, '_', ${'METNAME'.$i}); // passing form
	
	if (isset($_POST["$formmetn[$i]"]))  {
        $check[$i] = 'on';
        $selec     = true;
	} elseif (isset($_GET["$formmetn[$i]"]))  {	
		$check[$i] = 'on';
        $selec     = true;
    } else {
        $check[$i] = 'off';
    }
    if (${'TYPE' . $i} == 'Elect' && ${'PROD' . $i} != 0 && !isset($grid[${'PHASE' . $i}])) {
        $grid[${'PHASE' . $i}] = ${'PHASE' . $i};
    }
}

sort($grid);
$cnt   = count($grid);
$sscnt = 0;
$efcnt = 0;

for ($i = 0; $i < $cnt; $i++) {
    if (!empty($_POST["ss$i"])) {
        $ss[$i] = $_POST["ss$i"];
        $selec  = true;
        if ($ss[$i] != 0) {
            $selfsuff[$sscnt] = $ss[$i];
            $sscnt++;
        }
    } else {
        $ss[$i] = 0;
    }
    if (!empty($_POST["ef$i"])) {
        $ef[$i] = $_POST["ef$i"];
        $selec  = true;
        if ($ef[$i] != 0) {
            $energf[$efcnt] = $ef[$i];
            $efcnt++;
        }
    } else {
        $ef[$i] = 0;
    }
}

if (!$selec) { //Nothing selected
    $check[1] = 'on';
}

$titledate = substr($date1, 0, 10);
$csvdate1  = (substr($date1, 6, 4)) . (substr($date1, 3, 2)) . (substr($date1, 0, 2)) . ".csv";
?>
<script type="text/javascript">

$(document).ready(function()
{
Highcharts.setOptions({
global: {
useUTC: false
},
lang: {
decimalPoint: '<?php
echo $DPOINT;
?>',
thousandsSep: '<?php
echo "$THSEP',
drillUpText: '$lgDRILLUP',
loading: '$lgLOAD',
printChart: '$lgPRINT',
resetZoom: '$lgRESETZ'
";
?>
}
});

var Mychart, options = {
chart: {
backgroundColor: null,
zoomType: 'xy',
resetZoomButton: {
                position: {
                    align: 'right',
                    verticalAlign: 'top'
                }
},
loading: {
 labelStyle: { top: '45%' },
 style: { backgroundColor: null }
},
spaceRight:20
},
credits: {enabled: false},
<?php
echo "
subtitle: { text: '$lgDETAILSUBTITLE' },
xAxis: {
type: 'datetime',
minRange: 300000,
dateTimeLabelFormats: {minute: '%H:%M'}
},
yAxis: [";
$yaxislist = array();
for ($i = 1; $i <= $NUMMETER; $i++) {
    if ($check[$i] == 'on') {
        if (!in_array(${'UNIT' . $i}, $yaxislist)) {
            array_push($yaxislist, ${'UNIT' . $i});
        }
    }
}
if ($sscnt > 0) {
    array_push($yaxislist, '%');
}
if ($efcnt > 0 && !in_array('Wh', $yaxislist)) {
    array_push($yaxislist, 'Wh');
}
$conta = count($yaxislist);
$conta--;
for ($i = 0; $i <= $conta; $i++) {
    echo "{
  labels: { formatter: function() { return this.value +'$yaxislist[$i]';}},
  title: { text: '$yaxislist[$i]'},
  gridLineColor: '#BDBDBD'
  }";
    if ($i != $conta) {
        echo ',';
    }
}
echo "],
tooltip: {
formatter: function() {
";
for ($i = 1; $i <= $NUMMETER; $i++) {
    settype(${'PRECI' . $i}, 'integer');
    if ($i == 1) {
        echo "if";
    } else {
        echo " else if";
    }
    echo "(this.series.name=='${'METNAME'.$i}') {
return '<b>' + Highcharts.numberFormat(this.y,'${'PRECI'.$i}') + ' ${'UNIT'.$i} </b>'";
    if (${'TYPE' . $i} == 'Elect') {
        echo " + '~' + Highcharts.numberFormat(this.y*12,'0') + 'W $lgAVG'";
    }
    echo "+ '<br>' + Highcharts.dateFormat('%H:%M', this.x)
}";
}
for ($i = 0; $i < $sscnt; $i++) {
    echo " else if (this.series.name=='$lgSELFS$selfsuff[$i]') {
return '<b>' + Highcharts.dateFormat('%H:%M', this.x) + ': ' + Highcharts.numberFormat(this.y,'1') + '%</b>'
}";
}
for ($i = 0; $i < $efcnt; $i++) {
    echo " else if (this.series.name=='$lgENERGYF$energf[$i]') {
return '<b>' + Highcharts.dateFormat('%H:%M', this.x) + ': ' + Highcharts.numberFormat(this.y,'0') + 'Wh</b>'
}";
}
echo "else {return '<b>' + Highcharts.numberFormat(this.y,'1') + '</b><br/>' + Highcharts.dateFormat('%H:%M', this.x)
}
}
},
legend: {
layout: 'horizontal',
align: 'center',
floating: false,
backgroundColor: '#FFFFFF'
},
plotOptions: {
 areaspline: {
 fillOpacity: 0.3
 }
},
exporting: {
filename: 'meterN-chart',
width: 1200
},
series: []
};
"; // End of echo

// transmit the value to proceed them via _GET
echo "
var date1 = '$csvdate1'
";
for ($i = 1; $i <= $NUMMETER; $i++) {
    echo "var check$i = '$check[$i]'
";
}

for ($i = 0; $i < $cnt; $i++) {
    echo "var ss$i = '$ss[$i]'
	 var ef$i = '$ef[$i]'
	 
";
}

echo "
Mychart= Highcharts.chart('container',options);
Mychart.showLoading();
  $.getJSON('programs/programdetailed.php', {date1: date1";
for ($i = 0; $i < $cnt; $i++) {
    echo ",ss$i:ss$i,ef$i:ef$i";
}
for ($i = 1; $i <= $NUMMETER; $i++) {
    echo ",check$i:check$i";
}
echo "}, function(JSONResponse) 
{
options.series = JSONResponse.data;
Mychart= Highcharts.chart('container',options);
Mychart.setTitle({text: JSONResponse.title});
Mychart.hideLoading();
});
 
});
</script>

<div align='center'>
<div id='container' style='width: 100%; height: 400px'></div>
<br>
<table border=1 cellspacing=0 cellpadding=0 width='30%' align='center'>
<tr><td> 
<form method='POST' action='detailed.php' name='chooseDateForm' id='chooseDateForm' action='#'>
$lgCHOOSEDATE :&nbsp;
<button id='oneDayBack'> < </button>
<input name='date1' id='datepickid' value='$date1' size=8 maxlength=10>
<button id='oneDayFwd'> > </button>";

$housecons = false;
$houseprod = false;
for ($i = 1; $i <= $NUMMETER; $i++) {
    include("config/config_met$i.php");
    if (${'TYPE' . $i} == 'Elect') {
        if (${'PROD' . $i} == 2) {
            $housecons = true;
        } elseif (${'PROD' . $i} == 1) {
            $houseprod = true;
        }
        if (!isset($grid[${'PHASE' . $i}]) && ${'PROD' . $i} != 0) {
            $grid[${'PHASE' . $i}] = ${'PHASE' . $i}; // grid value on ph n
        }
    }
	echo "<tr><td><input type='checkbox' name='$formmetn[$i]' value='on'";
    if ($check[$i] == 'on') {
        echo ' checked';
    }
    echo ">${'METNAME'.$i}</td></tr>";
}
if ($housecons == true && $houseprod == true) {
    echo "<tr><td>&nbsp;</td></tr>";
    for ($i = 0; $i < $cnt; $i++) {
        echo "<tr><td><input type='checkbox' name='ss$i' value='$grid[$i]'";
        if ($ss[$i] != 0) {
            echo ' checked';
        }
        echo ">$lgSELFSUFF$grid[$i] <img src='images/info10.png' width='10' height='10' border='0' title='$lg5MINFO'> </td></tr>";
        echo "<tr><td><input type='checkbox' name='ef$i' value='$grid[$i]'";
        if ($ef[$i] != 0) {
            echo ' checked';
        }
        echo ">$lgENERGYFL$grid[$i] <img src='images/info10.png' width='10' height='10' border='0' title='$lg5MINFO'> </td></tr>";
    }
}
echo "<tr><td align=center><br>&nbsp;<input type='submit' value='   $lgOK   '></td></tr>
</table>
</form>
<br>";
include("styles/" . $user_style . "/footer.php");
?>

ambramia
Posts: 25
Joined: Thu Apr 21, 2016 11:33 am

Re: meterN 0.8

Post by ambramia » Fri May 13, 2016 8:01 pm

it's OK now in detailed, it seems to run even in the last 15 days with this change :lol: you can see in my metern the link is still right........
But going to: readings->year(2016_in my case)meter_with_space_in_the_name->month-> and click in one day there is still the problem....... :oops:

jeanmarc
Posts: 1917
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 0.8

Post by jeanmarc » Sat May 14, 2016 6:46 am

sorry, readings need to be change as well :

Code: Select all

<?php
include('styles/globalheader.php');
include('config/config_main.php');

$output = array();
$dir    = 'data/meters/';
$output = glob($dir . '*.csv');
$cnt    = count($output);

if ($cnt > 1) {
    if (!empty($_POST['meter'])) {
        $meter = $_POST['meter'];
    } else {
        $meter = 1;
    }
    
    echo "<table width='95%' border=0 align=center cellpadding=8>
<tr><td>
<form method='POST' action='readings.php'>
$lgCHOOSEMET: <select name='meter' onchange='this.form.submit()'>";
    for ($i = 1; $i <= $NUMMETER; $i++) {
        include("config/config_met$i.php");
        if ($meter == $i) {
            echo "<option value='$i' SELECTED>";
        } else {
            echo "<option value='$i'>";
        }
        echo "${'METNAME'.$i}</option>";
    }
    echo "</select> 
</form>
";
?>
</td></tr>
</table>

<script type="text/javascript">
$(document).ready(function() {
Highcharts.setOptions({
global: {useUTC: false},
lang: {
decimalPoint: '<?php
    echo $DPOINT;
?>',
thousandsSep: '<?php
    echo $THSEP;
?>',
months: ['<?php
    for ($i = 1; $i < 12; $i++) {
        echo "$lgMONTH[$i]','";
    }
    echo $lgMONTH[12];
?>'],
shortMonths: ['<?php
    for ($i = 1; $i < 12; $i++) {
        echo "$lgSMONTH[$i]','";
    }
    echo $lgSMONTH[12];
?>'],
weekdays: ['<?php
    for ($i = 1; $i < 7; $i++) {
        echo "$lgWEEKD[$i]','";
    }
    echo "$lgWEEKD[7]'],
drillUpText: '$lgDRILLUP',
loading: '$lgLOAD',
printChart: '$lgPRINT',
resetZoom: '$lgRESETZ'
";
?>
}
});

var defaultTitle = "<?php
    echo "$lgCONSUTITLE: ${'METNAME'.$meter}";
?>", prevPointTitle = null;

var Mychart, options = {
        chart: {
                type: 'column',
                backgroundColor: null,
				events: {
					drilldown: function (e) {
						this.setTitle({
							text: e.point.title
						});
						if (!prevPointTitle) {
							prevPointTitle = e.point.title;
						}
					},
					drillup: function (e) {
						if ( !! this.series[0].drilldownLevel) {
							this.setTitle({
								text: defaultTitle
							});
							prevPointTitle = null;
						} else {
							this.setTitle({
								text: prevPointTitle
							});
						}
					}
				},
            },
			title: {
				text: defaultTitle
			},
            subtitle: {text: '<?php
    echo "$lgCONSUSUBTITLE";
?>'},
            xAxis: {
            type: 'datetime'
            },
            yAxis: {
    		min: 0,
    		minPadding: 0,
			title: {text: '<?php
    echo "${'UNIT'.$meter}";
?>'}
            },
		plotOptions: {
			series: {
				borderWidth: 1,
				dataLabels: {
					enabled: true,
					formatter:function() 
					{
						return Highcharts.numberFormat(this.y,<?php
    if (${'TYPE' . $meter} == 'Elect') {
        echo "0) + ' kWh';";
    } else {
        echo "${'PRECI'.$meter}) + ' ${'UNIT'.$meter}';";
    }
?>

					}
				},
				point: {
					events: {
						click: function(event) {
							var point = this;
								if (point.y) {
									if (confirm('<?php
    echo $lgSHOWDETAIL;
?>')) {
									window.location = 'detailed.php?<?php echo ${'METNAME'.$meter};?>=on&date2='+this.x;
									}
								}
						}
					}
				}
			},
			column: {
			  color: "<?php
    echo "#${'COLOR'.$meter}";
?>",
			  cursor: 'pointer'
			}
		},
        tooltip: {
			formatter: function() {
				if (Mychart.series[0].options._levelNumber==1) {
				s= '<b>' + Highcharts.dateFormat('%B %Y', this.x);
				} else if (Mychart.series[0].options._levelNumber==2) {
				s= '<b>' + Highcharts.dateFormat('%a. %d %B %Y', this.x);	
				} else {
				s= '<b>' + Highcharts.dateFormat('%Y', this.x);
				}
			s+= '</b><br><b>'+ Highcharts.numberFormat(this.y,<?php
    if (${'TYPE' . $meter} == 'Elect') {
        echo "2) + ' kWh</b>';";
    } else {
        echo "${'PRECI'.$meter}) + ' ${'UNIT'.$meter}</b>';";
    }
    if (${'PRICE' . $meter} > 0) {
        echo "
		    s += ' (' + Highcharts.numberFormat((this.y*${'PRICE'.$meter}),1) + '$CURS)';
		";
    }
?>
	return s;
			
			}
		 },		
  exporting: {
  filename: 'meterN-chart',
  width: 1200
  },
  credits: {
  enabled: false
  },
    series: [],
    drilldown: []
 };
<?php
    $destination = "programs/programreadings.php";
    echo "
var meter = '$meter';
Mychart= Highcharts.chart('container',options);

Mychart.showLoading();
$.getJSON('$destination', { meter: meter }, function(JSONResponse) {
  options.series = JSONResponse.series;
  options.drilldown = JSONResponse.drilldown;
  Mychart= Highcharts.chart('container',options);
  Mychart.hideLoading();
});
});";
    
    echo "
</script>";
} else {
    echo '<br>No data';
}
echo "
<table width='100%' border=0 align=center cellpadding=0>
<tr><td><div id='container' style='width: 95%; height: 450px'></div></td></tr>
</table>
";

include("styles/" . $user_style . "/footer.php");
?>

ambramia
Posts: 25
Joined: Thu Apr 21, 2016 11:33 am

Re: meterN 0.8

Post by ambramia » Sat May 14, 2016 4:34 pm

Many thanks Jeanmarc, now it's all ok.
About six decimal in "Bolletta" and "Risparmio" if i change to two decimals all data and previous graphics wrong.
You can do something like this? :roll:

Image

this change had been made by a "Energeticambiente" forum user but does not work now with new versions of metern.

Locked

Who is online

Users browsing this forum: No registered users and 2 guests