Skip to content

Commit

Permalink
#185 better explanation of metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Mar 4, 2024
1 parent 3004284 commit 1cb50a2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion metrics/ast.py
Expand Up @@ -418,7 +418,7 @@ class NotClassError(Exception):
amount of parameters in some static method in a class\n')
metric.write(f'nom {nom(tree_class)} '
f'Number of Overriding Methods (NOM), which is the number of methods \
with the \\text{{@Override}} annotation\n')
with the \\texttt{{@Override}} annotation\n')
metric.write(f'nop {nop(tree_class)} '
f'Number of Polymorphic Methods (NOP), which is the count of methods \
that are overloaded at least once --- have similar names but different parameters\n')
Expand Down
10 changes: 5 additions & 5 deletions metrics/multimetric.sh
Expand Up @@ -33,9 +33,9 @@ temp="${TARGET}/temp/multimetric.json"
mkdir -p "$(dirname "${temp}")"
echo "${body}" > "${temp}"
cat <<EOT> "${output}"
hsd $(echo "${body}" | jq '.halstead_difficulty' | "${LOCAL}/help/float.sh") Halstead Difficulty
hse $(echo "${body}" | jq '.halstead_effort' | "${LOCAL}/help/float.sh") Halstead Effort
hsv $(echo "${body}" | jq '.halstead_volume' | "${LOCAL}/help/float.sh") Halstead Volume
midx $(echo "${body}" | jq '.maintainability_index' | "${LOCAL}/help/float.sh") Maintainability Index
fout $(echo "${body}" | jq '.fanout_external' | "${LOCAL}/help/float.sh") Fan-Out
hsd $(echo "${body}" | jq '.halstead_difficulty' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Halstead_complexity_measures}{Halstead Difficulty}
hse $(echo "${body}" | jq '.halstead_effort' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Halstead_complexity_measures}{Halstead Effort}
hsv $(echo "${body}" | jq '.halstead_volume' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Halstead_complexity_measures}{Halstead Volume}
midx $(echo "${body}" | jq '.maintainability_index' | "${LOCAL}/help/float.sh") \href{https://ieeexplore.ieee.org/abstract/document/303623/}{Maintainability Index}
fout $(echo "${body}" | jq '.fanout_external' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Fan-out_(software)}{Fan-Out}
EOT
15 changes: 8 additions & 7 deletions metrics/pmd.sh
Expand Up @@ -50,18 +50,19 @@ export PMD_JAVA_OPTS=${JVM_OPTS}
# We don't use --cache here, because it becomes too big and leads to "Out Of Memory" error
pmd pmd -R "${tmp}/config.xml" -d "${tmp}" --format xml --fail-on-violation false > "${tmp}/result.xml" 2> "${tmp}/stderr.txt" || (cat "${tmp}/stderr.txt"; exit 1)

tail='\\href{https://en.wikipedia.org/wiki/Cognitive_complexity}{Cognitive Complexity} values for all methods in a class'
sed 's/xmlns=".*"//g' "${tmp}/result.xml" | \
(xmllint --xpath '//violation[@rule="CognitiveComplexity"]/text()' - 2>/dev/null || echo '') | \
sed -E "s/.*complexity of ([0-9]+).*/\1/" | \
sed '/^[[:space:]]*$/d' | \
ruby -e '
a = STDIN.read.split(" ").map(&:to_i)
ruby -e "
a = STDIN.read.split(' ').map(&:to_i)
sum = a.inject(&:+)
puts "coco #{a.empty? ? 0 : sum} Total Cognitive Complexity of All Methods"
puts "acoco #{a.empty? ? 0 : sum / a.count} Average Cognitive Complexity of a Method"
puts "mxcoco #{a.empty? ? 0 : a.max} Max Cognitive Complexity of a Method"
puts "mncoco #{a.empty? ? 0 : a.min} Min Cognitive Complexity of a Method"
' > "${output}"
puts \"coco #{a.empty? ? 0 : sum} Summary of ${tail}\"
puts \"acoco #{a.empty? ? 0 : sum / a.count} Average of ${tail}\"
puts \"mxcoco #{a.empty? ? 0 : a.max} Maximum ${tail}\"
puts \"mncoco #{a.empty? ? 0 : a.min} Minimum ${tail}\"
" > "${output}"

rm -rf "${tmp}"

6 changes: 5 additions & 1 deletion steps/tests.sh
Expand Up @@ -28,9 +28,13 @@ mkdir -p "${temp}"

export CAMTESTS=1

find "${LOCAL}/tests" -type f -name '*.sh' | sort | while IFS= read -r test; do
dir="${LOCAL}/tests"
tests=$(find "${dir}" -type f -name '*.sh' | sort)
echo "There are $(echo "${tests}" | wc -l | xargs) tests in ${dir}"
echo "${tests}" | while IFS= read -r test; do
name=$(realpath --relative-to="${LOCAL}/tests" "${test}")
if [ -n "${TEST}" ] && [ ! "${TEST}" = "${name}" ] && [ ! "${TEST}" = "tests/${name}" ]; then
echo "Skipped ${name}"
continue
fi
echo -e "\n${name}:"
Expand Down

0 comments on commit 1cb50a2

Please sign in to comment.