Last active
February 2, 2016 21:29
-
-
Save dpavlin/bab444f7c1d08c00a73d to your computer and use it in GitHub Desktop.
Convert cheali charger logview output into tab seperated values in clipboard for easy copy/paste into spreadsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -xe | |
# .i3/config | |
# for_window[title="^Gnuplot"] floating enable | |
# http://users.softlab.ntua.gr/~ttsiod/gnuplotStreaming.html | |
test -x driveGnuPlots.pl || wget http://users.softlab.ntua.gr/~ttsiod/driveGnuPlots.pl && chmod 755 driveGnuPlots.pl | |
width=600 | |
file=$1 | |
test -z "$file" && file=`ls -t log/*.log | head -1` | |
echo "# using $width points from file $file" | |
#tail -f `ls -t log/*.log | head -1` \ | |
cat $file \ | |
| grep '$1' | cut -d\; -f \ | |
4,5,6,\ | |
10,11,\ | |
12,13,14,15,16,17,\ | |
18,19,20,21,22,23,\ | |
24,25,26,27,28 \ | |
| sed \ | |
-e 's/^/0:/' \ | |
-e 's/;/\n1:/' \ | |
-e 's/;/\n2:/' \ | |
-e 's/;/\n3:/' \ | |
-e 's/;/\n4:/' \ | |
-e 's/;/\n5:/' \ | |
-e 's/;/\n6:/' \ | |
-e 's/;/\n7:/' \ | |
-e 's/;/\n8:/' \ | |
-e 's/;/\n9:/' \ | |
-e 's/;/\n10:/' \ | |
-e 's/;/\n11:/' \ | |
-e 's/;/\n12:/' \ | |
-e 's/;/\n13:/' \ | |
-e 's/;/\n14:/' \ | |
-e 's/;/\n15:/' \ | |
-e 's/;/\n16:/' \ | |
-e 's/;/\n17:/' \ | |
-e 's/;/\n18:/' \ | |
-e 's/;/\n19:/' \ | |
-e 's/;/\n20:/' \ | |
-e 's/;/\n21:/' \ | |
-e 's/;/\n22:/' \ | |
| ./driveGnuPlots.pl 22 \ | |
$width $width $width \ | |
$width $width \ | |
$width $width $width $width $width $width \ | |
$width $width $width $width $width $width \ | |
$width $width $width $width $width \ | |
V mA mAh \ | |
temp Vinput, \ | |
v1 v2 v3 v4 v5 v6, \ | |
r1 r2 r3 r4 r5 r6, \ | |
Rbat Rwire Z AA AB \ | |
2>/dev/null | |
# leave empty line bove this one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
sub usage { | |
print "Usage: $0 <options>\n"; | |
print <<OEF; | |
where options are (in order): | |
NumberOfStreams How many streams to plot (windows) | |
Stream1_WindowSampleSize <Stream2...> This many window samples for each stream | |
Stream1_Title <Stream2_Title> ... Title used for each stream | |
(Optional) Stream1_geometry <Stream2_geometry>... X and Y position in pixels from the top left | |
The last parameters (the optionally provided geometries of the gnuplot windows) | |
are of the form: | |
WIDTHxHEIGHT+XOFF+YOFF | |
OEF | |
exit(1); | |
} | |
sub Arg { | |
if ($#ARGV < $_[0]) { | |
print "Expected parameter missing...\n\n"; | |
usage; | |
} | |
$ARGV[int($_[0])]; | |
} | |
sub main { | |
my $argIdx = 0; | |
my $numberOfStreams = Arg($argIdx++); | |
print "Will display $numberOfStreams Streams (in $numberOfStreams windows)...\n"; | |
my @sampleSizes; | |
for(my $i=0; $i<$numberOfStreams; $i++) { | |
my $samples = Arg($argIdx++); | |
push @sampleSizes, $samples; | |
print "Stream ".($i+1)." will use a window of $samples samples\n"; | |
} | |
my @titles; | |
for(my $i=0; $i<$numberOfStreams; $i++) { | |
my $title = Arg($argIdx++); | |
push @titles, $title; | |
print "Stream ".($i+1)." will use a title of '$title'\n"; | |
} | |
my @geometries; | |
if ($#ARGV >= $argIdx) { | |
for(my $i=0; $i<$numberOfStreams; $i++) { | |
my $geometry = Arg($argIdx++); | |
push @geometries, $geometry; | |
print "Stream ".($i+1)." will use a geometry of '$geometry'\n"; | |
} | |
} | |
my $terminal = ""; | |
open GNUPLOT_TERM, "echo 'show terminal;' | gnuplot 2>&1 |"; | |
while (<GNUPLOT_TERM>) { | |
if (m/terminal type is (\w+)/) { | |
$terminal=$1; | |
} | |
} | |
close GNUPLOT_TERM; | |
# unfortunately, the wxt terminal type does not support positioning. | |
# hardcode it... | |
$terminal = "x11"; | |
my $x_start = 10; | |
my $y_start = 30; | |
my $x_space = 5; # gnuplot needs some space | |
my $y_space = 15; | |
my $w = 320; | |
my $h = 200; | |
my $x = $x_start; | |
my $y = $y_start; | |
my ($x_size, $y_size) = ( 1,1 ); | |
my $vertical = 1; | |
foreach my $title (@titles) { | |
if ( $title =~ m/,$/ ) { | |
$y_size = $vertical if $vertical > $y_size; | |
$vertical = 1; | |
$x_size++; | |
} else { | |
$vertical++; | |
} | |
} | |
print "# grid $x_size x $y_size\n"; | |
my $info = `xwininfo -root`; | |
if ( $info =~ m/-geometry (\d+)x(\d+)/ ) { | |
my ( $x_screen, $y_screen ) = ( $1, $2 ); | |
$w = int( ( $x_screen - ( 2 * $x_start ) - ( ($x_size-1) * $x_space ) ) / $x_size ); | |
$h = int( ( $y_screen - ( 2 * $y_start ) - ( ($y_size-1) * $y_space ) ) / $y_size ); | |
print "# graph size $w x $h\n"; | |
} | |
my @gnuplots; | |
my @buffers; | |
my @xcounters; | |
shift @ARGV; # number of streams | |
for(my $i=0; $i<$numberOfStreams; $i++) { | |
shift @ARGV; # sample size | |
shift @ARGV; # title | |
shift @ARGV; # geometry | |
local *PIPE; | |
my $geometry = "${w}x${h}+${x}+${y}"; | |
$geometries[$i] = $geometry; | |
print "# $i $titles[$i] $geometry\n"; | |
$geometry = " -geometry $geometry"; | |
if ( $titles[$i] =~ s/,$// ) { | |
$x += $w + $x_space; | |
$y = $y_start; | |
} else { | |
$y += $h + $y_space; | |
} | |
open PIPE, "|gnuplot $geometry " || die "Can't initialize gnuplot number ".($i+1)."\n"; | |
select((select(PIPE), $| = 1)[0]); | |
push @gnuplots, *PIPE; | |
print PIPE "set xtics\n"; | |
print PIPE "set ytics\n"; | |
# print PIPE "set style data linespoints\n"; | |
print PIPE "set style data lines\n"; | |
print PIPE "set grid\n"; | |
if ($numberOfStreams == 1) { | |
print PIPE "set terminal $terminal title '".$titles[0]."' noraise\n"; | |
} else { | |
print PIPE "set terminal $terminal noraise\n"; | |
} | |
print PIPE "set autoscale\n"; | |
my @data = []; | |
push @buffers, @data; | |
push @xcounters, 0; | |
} | |
my $streamIdx = 0; | |
select((select(STDOUT), $| = 1)[0]); | |
while(<>) { | |
chomp; | |
my @parts = split /:/; | |
$streamIdx = $parts[0]; | |
my $buf = $buffers[$streamIdx]; | |
my $pip = $gnuplots[$streamIdx]; | |
my $xcounter = $xcounters[$streamIdx]; | |
my $title = $titles[$streamIdx]; | |
# data buffering (up to stream sample size) | |
push @{$buf}, $parts[1]; | |
#print "stream $streamIdx: "; | |
print $pip "set xrange [".($xcounter-$sampleSizes[$streamIdx]).":".($xcounter+1)."]\n"; | |
if ($numberOfStreams == 1) { | |
print $pip "plot \"-\"\n"; | |
} else { | |
print $pip "plot \"-\" title '$title'\n"; | |
} | |
my $cnt = 0; | |
for my $elem (reverse @{$buf}) { | |
#print " ".$elem; | |
print $pip ($xcounter-$cnt)." ".$elem."\n"; | |
$cnt += 1; | |
} | |
#print "\n"; | |
print $pip "e\n"; | |
if ($cnt>=$sampleSizes[$streamIdx]) { | |
shift @{$buf}; | |
} | |
$xcounters[$streamIdx]++; | |
} | |
for(my $i=0; $i<$numberOfStreams; $i++) { | |
my $pip = $gnuplots[$i]; | |
print $pip "exit;\n"; | |
close $pip; | |
} | |
} | |
main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for_window[title="^Gnuplot"] floating enable, border none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -xe | |
# .i3/config | |
# for_window[title="^Gnuplot"] floating enable | |
# http://users.softlab.ntua.gr/~ttsiod/gnuplotStreaming.html | |
test -x driveGnuPlots.pl || wget http://users.softlab.ntua.gr/~ttsiod/driveGnuPlots.pl && chmod 755 driveGnuPlots.pl | |
width=120 | |
file=$1 | |
test -z "$file" && file=`ls -t log/*.log | head -1` | |
echo "# using $width points from file $file" | |
#tail -f `ls -t log/*.log | head -1` \ | |
cat $file \ | |
| grep '$1' | cut -d\; -f \ | |
4,5,6,\ | |
10,11,\ | |
12,13,14,15,16,17,\ | |
18,19,20,21,22,23,\ | |
24,25,26,27,28 \ | |
| sed \ | |
-e 's/^/0:/' \ | |
-e 's/;/\n1:/' \ | |
-e 's/;/\n2:/' \ | |
-e 's/;/\n3:/' \ | |
-e 's/;/\n4:/' \ | |
-e 's/;/\n5:/' \ | |
-e 's/;/\n6:/' \ | |
-e 's/;/\n7:/' \ | |
-e 's/;/\n8:/' \ | |
-e 's/;/\n9:/' \ | |
-e 's/;/\n10:/' \ | |
-e 's/;/\n11:/' \ | |
-e 's/;/\n12:/' \ | |
-e 's/;/\n13:/' \ | |
-e 's/;/\n14:/' \ | |
-e 's/;/\n15:/' \ | |
-e 's/;/\n16:/' \ | |
-e 's/;/\n17:/' \ | |
-e 's/;/\n18:/' \ | |
-e 's/;/\n19:/' \ | |
-e 's/;/\n20:/' \ | |
-e 's/;/\n21:/' \ | |
-e 's/;/\n22:/' \ | |
| \ | |
./driveGnuPlots.pl 22 \ | |
$width $width $width \ | |
$width $width \ | |
$width $width $width $width $width $width \ | |
$width $width $width $width $width $width \ | |
$width $width $width $width $width \ | |
V mA mAh \ | |
temp Vinput \ | |
v1 v2 v3 v4 v5 v6 \ | |
r1 r2 r3 r4 r5 r6 \ | |
Rbat Rwire Z AA AB \ | |
320x200+1200+500 \ | |
320x200+1200+850 \ | |
320x200+1200+1200 \ | |
320x200+1550+500 \ | |
320x200+1550+850 \ | |
400x175+1900+450 \ | |
400x175+1900+650 \ | |
400x175+1900+850 \ | |
400x175+1900+1050 \ | |
400x100+1900+1250 \ | |
400x100+1900+1400 \ | |
400x175+2300+450 \ | |
400x175+2300+650 \ | |
400x175+2300+850 \ | |
400x175+2300+1050 \ | |
400x100+2300+1250 \ | |
400x100+2300+1400 \ | |
400x175+2700+450 \ | |
400x175+2700+650 \ | |
400x175+2700+850 \ | |
400x175+2700+1050 \ | |
400x175+2700+1250 \ | |
2>/dev/null | |
# leave empty line bove this one | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( | |
#echo " s V mA mAh temp Vinput V1 V2 V3 V4 V5 V6 R1 R2 R3 R4 R5 R6 Rb Rw " | |
echo -e "t V mA mAh temp Vinput V1 V2 V3 V4 V5 V6 R1 R2 R3 R4 R5 R6 Rb Rw " | |
grep '$1' cheali.log | sed 's/;/ /g' | \ | |
awk '{ print $3 "\t" $4 / 100 "\t" $5 "\t" $6 "\t" $10 / 100 "\t" $11 / 100 "\t" $12 "\t" $13 "\t" $14 "\t" $15 "\t" $16 "\t" $17 "\t" $18 "\t" $19 "\t" $20 "\t" $21 "\t" $22 "\t" $23 "\t" $24 "\t" $25 }' \ | |
| tail -n `grep '$1' cheali.log | wc -l | awk '{ print $1 - 2000 }'` | |
) \ | |
| tee logview.tsv | xclip -selection clipboard -i | |
#| less |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
microcom -p /dev/ttyUSB0 -s 57600 | tee log/`date +%Y-%m-%dT%H:%M:%S.log` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment