| 1 | package Image::Synchronize::GpsPositionCollection; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | #use parent 'Exporter'; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Image::Synchronize::Timerange; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Scalar::Util qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | looks_like_number | ||||||||||||||||||||||||||||
| 11 | 2 | ); | |||||||||||||||||||||||||||
| 12 | 2 | ▶ | use YAML::Any qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | Dump | ||||||||||||||||||||||||||||
| 14 | 2 | ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use overload '""' => \&stringify; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | Image::Synchronize::GpsPositionCollection - Manage a collection of GPS | ||||||||||||||||||||||||||||
| 21 | positions | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 METHODS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | The module provides the following methods: | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head2 new | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | $gpc = Image::Synchronize::GpsPositionCollection->new; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Creates and returns a new instance of the class. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 1 | my ($class) = @_; | |||||||||||||||||||||||||||
| 37 | 1 | bless { data => [], reduced => 0 }, $class; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head2 add | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | $gpc->add($time, $latitude, $longitude, $altitude, $id, $scope); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Adds a point to the track with the specified C<$id>, for the specified | ||||||||||||||||||||||||||||
| 45 | C<$scope>. The data of the point include the C<$time> (as from | ||||||||||||||||||||||||||||
| 46 | L<gmtime>), the C<$latitude> in degrees (positive to the north, | ||||||||||||||||||||||||||||
| 47 | negative to the south), the C<$longitude> in degrees (positive to the | ||||||||||||||||||||||||||||
| 48 | east, negative to the west), and the C<$altitude> in meters. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Returns the C<Image::Synchronize::GpsPositionCollection> itself. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 7 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=14 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 7 | my ( $self, $time, $latitude, $longitude, $altitude, $id, $scope ) = @_; | |||||||||||||||||||||||||||
| 56 | 7 | ▶ | $self->{tracks}->{$scope}->{$id} //= | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"tracks"}{$scope}{$id} //= {"data", [], "min_time", undef, "max_time", undef}
MC/DC100%1/1
$self->{"tracks"}{$scope}{$id} //= {"data", [], "min_time", undef, "max_time", undef}
$self->{"tracks"}{$scope}{$id}
Truth table100%2/2
A
A= $self->{"tracks"}{$scope}{$id}
| |||||||||||||||||||||||||||||
| 57 | { data => [], min_time => undef, max_time => undef }; | ||||||||||||||||||||||||||||
| 58 | 7 | $self->{track_id2scope}->{$id} = $scope; | |||||||||||||||||||||||||||
| 59 | 7 | my $track = $self->{tracks}->{$scope}->{$id}; | |||||||||||||||||||||||||||
| 60 | 7 | push @{ $track->{data} }, [ $time, $latitude, $longitude, $altitude ]; | |||||||||||||||||||||||||||
| 61 | 7 | ▶ | if ( defined $track->{max_time} and $time < $track->{max_time} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $track->{"max_time"} and $time < $track->{"max_time"}
MC/DC0%0/2
defined $track->{"max_time"} and $time < $track->{"max_time"}
defined $track->{"max_time"}
$time < $track->{"max_time"}
Truth table66%2/3
A and B
A= defined $track->{"max_time"}B= $time < $track->{"max_time"}
| |||||||||||||||||||||||||||||
| 62 | 0 | $track->{needs_reduction} = 1; | |||||||||||||||||||||||||||
| 63 | 0 | $self->{reduced} = 0; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | $track->{min_time} = $time if $time < $track->{min_time}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||
| 67 | 7 | ▶ | $track->{min_time} //= $time; | ||||||||||||||||||||||||||
|
Condition66%2/3
$track->{"min_time"} //= $time
MC/DC0%0/2
$track->{"min_time"} //= $time
$track->{"min_time"}
$time
Truth table66%2/3
A //= B
A= $track->{"min_time"}B= $time
| |||||||||||||||||||||||||||||
| 68 | 7 | $track->{max_time} = $time; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # TODO: support position bounding box crossing longitude 180 degrees | ||||||||||||||||||||||||||||
| 72 | $track->{min_longitude} = $longitude | ||||||||||||||||||||||||||||
| 73 | 7 | ▶ | if $longitude < ( $track->{min_longitude} // 1000 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$track->{"min_longitude"} // 1000
MC/DC100%1/1
$track->{"min_longitude"} // 1000
$track->{"min_longitude"}
Truth table100%2/2
A
A= $track->{"min_longitude"}
| |||||||||||||||||||||||||||||
| 74 | $track->{max_longitude} = $longitude | ||||||||||||||||||||||||||||
| 75 | 7 | ▶ | if $longitude > ( $track->{max_longitude} // -1000 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$track->{"max_longitude"} // -1000
MC/DC100%1/1
$track->{"max_longitude"} // -1000
$track->{"max_longitude"}
Truth table100%2/2
A
A= $track->{"max_longitude"}
| |||||||||||||||||||||||||||||
| 76 | $track->{min_latitude} = $latitude | ||||||||||||||||||||||||||||
| 77 | 7 | ▶ | if $latitude < ( $track->{min_latitude} // 1000 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$track->{"min_latitude"} // 1000
MC/DC100%1/1
$track->{"min_latitude"} // 1000
$track->{"min_latitude"}
Truth table100%2/2
A
A= $track->{"min_latitude"}
| |||||||||||||||||||||||||||||
| 78 | $track->{max_latitude} = $latitude | ||||||||||||||||||||||||||||
| 79 | 7 | ▶ | if $latitude > ( $track->{max_latitude} // -1000 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$track->{"max_latitude"} // -1000
MC/DC100%1/1
$track->{"max_latitude"} // -1000
$track->{"max_latitude"}
Truth table100%2/2
A
A= $track->{"max_latitude"}
| |||||||||||||||||||||||||||||
| 80 | 7 | return $self; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head2 ids_for_track | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | @ids_for_track = $gpc->ids_for_track($scope); | ||||||||||||||||||||||||||||
| 86 | @ids_for_track = $gpc->ids_for_track; # all scopes | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Returns a list of track IDs for the specified C<$scope>, or for all | ||||||||||||||||||||||||||||
| 89 | scopes. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | Note that a given C<$scope> includes all other scopes whose names have | ||||||||||||||||||||||||||||
| 92 | C<$scope> as their prefix. So, scope 'foo/bar' includes scopes | ||||||||||||||||||||||||||||
| 93 | 'foo/barbar' and 'foo/bar/bar', but not scope 'foo/fie'. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 9 | ▶ | sub ids_for_track { | ||||||||||||||||||||||||||
|
Subroutine
ids_for_track: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 9 | my ( $self, $scope ) = @_; | |||||||||||||||||||||||||||
| 99 | 9 | my @ids; | |||||||||||||||||||||||||||
| 100 | 9 | foreach my $s ( keys %{ $self->{tracks} } ) { | |||||||||||||||||||||||||||
| 101 | 20 | ▶ | if ($scope) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 9 | ▶ | next unless $s =~ /^\Q$scope\E/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 16 | push @ids, keys %{ $self->{tracks}->{$s} }; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 9 | return sort { $a cmp $b } @ids; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 16 | ▶ | sub track_for_id { | ||||||||||||||||||||||||||
|
Subroutine
track_for_id: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 110 | 16 | my ( $self, $track_id ) = @_; | |||||||||||||||||||||||||||
| 111 | 16 | my $scope = $self->{track_id2scope}->{$track_id}; | |||||||||||||||||||||||||||
| 112 | 16 | ▶ | return unless defined $scope; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 16 | my $track = $self->{tracks}->{$scope}->{$track_id}; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head2 points_for_track | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | $points = $gpc->points_for_track($track_id); | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Returns a reference to the array of track points for the track with | ||||||||||||||||||||||||||||
| 121 | the specified C<$track_id>, or C<undef> if that track is not known. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 6 | ▶ | sub points_for_track { | ||||||||||||||||||||||||||
|
Subroutine
points_for_track: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 6 | my ( $self, $track_id ) = @_; | |||||||||||||||||||||||||||
| 127 | 6 | my $track = $self->track_for_id($track_id); | |||||||||||||||||||||||||||
| 128 | 6 | ▶ | return unless $track; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 6 | return $track->{data}; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head2 extreme_times_for_track | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | ($min_time, $max_time) = $gpc->extreme_times_for_track($track_id); | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | Returns the least and greatest times of any points in the track with | ||||||||||||||||||||||||||||
| 137 | the specified C<$track_id>, or C<undef> if that track is not known. | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 7 | ▶ | sub extreme_times_for_track { | ||||||||||||||||||||||||||
|
Subroutine
extreme_times_for_track: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 7 | my ( $self, $track_id ) = @_; | |||||||||||||||||||||||||||
| 143 | 7 | my $track = $self->track_for_id($track_id); | |||||||||||||||||||||||||||
| 144 | 7 | ▶ | return unless $track; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 7 | return ( $track->{min_time}, $track->{max_time} ); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =head2 middle_bounding_box_for_track | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | ($latitude, $longitude) = $gpc->middle_bounding_box_for_track($track_id); | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Returns the coordinates of the middle of the bounding box of the track | ||||||||||||||||||||||||||||
| 153 | with the specified C<$track_id>, or C<undef> if that track is not | ||||||||||||||||||||||||||||
| 154 | known. | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | The bounding box touches the points with the least and greatest | ||||||||||||||||||||||||||||
| 157 | longitudes and latitudes. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 3 | ▶ | sub middle_bounding_box_for_track { | ||||||||||||||||||||||||||
|
Subroutine
middle_bounding_box_for_track: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 3 | my ( $self, $track_id ) = @_; | |||||||||||||||||||||||||||
| 163 | 3 | my $track = $self->track_for_id($track_id); | |||||||||||||||||||||||||||
| 164 | 3 | ▶ | return unless $track; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | return ( | ||||||||||||||||||||||||||||
| 166 | ( $track->{min_latitude} + $track->{max_latitude} ) / 2, | ||||||||||||||||||||||||||||
| 167 | 3 | ( $track->{min_longitude} + $track->{max_longitude} ) / 2, | |||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head2 reduce | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | $gpc->reduce; | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Ensures that for each GPS track the points are sorted in ascending | ||||||||||||||||||||||||||||
| 176 | order of time, and that there are no duplicate times. This is needed | ||||||||||||||||||||||||||||
| 177 | by L<position_for_time>. | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =cut | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # TODO: ensure that there are no duplicate times | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 1 | ▶ | sub reduce { | ||||||||||||||||||||||||||
|
Subroutine
reduce: called CC=5 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||
| 184 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 185 | 1 | ▶ | return if $self->{reduced}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 1 | foreach my $scope ( keys %{ $self->{tracks} } ) { | |||||||||||||||||||||||||||
| 187 | 3 | foreach my $track_id ( keys %{ $self->{tracks}->{$scope} } ) { | |||||||||||||||||||||||||||
| 188 | 3 | my $track = $self->{tracks}->{$scope}->{$track_id}; | |||||||||||||||||||||||||||
| 189 | 3 | ▶ | if ( $track->{needs_reduction} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | @{ $track->{data} } = sort { $a->[0] <=> $b->[0] } @{ $track->{data} }; | |||||||||||||||||||||||||||
| 191 | 0 | delete $track->{needs_reduction}; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | 1 | $self->{reduced} = 1; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =head2 tracks_for_time | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | @ids_for_track = $gpc->tracks_for_time($time, $scope); | ||||||||||||||||||||||||||||
| 201 | @ids_for_track = $gpc->tracks_for_time($time); # all scopes | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | Returns the C<@ids_for_track>, for the specified C<$scope> or all scopes, | ||||||||||||||||||||||||||||
| 204 | that cover the C<$time>, i.e., for which the C<$time> is greater than | ||||||||||||||||||||||||||||
| 205 | or equal to the oldest time of the track and the C<$time> is less than | ||||||||||||||||||||||||||||
| 206 | or equal to the youngest time of the track. | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Note that a given C<$scope> includes all other scopes whose names have | ||||||||||||||||||||||||||||
| 209 | C<$scope> as their prefix. So, scope 'foo/bar' includes scopes | ||||||||||||||||||||||||||||
| 210 | 'foo/barbar' and 'foo/bar/bar', but not scope 'foo/fie'. | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | Returns the empty list if no tracks cover the time (within the scope, | ||||||||||||||||||||||||||||
| 213 | if specified). | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub tracks_for_time { | ||||||||||||||||||||||||||
|
Subroutine
tracks_for_time: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 218 | 0 | my ( $self, $time, $scope ) = @_; | |||||||||||||||||||||||||||
| 219 | 0 | my @matching_ids_for_track; | |||||||||||||||||||||||||||
| 220 | 0 | foreach my $track_id ( $self->ids_for_track($scope) ) { | |||||||||||||||||||||||||||
| 221 | 0 | my ( $mintime, $maxtime ) = $self->extreme_times_for_track($track_id); | |||||||||||||||||||||||||||
| 222 | 0 | ▶ | push @matching_ids_for_track, $track_id | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mintime <= $time and $time <= $maxtime
MC/DC0%0/2
$mintime <= $time and $time <= $maxtime
$mintime <= $time
$time <= $maxtime
Truth table0%0/3
A and B
A= $mintime <= $timeB= $time <= $maxtime
| |||||||||||||||||||||||||||||
| 223 | if $mintime <= $time && $time <= $maxtime; | ||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | 0 | return @matching_ids_for_track; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | sub interpolate_point_ { | ||||||||||||||||||||||||||
|
Subroutine
interpolate_point_: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 229 | 0 | my ( $point1, $point2, $fraction ) = @_; | |||||||||||||||||||||||||||
| 230 | 0 | my @point_for_time; | |||||||||||||||||||||||||||
| 231 | 0 | foreach ( 1 .. 3 ) { | |||||||||||||||||||||||||||
| 232 | 0 | my $val1 = $point1->[$_]; | |||||||||||||||||||||||||||
| 233 | 0 | my $val2 = $point2->[$_]; | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | if ( looks_like_number($val1) && looks_like_number($val2) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&looks_like_number($val1) and &looks_like_number($val2)
MC/DC0%0/2
&looks_like_number($val1) and &looks_like_number($val2)
&looks_like_number($val1)
&looks_like_number($val2)
Truth table0%0/3
A and B
A= &looks_like_number($val1)B= &looks_like_number($val2)
| |||||||||||||||||||||||||||||
| 235 | 0 | push @point_for_time, $val1 * ( 1 - $fraction ) + $val2 * $fraction; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | else { | ||||||||||||||||||||||||||||
| 238 | 0 | push @point_for_time, $val1; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | 0 | return @point_for_time; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =head2 position_for_time | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | %positions = $gpc->position_for_time($time, | ||||||||||||||||||||||||||||
| 247 | scope => $scope, | ||||||||||||||||||||||||||||
| 248 | track => $track_id); | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | Returns the GPS positions for the indicated C<$time>, C<$scope>, | ||||||||||||||||||||||||||||
| 251 | and/or C<$track_id>, or an empty list if no matching positions are | ||||||||||||||||||||||||||||
| 252 | known. | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | The returned C<@positions> contains a reference to a hash for each | ||||||||||||||||||||||||||||
| 255 | found position. The hash contains keys C<'track'>, C<'scope'>, and | ||||||||||||||||||||||||||||
| 256 | C<'position'>. The value for the first key is the track ID. The | ||||||||||||||||||||||||||||
| 257 | value for the second key is the scope. The value for the last key is | ||||||||||||||||||||||||||||
| 258 | a reference to an array with elements C<[$longitude, $latitude, | ||||||||||||||||||||||||||||
| 259 | $altitude]>. The positions are sorted by decreasing scope length. | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =cut | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 0 | ▶ | sub position_for_time { | ||||||||||||||||||||||||||
|
Subroutine
position_for_time: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 264 | 0 | my ( $self, $time, %options ) = @_; | |||||||||||||||||||||||||||
| 265 | 0 | ▶ | $time = $time->time_utc | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | if Image::Synchronize::Timestamp->istypeof($time); | ||||||||||||||||||||||||||||
| 267 | 0 | my @results; | |||||||||||||||||||||||||||
| 268 | 0 | foreach my $scope ( | |||||||||||||||||||||||||||
| 269 | 0 | ▶ | sort { length($b) <=> length($a) or $a cmp $b } | ||||||||||||||||||||||||||
|
Condition0%0/3
length $b <=> length $a || $a cmp $b
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a
$a cmp $b
Truth table0%0/3
A || B
A= length $b <=> length $aB= $a cmp $b
| |||||||||||||||||||||||||||||
| 270 | 0 | keys %{ $self->{tracks} } | |||||||||||||||||||||||||||
| 271 | ) | ||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | # we accept points from GPX files in the same or higher | ||||||||||||||||||||||||||||
| 275 | # directories as the specified scope | ||||||||||||||||||||||||||||
| 276 | next | ||||||||||||||||||||||||||||
| 277 | if defined( $options{scope} ) | ||||||||||||||||||||||||||||
| 278 | 0 | ▶ | and $options{scope} !~ /^\Q$scope\E/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $options{"scope"} and not $options{"scope"} =~ /^\Q$scope\E/u
MC/DC0%0/2
defined $options{"scope"} and not $options{"scope"} =~ /^\Q$scope\E/u
defined $options{"scope"}
not $options{"scope"} =~ /^\Q$scope\E/u
Truth table0%0/3
A and not(B)
A= defined $options{"scope"}B= not $options{"scope"} =~ /^\Q$scope\E/u
| |||||||||||||||||||||||||||||
| 279 | 0 | my $data_for_scope = $self->{tracks}->{$scope}; | |||||||||||||||||||||||||||
| 280 | 0 | foreach my $track_id ( sort keys %{$data_for_scope} ) { | |||||||||||||||||||||||||||
| 281 | next | ||||||||||||||||||||||||||||
| 282 | if defined( $options{track_id} ) | ||||||||||||||||||||||||||||
| 283 | 0 | ▶ | and $track_id ne $options{track_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $options{"track_id"} and $track_id ne $options{"track_id"}
MC/DC0%0/2
defined $options{"track_id"} and $track_id ne $options{"track_id"}
defined $options{"track_id"}
$track_id ne $options{"track_id"}
Truth table0%0/3
A and B
A= defined $options{"track_id"}B= $track_id ne $options{"track_id"}
| |||||||||||||||||||||||||||||
| 284 | 0 | my $data_for_track = $data_for_scope->{$track_id}; | |||||||||||||||||||||||||||
| 285 | next | ||||||||||||||||||||||||||||
| 286 | if $time < $data_for_track->{min_time} | ||||||||||||||||||||||||||||
| 287 | 0 | ▶ | or $time > $data_for_track->{max_time}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$time < $data_for_track->{"min_time"} or $time > $data_for_track->{"max_time"}
MC/DC0%0/2
$time < $data_for_track->{"min_time"} or $time > $data_for_track->{"max_time"}
$time < $data_for_track->{"min_time"}
$time > $data_for_track->{"max_time"}
Truth table0%0/3
A or B
A= $time < $data_for_track->{"min_time"}B= $time > $data_for_track->{"max_time"}
| |||||||||||||||||||||||||||||
| 288 | 0 | my $points = $data_for_track->{data}; | |||||||||||||||||||||||||||
| 289 | my $index = | ||||||||||||||||||||||||||||
| 290 | 0 | ▶ | search( $time, scalar @{$points}, sub { $points->[ $_[0] ]->[0] } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | # now $index is the index into @$points of the last point with | ||||||||||||||||||||||||||||
| 293 | # time at or before $time | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | --$index if $index == scalar( @{$points} ) - 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if ( $index >= 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 0 | my $point1 = $points->[$index]; | |||||||||||||||||||||||||||
| 298 | 0 | my $point2 = $points->[ $index + 1 ]; | |||||||||||||||||||||||||||
| 299 | 0 | my $fraction = | |||||||||||||||||||||||||||
| 300 | ( $time - $point1->[0] ) / ( $point2->[0] - $point1->[0] ); | ||||||||||||||||||||||||||||
| 301 | 0 | my @point_for_time = interpolate_point_( $point1, $point2, $fraction ); | |||||||||||||||||||||||||||
| 302 | 0 | push @results, | |||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||
| 304 | track => $track_id, | ||||||||||||||||||||||||||||
| 305 | scope => $scope, | ||||||||||||||||||||||||||||
| 306 | position => \@point_for_time | ||||||||||||||||||||||||||||
| 307 | }; | ||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | 0 | return @results; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 219 | ▶ | sub get_value_ { | ||||||||||||||||||||||||||
|
Subroutine
get_value_: called CC=4 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 315 | 219 | my ( $get, $index ) = @_; | |||||||||||||||||||||||||||
| 316 | 219 | my $ok; | |||||||||||||||||||||||||||
| 317 | my $value; | ||||||||||||||||||||||||||||
| 318 | 219 | ▶ | if ( ref $get eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 319 | 0 | $value = $get->[$index]; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | elsif ( ref $get eq 'CODE' ) { | ||||||||||||||||||||||||||||
| 322 | 219 | $value = $get->($index); | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | else { | ||||||||||||||||||||||||||||
| 325 | 0 | ▶ | croak "Cannot search in data of type '" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | . ( ref($get) ? ref($get) : 'scalar' ) . "'\n"; | ||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | 219 | $value; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | =head2 search | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | $index = search($target, $count, $get); | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | Searches for the C<$target> in an array of C<$count> elements sorted | ||||||||||||||||||||||||||||
| 336 | in non-descending order. The array elements are accessed through | ||||||||||||||||||||||||||||
| 337 | C<$get>, which may be an array reference or a code reference. If it | ||||||||||||||||||||||||||||
| 338 | is a code reference, then the elements of the array are accessed | ||||||||||||||||||||||||||||
| 339 | through C<< $get->($index) >>. | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | Returns the greatest element C<$index> for which the element is equal | ||||||||||||||||||||||||||||
| 342 | to or less than the C<$target>. If the C<$target> is less than the | ||||||||||||||||||||||||||||
| 343 | first element of the array, then returns -1. | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | =cut | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 51 | ▶ | sub search { | ||||||||||||||||||||||||||
|
Subroutine
search: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 348 | 2 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 349 | 51 | my ( $target, $count, $get ) = @_; | |||||||||||||||||||||||||||
| 350 | 51 | my $imin = 0; | |||||||||||||||||||||||||||
| 351 | 51 | my $imax = $count; | |||||||||||||||||||||||||||
| 352 | 51 | ▶ | while ( $imin < $imax ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | 170 | my $imid = ( $imin + $imax ) / 2; | |||||||||||||||||||||||||||
| 354 | 170 | my $value; | |||||||||||||||||||||||||||
| 355 | 170 | $value = get_value_( $get, $imid ); | |||||||||||||||||||||||||||
| 356 | 170 | ▶ | if ( $value < $target ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 72 | $imin = $imid + 1; | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | else { | ||||||||||||||||||||||||||||
| 360 | 98 | $imax = $imid; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | 51 | ▶ | return $count - 1 if $imin == $count; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 49 | my $value = get_value_( $get, $imin ); | |||||||||||||||||||||||||||
| 365 | 49 | ▶ | return $imin - 1 if $target < $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 21 | return $imin; | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 0 | ▶ | sub display_time_utc { | ||||||||||||||||||||||||||
|
Subroutine
display_time_utc: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 370 | 0 | my ($time) = @_; | |||||||||||||||||||||||||||
| 371 | 0 | ▶ | return unless defined $time; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | 0 | my ( $second, $minute, $hour, $day, $month, $year ) = gmtime($time); | |||||||||||||||||||||||||||
| 373 | 0 | ++$month; | |||||||||||||||||||||||||||
| 374 | 0 | $year += 1900; | |||||||||||||||||||||||||||
| 375 | 0 | return sprintf( '%d-%02d-%02dT%02d:%02d:%02dZ', | |||||||||||||||||||||||||||
| 376 | $year, $month, $day, $hour, $minute, $second ); | ||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 1 | ▶ | sub extends { | ||||||||||||||||||||||||||
|
Subroutine
extends: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 380 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 381 | 1 | my @ranges; | |||||||||||||||||||||||||||
| 382 | 1 | foreach my $track_id ( $self->ids_for_track ) { | |||||||||||||||||||||||||||
| 383 | 3 | push @ranges, | |||||||||||||||||||||||||||
| 384 | { | ||||||||||||||||||||||||||||
| 385 | times => [ $self->extreme_times_for_track($track_id) ], | ||||||||||||||||||||||||||||
| 386 | position => [ $self->middle_bounding_box_for_track($track_id) ] | ||||||||||||||||||||||||||||
| 387 | }; | ||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | 1 | @ranges = sort { $a->{times}->[0] <=> $b->{times}->[0] } @ranges; | |||||||||||||||||||||||||||
| 390 | 1 | foreach my $i ( 0 .. $#ranges ) { | |||||||||||||||||||||||||||
| 391 | 3 | my $r = $ranges[$i]->{times}; | |||||||||||||||||||||||||||
| 392 | $ranges[$i]->{times} = | ||||||||||||||||||||||||||||
| 393 | 3 | Image::Synchronize::Timerange->new( $r->[0], $r->[1] ); | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | 1 | return @ranges; | |||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 1 | ▶ | sub stringify { | ||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 399 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 400 | 1 | my @r = $self->extends; | |||||||||||||||||||||||||||
| 401 | 3 | $_ = sprintf( '%-34s %#13.8f %#13.8f', $_->{times}, @{ $_->{position} } ) | |||||||||||||||||||||||||||
| 402 | 1 | foreach @r; | |||||||||||||||||||||||||||
| 403 | 1 | return Dump( \@r ); | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | This module uses the following non-core Perl module: | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | =over | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | =item | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | Image::Synchronize::Timerange; | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | =item | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | namespace::clean | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | =item | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | YAML::Any | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | =back | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | Louis Strous E<lt>LS@quae.nlE<gt> | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | Copyright (c) 2018 - 2020 Louis Strous. | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 435 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | =cut | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 2 | 1; | |||||||||||||||||||||||||||