Skip to content

Commit

Permalink
#104 partial aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 13, 2023
1 parent 57a2995 commit a47093c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
25 changes: 21 additions & 4 deletions steps/aggregate-repo.sh
Expand Up @@ -26,14 +26,31 @@ set -o pipefail
repo=$1
pos=$2
total=$3
all=$4
metrics=$4

start=$(date +%s%N)

dir=${TARGET}/measurements/${repo}
ddir=${TARGET}/data/${repo}
if [ -e "${ddir}" ]; then
echo "${repo} already aggregated (${pos}/${total}): ${ddir}"
declare -i found=0
declare -i missing=0
for m in ${metrics}; do
if [ -e "${ddir}/${m}.csv" ]; then
found=$((found+1))
else
missing=$((missing+1))
fi
done
if [ "${missing}" = 0 ]; then
echo "All ${found} metrics in ${repo} already aggregated (${pos}/${total}): ${ddir}"
exit
fi
echo "Not all $((found+missing)) metrics aggregated in ${repo} (${pos}/${total}), ${missing} missing: ${ddir}"
fi

if [ ! -e "${dir}" ]; then
echo "Nothing to aggregate in ${repo} (${pos}/${total}), no measurements in ${ddir}"
exit
fi

Expand All @@ -55,14 +72,14 @@ find "${dir}" -name '*.m' | {
mkdir -p "$(dirname "${csv}")"
if [ ! -e "${csv}" ]; then
printf 'java_file' > "${csv}"
for a in ${all}; do
for a in ${metrics}; do
printf ",%s" "${a}" >> "${csv}"
done
printf '\n' >> "${csv}"
fi
java=$(echo "${m}" | sed "s|${dir}||" | sed "s|\.m$||")
printf '%s' "$(echo "${java}" | "${LOCAL}/help/to-csv.sh")" >> "${csv}"
for a in ${all}; do
for a in ${metrics}; do
if [ -e "${m}.${a}" ]; then
value=$("${LOCAL}/help/float.sh" < "${m}.${a}")
printf ",%s" "${value}" >> "${csv}"
Expand Down
26 changes: 19 additions & 7 deletions tests/steps/test-aggregate-repo.sh
Expand Up @@ -35,11 +35,23 @@ msg=$("${LOCAL}/steps/aggregate-repo.sh" "${repo}" 1 1 'loc nhd')
test "$(echo "${msg}" | grep -c "sum=0")" == 0
test "$(echo "${msg}" | grep -c "files=0")" == 0
test -e "${TARGET}/data/${repo}/all.csv"
grep "/a/Foo\\\\,Bar.java,42,0.75" "${TARGET}/data/${repo}/all.csv" >> "${stdout}" 2>&1
grep "java_file,loc,nhd" "${TARGET}/data/${repo}/all.csv" >> "${stdout}" 2>&1
test -e "${TARGET}/data/${repo}/loc.csv"
grep "java_file,loc" "${TARGET}/data/${repo}/loc.csv" >> "${stdout}" 2>&1
grep "/a/Foo\\\\,Bar.java,42" "${TARGET}/data/${repo}/loc.csv" >> "${stdout}" 2>&1
test -e "${TARGET}/data/${repo}/nhd.csv"
grep ",42" "${TARGET}/data/${repo}/loc.csv" >> "${stdout}" 2>&1
{
grep "/a/Foo\\\\,Bar.java,42,0.75" "${TARGET}/data/${repo}/all.csv"
grep "java_file,loc,nhd" "${TARGET}/data/${repo}/all.csv"
test -e "${TARGET}/data/${repo}/loc.csv"
grep "java_file,loc" "${TARGET}/data/${repo}/loc.csv"
grep "/a/Foo\\\\,Bar.java,42" "${TARGET}/data/${repo}/loc.csv"
test -e "${TARGET}/data/${repo}/nhd.csv"
grep ",42" "${TARGET}/data/${repo}/loc.csv"
} >> "${stdout}" 2>&1
echo "👍🏻 A repo aggregated correctly"

repo="dog/cat"
dir="${TARGET}/data/${repo}"
mkdir -p "${dir}"
touch "${dir}/loc.csv"
msg=$("${LOCAL}/steps/aggregate-repo.sh" "${repo}" 1 1 'loc nhd')
{
echo "${msg}" | grep "Not all 2 metrics aggregated"
} >> "${stdout}" 2>&1
echo "👍🏻 A partially aggregated repo processed correctly"

0 comments on commit a47093c

Please sign in to comment.