From: Nathael Pajani Date: Mon, 5 Sep 2016 10:06:51 +0000 (+0200) Subject: Add perl scripts to create graphs from logfiles Ignore logfiles. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=8d564dbddcd91212537367941b0f386dfb23e87c;p=soft%2Flpc82x%2Fexanh Add perl scripts to create graphs from logfiles Ignore logfiles. --- diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..3c92fb5 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,2 @@ +*.log +logs* diff --git a/test/gnuplot.cmds b/test/gnuplot.cmds new file mode 100644 index 0000000..55f8357 --- /dev/null +++ b/test/gnuplot.cmds @@ -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 index 0000000..2799b7b --- /dev/null +++ b/test/graph.pl @@ -0,0 +1,108 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; + +# Author : Nathael Pajani +# Copyright 2016 Nathael Pajani +# +# 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 . + + +# 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 () { + 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 index 0000000..8829c72 --- /dev/null +++ b/test/translate.pl @@ -0,0 +1,63 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; + +# Author : Nathael Pajani +# Copyright 2016 Nathael Pajani +# +# 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 . + + +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 () { + 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); +