#!/usr/bin/perl -w
#
# (w) XL 2016/03/08
#
# usage: akku.pl < akku.log

use strict;

my $Ah1= 0.0; # upper limit
my $Ah2= 0.0; # averaged
my $Ah3= 0.0; # lower limit
my $R = 15.0;

my $old_u= 0;
my ($u, $Ah);

while (<>) {
    (undef, $u, undef, $Ah, undef) = split '\t';
    if ($old_u == 0) {
        $old_u= $u;
    }
    $Ah1 += $old_u/$R/360.0;
    $Ah2 += ($old_u + $u)/$R/720.0;
    $Ah3 += $u/$R/360.0;
    $old_u= $u;
}

printf "Akku-Kapazität oberer Grenzwert:  %.5f Ah\n", $Ah1;
printf "Akku-Kapazität linear gemittelt:  %.5f Ah\n", $Ah2;
printf "Akku-Kapazität unterer Grenzwert: %.5f Ah\n", $Ah3;
printf "Akku-Kapazität vom Akkutester: %s Ah\n", $Ah;
printf "Toleranzband: %.3f %%\n", 200.0*($Ah1-$Ah3)/($Ah1+$Ah3);
