18 |
my $got_it; |
my $got_it; |
19 |
my $stats; |
my $stats; |
20 |
|
|
21 |
|
sub error { |
22 |
|
my ( $self, $message, $line ) = @_; |
23 |
|
push @{ $stats->{errors}->{$message} }, $line; |
24 |
|
} |
25 |
|
|
26 |
|
sub stats { |
27 |
|
my $self = shift; |
28 |
|
return $stats; |
29 |
|
} |
30 |
|
|
31 |
sub line { |
sub line { |
32 |
my $self = shift; |
my $self = shift; |
33 |
my $l = shift || return; |
my $l = shift || return; |
36 |
chomp; |
chomp; |
37 |
my @a = split(/,/,$_); |
my @a = split(/,/,$_); |
38 |
|
|
39 |
return unless $#a == 12; |
if ( $#a != 12 ) { |
40 |
|
$self->error( 'invalid line length' => $_ ); |
41 |
|
return; |
42 |
|
} |
43 |
|
|
44 |
# warn "## [$#a] ", join(' ', map { "$_:$a[$_]" } ( 0 .. $#a )), " from $_\n"; |
# warn "## [$#a] ", join(' ', map { "$_:$a[$_]" } ( 0 .. $#a )), " from $_\n"; |
45 |
|
|
46 |
# is valid? |
# is valid? |
47 |
return unless $a[2] eq 'A'; |
if ( $a[2] ne 'A' ) { |
48 |
|
$self->error( 'not valid' => $_ ); |
49 |
|
return; |
50 |
|
} |
51 |
|
|
52 |
my $hash; |
my $hash; |
53 |
my $i = 1; # skip GPRMC; |
my $i = 1; # skip GPRMC; |
58 |
$hash->{lat} = hhmm( ( $hash->{lat_ns} eq 'S' ? -1 : 1 ) * $hash->{lat_hhmm} ) || return; |
$hash->{lat} = hhmm( ( $hash->{lat_ns} eq 'S' ? -1 : 1 ) * $hash->{lat_hhmm} ) || return; |
59 |
$hash->{lon} = hhmm( ( $hash->{lon_ew} eq 'W' ? -1 : 1 ) * $hash->{lon_hhmm} ) || return; |
$hash->{lon} = hhmm( ( $hash->{lon_ew} eq 'W' ? -1 : 1 ) * $hash->{lon_hhmm} ) || return; |
60 |
|
|
61 |
return if ( $got_it->{ $hash->{lat} . ' ' . $hash->{lon} }++ ); |
if ( $got_it->{ $hash->{lat} . ' ' . $hash->{lon} }++ ) { |
62 |
|
$self->error( 'duplicate line' => $_ ); |
63 |
|
return; |
64 |
|
} |
65 |
|
|
66 |
|
$stats->{ 'min_'.$_ } = $hash->{ $_ } < $stats->{ 'min_'.$_ } foreach ( qw/lat lon/ ); |
67 |
|
$stats->{ 'max_'.$_ } = $hash->{ $_ } > $stats->{ 'max_'.$_ } foreach ( qw/lat lon/ ); |
68 |
|
|
69 |
|
$hash->{number} = $stats->{total}++; |
70 |
|
|
71 |
# warn "##>>>> ",dump( $hash ); |
# warn "##>>>> ",dump( $hash ); |
72 |
return $hash; |
return $hash; |