<commit_before># Get total count of python dependencies and outdated python dependencies

total_python_deps="$(pip list| wc -l)"
outdated_python_deps="$(pip list --outdated| wc -l)"
major_outdated_python_deps="$(pip list --format json --outdated | ./scripts/pip-dep-debt.py | grep -v '^0\.' | wc -l)"

# Get outdated JS dependency count

function outdated_count {
    python - <(cat -) <<-END
import json
import sys
with open(sys.argv[1], "r") as json_file:
    dep_arr = json.load(json_file)
print(len(dep_arr["data"]["body"]))
END
}

outdated_js_deps="$(yarn outdated --json | sed -n 2p | outdated_count)"


# Get total JS dependencies from package.json

function dependency_count {
    local json_path="$1"
    python - "$json_path" <<-END
import json
import sys

with open(sys.argv[1], "r") as json_file:
    packages = json.load(json_file)

print(sum(len(packages[k]) for k in ["dependencies", "devDependencies"]))
END
}

total_js_deps=$(dependency_count package.json)

# Publish metrics to Datadog

source scripts/datadog-utils.sh

send_metric_to_datadog "commcare.static_analysis.dependency.python.total" $total_python_deps "gauge"
send_metric_to_datadog "commcare.static_analysis.dependency.python.outdated" $outdated_python_deps "gauge"
send_metric_to_datadog "commcare.static_analysis.dependency.python.major_outdated" $major_outdated_python_deps "gauge"


send_metric_to_datadog "commcare.static_analysis.dependency.js.total" $total_js_deps "gauge"
send_metric_to_datadog "commcare.static_analysis.dependency.js.outdated" $outdated_js_deps "gauge"
<commit_msg>Add metrics for python deps on outdated minor/patch release as well<commit_after># Get total count of python dependencies and outdated python dependencies

total_python_deps="$(pip list| wc -l)"
outdated_python_deps_list="$(pip list --format json --outdated | ./scripts/pip-dep-debt.py)"
outdated_python_deps="$(echo ${outdated_python_deps_list} | wc -l)"
major_outdated_python_deps="$(echo ${outdated_python_deps_list} | grep '^[^0]' | wc -l)"
minor_outdated_python_deps="$(echo ${outdated_python_deps_list} | grep '^0\.[^0]' | wc -l)"
patch_outdated_python_deps="$(echo ${outdated_python_deps_list} | grep '^0\.0\.[^0]' | wc -l)"

# Get outdated JS dependency count

function outdated_count {
    python - <(cat -) <<-END
import json
import sys
with open(sys.argv[1], "r") as json_file:
    dep_arr = json.load(json_file)
print(len(dep_arr["data"]["body"]))
END
}

outdated_js_deps="$(yarn outdated --json | sed -n 2p | outdated_count)"


# Get total JS dependencies from package.json

function dependency_count {
    local json_path="$1"
    python - "$json_path" <<-END
import json
import sys

with open(sys.argv[1], "r") as json_file:
    packages = json.load(json_file)

print(sum(len(packages[k]) for k in ["dependencies", "devDependencies"]))
END
}

total_js_deps=$(dependency_count package.json)

# Publish metrics to Datadog

source scripts/datadog-utils.sh

send_metric_to_datadog "commcare.static_analysis.dependency.python.total" $total_python_deps "gauge"
send_metric_to_datadog "commcare.static_analysis.dependency.python.outdated" $outdated_python_deps "gauge"
send_metric_to_datadog "commcare.static_analysis.dependency.python.major_outdated" $major_outdated_python_deps "gauge"
send_metric_to_datadog "commcare.static_analysis.dependency.python.minor_outdated" $minor_outdated_python_deps "gauge"
send_metric_to_datadog "commcare.static_analysis.dependency.python.patch_outdated" $patch_outdated_python_deps "gauge"


send_metric_to_datadog "commcare.static_analysis.dependency.js.total" $total_js_deps "gauge"
send_metric_to_datadog "commcare.static_analysis.dependency.js.outdated" $outdated_js_deps "gauge"

{'fraction_non_alphanumeric': 0.12300621789672884, 'fraction_numerical': 0.0040551500405515, 'mean_word_length': 6.370517928286852, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2957642', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1272, 'n_words': 270}