Skip to content

Commit 9103e32

Browse files
committed
evaluation - parameterized scripts for managing and processing logs
- Aim is to avoid copying each script to log directories. Instead, all logs now take parameters that define where are the logs etc. - Deleted `evaluate_newest` as its functionality would be the same as `evaluate_from_dir`'s after parameterization
1 parent 70a6f12 commit 9103e32

File tree

4 files changed

+89
-47
lines changed

4 files changed

+89
-47
lines changed

srpb_evaluation/scripts/copy_logs.sh

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
#!/usr/bin/env bash
22
#
3-
# Copies 3 newest files from this directory to the directory given by argument.
4-
# It is handy to put that script into the logs directory.
3+
# Copies 3 newest log files (robot/people/groups) from the one directory to the directory given by argument.
54
#
6-
if [ "$#" -ne 1 ]; then
7-
echo "What's the target directory?"
5+
# Usage looks like:
6+
#
7+
# rosrun srpb_evaluation copy_logs.sh <path_to_the_main_directory_with_logs> <path_to_the_target_directory>
8+
#
9+
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
10+
echo "Wrong usage. Script args:"
11+
echo " (1) [required] path to the source directory with logs ('*_robot.txt', '*_people.txt', and '*_groups.txt')"
12+
echo " (2) [required] path to the target directory with copied logs; relative paths will be considered as relative to the source directory"
813
exit 0
914
fi
1015

