source: trunk/Arduino/projects/OT_boiler/mittelwert @ 28

Last change on this file since 28 was 28, checked in by markus, 7 years ago

Adding measurement data and tools

  • Property svn:executable set to *
File size: 2.1 KB
RevLine 
[28]1#!/usr/bin/perl -w
2
3use strict;
4use warnings;
5use 5.010;
6use Getopt::Long qw(GetOptions);
7Getopt::Long::Configure qw(gnu_getopt);
8use Data::Dumper;
9use DateTime;
10use Math::Round qw/nearest/;
11
12my $srcFile = "/dev/stdin";
13my $interval = 10;
14my $precision = 1;
15
16GetOptions(
17        'interval|i=s' => \$interval,
18        'precision|p=s' => \$precision,
19) or die "Usage: $0 [--interval <sec:=10>][--precision <dec:=1>]\n";
20my $pf = 1/(10**$precision);
21
22die "No source file found!" unless (-e $srcFile);
23my $srcHnd = undef;
24open($srcHnd, "< :encoding(UTF-8)", $srcFile) || die "$0: can't open $srcFile for reading: $!";
25my $limit = undef;
26my $cnt = 0;
27my $pe = 0;
28my $a2 = 0;
29my $a3 = 0;
30my $a4 = 0;
31my $a5 = 0;
32my $te = 0;
33while (<$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}
Note: See TracBrowser for help on using the repository browser.