[scripts] AggSetCoord: -l option (select lines)

This commit is contained in:
Matteo Cypriani 2013-07-30 14:29:36 -04:00
parent 37b8157bc6
commit 1ffbe7a8c1
1 changed files with 27 additions and 13 deletions

View File

@ -10,7 +10,7 @@ owlps-aggsetcoord - set the coordinates in an aggregation CSV file
B<owlps-aggsetcoord> B<owlps-aggsetcoord>
[ B<-h> | B<-V> ] [ B<-h> | B<-V> ]
[ B<-v> ] [ B<-v> ]
[ B<-c> <I<coordinates>> ] [ B<-c> <I<coordinates>> [ B<-l> <I<line_selection>> ] ]
[ B<-m> <I<mac>> ] [ B<-m> <I<mac>> ]
[ <I<aggregation_file>> ] [ <I<aggregation_file>> ]
@ -49,17 +49,6 @@ diff tools such as I<vimdiff> to visualise the differences between the input
file and the result and make sure it corresponds to what was expected. file and the result and make sure it corresponds to what was expected.
=head1 LIMITATIONS
=over 3
=item *
It is not yet possible to choose an interval of lines to work on: the whole file
is treated.
=back
=head1 OPTIONS =head1 OPTIONS
=over 7 =over 7
@ -82,6 +71,13 @@ Apply I<coordinates> to every positioning request with default X, Y and Z. A
line in which at least one of the three coordinates is set to a non-default line in which at least one of the three coordinates is set to a non-default
value will be left untouched. I<coordinates> is a string "X;Y;Z". value will be left untouched. I<coordinates> is a string "X;Y;Z".
=item B<-l> <I<line_selection>>
Skip lines that are not part of the selection pattern I<line_selection>, which
is evaluated as a Perl numeric list. For example, "3, 5, 8..10" will select the
lines 3, 5, 8, 9 and 10; "1..25,42..45" will select the lines 1 to 25 and 42 to
77. This works only with the B<-c> option.
=item B<-m> <I<mac>> =item B<-m> <I<mac>>
Work only on positioning requests transmitted by MAC address I<mac>. Work only on positioning requests transmitted by MAC address I<mac>.
@ -136,6 +132,10 @@ use constant BASE_COORD => "0.00";
# Verbose mode # Verbose mode
my $verbose; my $verbose;
# List of the lines to work on (will stay undefined if all the lines have to be
# worked on)
my %selected_lines;
# Selected transmitter's MAC address (will stay undefined if -m was not used) # Selected transmitter's MAC address (will stay undefined if -m was not used)
my $selected_mac; my $selected_mac;
@ -317,7 +317,7 @@ sub apply_interpolation($$$$$$) {
## Option parsing ## ## Option parsing ##
$Getopt::Std::STANDARD_HELP_VERSION = 1; $Getopt::Std::STANDARD_HELP_VERSION = 1;
use constant OPTIONS => 'c:hm:vV'; use constant OPTIONS => 'c:hl:m:vV';
my %options; my %options;
if (!getopts(OPTIONS, \%options)) { if (!getopts(OPTIONS, \%options)) {
HELP_MESSAGE(*STDERR); HELP_MESSAGE(*STDERR);
@ -343,6 +343,12 @@ if (defined($new_coordinates)) {
($new_x, $new_y, $new_z) = split_point_3d($new_coordinates); ($new_x, $new_y, $new_z) = split_point_3d($new_coordinates);
} }
# Register the selected lines
if (defined($options{'l'})) {
die "-l option requires -c option!" if (!defined($new_coordinates));
$selected_lines{$_} = 1 foreach eval $options{'l'};
}
## Main loop: read lines ## ## Main loop: read lines ##
@ -409,6 +415,13 @@ while ($cur_line = <>) {
# option): we print it immediately (we are sure not to have any previous # option): we print it immediately (we are sure not to have any previous
# lines in memory, since we don't do that in this mode) # lines in memory, since we don't do that in this mode)
if (defined($new_coordinates)) { if (defined($new_coordinates)) {
# Skip the line if it is not part of the selected lines
if (%selected_lines and !$selected_lines{$line_nb}) {
trace("Line not selected: skipped.\n");
print $cur_line;
next;
}
# If the current line is fully incomplete, we reconstitute it with the # If the current line is fully incomplete, we reconstitute it with the
# new coordinates # new coordinates
if (is_blank($x, $y, $z)) { if (is_blank($x, $y, $z)) {
@ -428,6 +441,7 @@ while ($cur_line = <>) {
else { else {
print $cur_line; print $cur_line;
} }
# In either case, jump to the next line # In either case, jump to the next line
next; next;
} }