11-
SCRIPT_DIR=$(realpath $(dirname $0))
12-
TARGET_DIR="$SCRIPT_DIR/$1"
13-
LOGS_DIR=$SCRIPT_DIR
14-
mkdir -p $TARGET_DIR
16+
logs_dir="$1"
17+
# trim trailing / (if exists)
18+
logs_dir="${logs_dir%/}"
19+
20+
target_dir="$2"
21+
# trim trailing / (if exists)
22+
target_dir="${target_dir%/}"
23+
24+
if [[ ! $target_dir == /* ]]; then
25+
echo "Relative path"
26+
target_dir=$logs_dir/$target_dir
27+
fi
28+
29+
# create a new directory for the copied logs
30+
mkdir -p $target_dir
1531

1632
# https://stackoverflow.com/a/54910963
17-
files_to_copy=$(ls -t $LOGS_DIR/log_*.txt | head -3)
18-
cp $files_to_copy $TARGET_DIR
33+
newest_robot=$(ls -t $logs_dir/log_*_robot.txt | head -1)
34+
newest_people=$(ls -t $logs_dir/log_*_people.txt | head -1)
35+
newest_groups=$(ls -t $logs_dir/log_*_groups.txt | head -1)
36+
37+
# added an escape sequence for newline (file paths are printed in separate lines)
38+
files_to_copy="$newest_robot"$'\n'"$newest_people"$'\n'"$newest_groups"
39+
cp $files_to_copy $target_dir
1940

2041
echo "Copied:"
2142
echo ""
2243
echo "$files_to_copy"
2344
echo ""
24-
echo "to $TARGET_DIR"
45+
echo "to $target_dir"

srpb_evaluation/scripts/evaluate_all_dirs.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,50 @@
22
#
33
# Runs srpb_evaluation node with the newest set of log files from each directory below the script's path
44
#
5-
# It expects that `evaluate_from_dir.sh` script is placed in the same directory
5+
# It expects that `evaluate_from_dir.sh` script is available using `rosrun srpb_evaluation evaluate_from_dir.sh`
66
#
77
# Remember to source your ROS workspace before execution
88
#
9-
SCRIPT_DIR=$(realpath $(dirname $0))
9+
# This script can be executed using:
10+
#
11+
# rosrun srpb_evaluation evaluate_all_dirs.sh <path> <safety_distance>
12+
#
13+
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
14+
echo "Wrong usage. Script args:"
15+
echo " (1) [required] full path to the main directory with grouped logs (3 logs in each separate directory)"
16+
echo " (2) [optional] safety distance for m_obs metric, 0.55 by default"
17+
exit 0
18+
fi
19+
20+
# only the path to logs directory is given
21+
if [ "$#" -eq 1 ]; then
22+
logs_dir="$1"
23+
# trim trailing / (if exists)
24+
logs_dir="${logs_dir%/}"
25+
safety_dist=0.55
26+
echo "Using logs main directory: '$logs_dir' and default safety distance of '$safety_dist' m"
27+
fi
28+
29+
if [ "$#" -eq 2 ]; then
30+
logs_dir="$1"
31+
# trim trailing / (if exists)
32+
logs_dir="${logs_dir%/}"
33+
safety_dist=$2
34+
echo "Using logs main directory: '$logs_dir' and custom safety distance of '$safety_dist' m"
35+
fi
36+
37+
# exclude main directory from the search below
38+
logs_basename=$(basename $logs_dir)
1039

1140
# - ignore directories starting with the underscore
1241
# - for each directory, run the `evaluate_from_dir` script, passing each found directory as an argument
1342
# Ref:
1443
# * https://stackoverflow.com/a/20292636
1544
# * https://stackoverflow.com/a/15736463
16-
find . -maxdepth 1 -type d -not -path "./_*" \( ! -name . \) -exec bash -c "$SCRIPT_DIR/evaluate_from_dir.sh '{}'" \;
45+
find $logs_dir -maxdepth 1 -type d -not -path "$logs_dir/_*" \( ! -name $logs_basename \) -exec bash -c "rosrun srpb_evaluation evaluate_from_dir.sh '{}'" \;
1746

1847
# first part of command above to save number of evaluated dirs, ref: https://stackoverflow.com/a/15663664
19-
count=$(find . -maxdepth 1 -type d -not -path "./_*" \( ! -name . \) | wc -l)
48+
count=$(find $logs_dir -maxdepth 1 -type d -not -path "$logs_dir/_*" \( ! -name $logs_basename \) | wc -l)
2049

2150
echo
2251
echo "Evaluated $count directories"

srpb_evaluation/scripts/evaluate_from_dir.sh

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,34 @@
44
#
55
# Remember to source your ROS workspace before execution
66
#
7-
if [ "$#" -ne 1 ]; then
8-
echo "What's the target directory?"
7+
# This script can be executed using:
8+
#
9+
# rosrun srpb_evaluation evaluate_from_dir.sh <path> <safety_distance>
10+
#
11+
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
12+
echo "Wrong usage. Script args:"
13+
echo " (1) [required] full path to the directory with logs ('*_robot.txt', '*_people.txt', and '*_groups.txt')"
14+
echo " (2) [optional] safety distance for m_obs metric, 0.55 by default"
915
exit 0
1016
fi
1117

12-
SCRIPT_DIR=$(realpath $(dirname $0))
13-
LOGS_DIR="$1"
14-
SAFETY_DIST=0.55
18+
# only the path to logs directory is given
19+
if [ "$#" -eq 1 ]; then
20+
logs_dir="$1"
21+
safety_dist=0.55
22+
echo "Using logs directory: '$logs_dir' and default safety distance of '$safety_dist' m"
23+
fi
24+
25+
if [ "$#" -eq 2 ]; then
26+
logs_dir="$1"
27+
safety_dist=$2
28+
echo "Using logs directory: '$logs_dir' and custom safety distance of '$safety_dist' m"
29+
fi
1530

1631
# https://stackoverflow.com/a/54910963
17-
newest_robot=$(ls -t $LOGS_DIR/log_*_robot.txt | head -1)
18-
newest_people=$(ls -t $LOGS_DIR/log_*_people.txt | head -1)
19-
newest_groups=$(ls -t $LOGS_DIR/log_*_groups.txt | head -1)
32+
newest_robot=$(ls -t $logs_dir/log_*_robot.txt | head -1)
33+
newest_people=$(ls -t $logs_dir/log_*_people.txt | head -1)
34+
newest_groups=$(ls -t $logs_dir/log_*_groups.txt | head -1)
2035

2136
echo "Evaluating:"
2237
echo ""
@@ -25,4 +40,4 @@ echo "people data: $newest_people"
2540
echo "groups data: $newest_groups"
2641
echo ""
2742

28-
rosrun srpb_evaluation srpb_evaluation $newest_robot $newest_people $newest_groups $SAFETY_DIST
43+
rosrun srpb_evaluation srpb_evaluation $newest_robot $newest_people $newest_groups $safety_dist

srpb_evaluation/scripts/evaluate_newest.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)