Add perl scripts to create graphs from logfiles Ignore logfiles.
authorNathael Pajani <nathael.pajani@ed3l.fr>
Mon, 5 Sep 2016 10:06:51 +0000 (12:06 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Sat, 11 Feb 2023 04:09:54 +0000 (05:09 +0100)
test/.gitignore [new file with mode: 0644]
test/gnuplot.cmds [new file with mode: 0644]
test/graph.pl [new file with mode: 0644]
test/translate.pl [new file with mode: 0755]

diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644 (file)
index 0000000..3c92fb5
--- /dev/null
@@ -0,0 +1,2 @@
+*.log
+logs*
diff --git a/test/gnuplot.cmds b/test/gnuplot.cmds
new file mode 100644 (file)
index 0000000..55f8357
--- /dev/null
@@ -0,0 +1,20 @@
+set terminal png size 1500,600
+set output 'temperature-0.png'
+plot "data_temp.log" using 1:2 title 'Temperature0' with lines
+
+set output 'cap-0.png'
+plot "data_cap.log" using 1:2 title 'Cap0' with lines
+
+set output 'res-0.png'
+plot "data_res.log" using 1:2 title 'Res0' with lines
+
+
+set terminal png size 1500,600
+set output 'temperature-1.png'
+plot "data_temp.log" using 1:2 title 'Temperature1' with lines
+
+set output 'cap-1.png'
+plot "data_cap.log" using 1:2 title 'Cap1' with lines
+
+set output 'res-1.png'
+plot "data_res.log" using 1:2 title 'Res1' with lines
diff --git a/test/graph.pl b/test/graph.pl
new file mode 100644 (file)
index 0000000..2799b7b
--- /dev/null
@@ -0,0 +1,108 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+# Author : Nathael Pajani
+# Copyright 2016 Nathael Pajani <nathael.pajani@techno-innov.fr>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+# How to use this script/programm
+# FIXME : TODO.
+
+use GD::Graph::bars;
+
+
+my $debug = 1; # 0: no debug
+
+my $file = $ARGV[0];
+if (! -e $file) {
+       print "Need file name as first argument\n";
+       exit 1;
+}
+
+my $count = 0;
+my @stime;
+my @stempdata;
+my @scapdata;
+my @sresdata;
+
+open(LOGFILE, "<", $file);
+foreach my $line (<LOGFILE>) {
+       chomp($line); # remove the newline from $line.
+       my $w = "(.+?)";
+       if ($line =~ m/Temp read: $w - raw/) {
+               push(@stime, $count);
+               push(@stempdata, $1);
+               # Increment counter
+               $count++;
+       } elsif ($line =~ m/ADC9: $w, ADC10: $w/) {
+               push(@scapdata, $1);
+               push(@sresdata, $2);
+       }
+}
+
+
+print "Got ".$#stime." values\n";
+
+# Temperature
+my $tempgraph = GD::Graph::bars->new(($#stime*2), 800);
+$tempgraph->set( 
+             x_label => 'time',
+             y_label => 'temp',
+             title   => 'Temp sensor vs time',
+             transparent => 0
+) or warn $tempgraph->error;
+my @tempdata = (\@stime, \@stempdata);
+my $temp_gd = $tempgraph->plot(\@tempdata) or die $tempgraph->error();
+# Save graph
+open(IMG, '>filetemp.png') or die $!;
+binmode IMG;
+print IMG $temp_gd->png;
+close(IMG);
+
+# Capacitance
+my $capgraph = GD::Graph::bars->new(($#stime*2), 800);
+$capgraph->set( 
+             x_label => 'time',
+             y_label => 'cap',
+             title   => 'Temp sensor vs time',
+             transparent => 0
+) or warn $capgraph->error;
+my @capdata = (\@stime, \@scapdata);
+my $cap_gd = $capgraph->plot(\@capdata) or die $capgraph->error();
+# Save graph
+open(IMG, '>filecap.png') or die $!;
+binmode IMG;
+print IMG $cap_gd->png;
+close(IMG);
+
+# Resistivity
+my $resgraph = GD::Graph::bars->new(($#stime*2), 800);
+$resgraph->set( 
+             x_label => 'time',
+             y_label => 'res',
+             title   => 'Temp sensor vs time',
+             transparent => 0
+) or warn $resgraph->error;
+my @resdata = (\@stime, \@sresdata);
+my $res_gd = $resgraph->plot(\@resdata) or die $resgraph->error();
+# Save graph
+open(IMG, '>fileres.png') or die $!;
+binmode IMG;
+print IMG $res_gd->png;
+close(IMG);
+
diff --git a/test/translate.pl b/test/translate.pl
new file mode 100755 (executable)
index 0000000..8829c72
--- /dev/null
@@ -0,0 +1,63 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+# Author : Nathael Pajani
+# Copyright 2016 Nathael Pajani <nathael.pajani@techno-innov.fr>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+my $file = $ARGV[0];
+if (! -e $file) {
+       print "Need file name as first argument\n";
+       exit 1;
+}
+
+my $count = 0;
+my $skip = 4000;
+
+open(LOGFILE, "<", $file);
+open(TEMP, ">", "data_temp.log") or die $!;
+open(CAP, ">", "data_cap.log") or die $!;
+open(RES, ">", "data_res.log") or die $!;
+
+
+foreach my $line (<LOGFILE>) {
+       if ($skip > 0) {
+               $skip--;
+               next;
+       }
+       chomp($line); # remove the newline from $line.
+       my $w = "(.+?)";
+       if ($line =~ m/Temp read: $w - raw/) {
+               my $temp = $1;
+               $temp =~ s/,/./;
+               print TEMP "$count  $temp\n";
+               # Increment counter
+               $count++;
+       } elsif ($line =~ m/ADC9: $w, ADC10: (.+)/) {
+               print CAP "$count  $1\n";
+               print RES "$count  $2\n";
+       }
+}
+
+
+print "Got $count values\n";
+
+close(TEMP);
+close(CAP);
+close(RES);
+