| [28] | 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use 5.010; |
|---|
| 6 | use Getopt::Long qw(GetOptions); |
|---|
| 7 | Getopt::Long::Configure qw(gnu_getopt); |
|---|
| 8 | use Data::Dumper; |
|---|
| 9 | use DateTime; |
|---|
| 10 | use Math::Round qw/nearest/; |
|---|
| 11 | |
|---|
| 12 | my $srcFile = "/dev/stdin"; |
|---|
| 13 | my $interval = 10; |
|---|
| 14 | my $precision = 1; |
|---|
| 15 | |
|---|
| 16 | GetOptions( |
|---|
| 17 | 'interval|i=s' => \$interval, |
|---|
| 18 | 'precision|p=s' => \$precision, |
|---|
| 19 | ) or die "Usage: $0 [--interval <sec:=10>][--precision <dec:=1>]\n"; |
|---|
| 20 | my $pf = 1/(10**$precision); |
|---|
| 21 | |
|---|
| 22 | die "No source file found!" unless (-e $srcFile); |
|---|
| 23 | my $srcHnd = undef; |
|---|
| 24 | open($srcHnd, "< :encoding(UTF-8)", $srcFile) || die "$0: can't open $srcFile for reading: $!"; |
|---|
| 25 | my $limit = undef; |
|---|
| 26 | my $cnt = 0; |
|---|
| 27 | my $pe = 0; |
|---|
| 28 | my $a2 = 0; |
|---|
| 29 | my $a3 = 0; |
|---|
| 30 | my $a4 = 0; |
|---|
| 31 | my $a5 = 0; |
|---|
| 32 | my $te = 0; |
|---|
| 33 | while (<$srcHnd>) { |
|---|
| 34 | # |
|---|
| 35 | # <Date>;<Time>;<Periode>;<A2>;<A3>;<A4>;<A5>;<Temperature> |
|---|
| 36 | # [1-3] [4-6] [7] [8] [9] [10] [11] [12] |
|---|
| 37 | # 3.10.2019;10:55:12;40804;318;311;103;103;39 |
|---|
| 38 | # |
|---|
| 39 | if (/^([0-9]+)\.([0-9]+)\.([0-9]+)[;\s+]([0-9]+):([0-9]+):([0-9]+);([0-9]+);([0-9\.]+);([0-9\.]+);([0-9\.]+);([0-9\.]+);([0-9\.]+)$/) { |
|---|
| 40 | my $dt = DateTime->new( |
|---|
| 41 | year => $3, |
|---|
| 42 | month => $2, |
|---|
| 43 | day => $1, |
|---|
| 44 | hour => $4, |
|---|
| 45 | minute => $5, |
|---|
| 46 | second => $6, |
|---|
| 47 | time_zone => 'floating', |
|---|
| 48 | ); |
|---|
| 49 | # print "$1.$2.$3 $4:$5:$6 => ".$dt->dmy('.')." ".$dt->hms."\n"; |
|---|
| 50 | if (!$limit) { |
|---|
| 51 | $limit = $dt->clone(); |
|---|
| 52 | $limit->add( seconds => $interval ); |
|---|
| 53 | $cnt = 0; |
|---|
| 54 | $pe = $7; |
|---|
| 55 | $a2 = 0; |
|---|
| 56 | $a3 = 0; |
|---|
| 57 | $a4 = 0; |
|---|
| 58 | $a5 = 0; |
|---|
| 59 | $te = 0; |
|---|
| 60 | } |
|---|
| 61 | # print "Current: ".$dt->dmy('.')." ".$dt->hms."\n"; |
|---|
| 62 | # print "Limit: ".$limit->dmy('.')." ".$limit->hms."\n"; |
|---|
| 63 | # exit 0; |
|---|
| 64 | $cnt += 1; |
|---|
| 65 | $a2 += $8; |
|---|
| 66 | $a3 += $9; |
|---|
| 67 | $a4 += $10; |
|---|
| 68 | $a5 += $11; |
|---|
| 69 | $te += $12; |
|---|
| 70 | if ($dt >= $limit) { |
|---|
| 71 | # print $limit->dmy('.').";".$limit->hms.";$pe;".nearest('0.1',$a2/$cnt).";".nearest('0.1',$a3/$cnt).";".nearest('0.1',$a4/$cnt).";".nearest('0.1',$a5/$cnt).";".nearest('0.1',$te/$cnt)."\n"; |
|---|
| 72 | print $limit->dmy('.')." ".$limit->hms.";$pe;".nearest($pf,$a2/$cnt).";".nearest($pf,$a3/$cnt).";".nearest($pf,$a4/$cnt).";".nearest($pf,$a5/$cnt).";".nearest($pf,$te/$cnt)."\n"; |
|---|
| 73 | undef $limit; |
|---|
| 74 | } |
|---|
| 75 | } else { |
|---|
| 76 | print STDERR "ERROR: $_\n"; |
|---|
| 77 | } |
|---|
| 78 | } |
|---|