<commit_before>#!/bin/bash

BUCKETS=(aardvark potato shinyunicorn flabbergasted supercalifragilistic vertigo pork random rubber parrot muffin antidisestablishmentarianism seven shishkebap cheesecake ballsacks)
TYPES=(g c s ms)

usage() {
    echo "Usage: -h [host] -p [port]"
    exit 1
}

rand() {
    printf $(($1 *  RANDOM  / 32767))
}

sample() {
    declare -a ary=("${!1}")
    unset ary[0]
    printf $'%s\n' "${ary[$(($(rand "${#ary[*]}")+1))]}"
}

emit() {
    local samples rate metric

    values=(1 $(rand 10) $(rand 10000))
    samples=('' "|@0.${RANDOM:0:2}" "")
    rate=$(sample samples[@])
    metric="$(sample BUCKETS[@]):$(sample values[@])|$(sample TYPES[@])$rate"

    echo $metric
    echo -n $metric | nc -u ${HOST-"127.0.0.1"} ${PORT-"8125"} -c
}<commit_msg>Using dict to generate psuedo random words for metric samples<commit_after>#!/bin/bash

RANDOM=$$;
WORDFILE=/usr/share/dict/words
LINES=30 # $(cat $WORDFILE | wc -l)

word() {
    rnum=$((RANDOM*RANDOM%$LINES+1))
    printf `sed -n "$rnum p" $WORDFILE`
}

TYPES=(g c s ms)

usage() {
    echo "Usage: -h [host] -p [port]"
    exit 1
}

rand() {
    printf $(($1 *  RANDOM  / 32767))
}

sample() {
    declare -a ary=("${!1}")
    unset ary[0]
    printf $'%s\n' "${ary[$(($(rand "${#ary[*]}")+1))]}"
}

emit() {
    local samples rate metric

    values=(1 $(rand 10) $(rand 10000))
    samples=('' "|@0.${RANDOM:0:2}" "")
    rate=$(sample samples[@])
    metric="$(word):$(sample values[@])|$(sample TYPES[@])$rate"

    echo $metric
    echo -n $metric | nc -u ${HOST-"127.0.0.1"} ${PORT-"8125"} -c
}
{'fraction_non_alphanumeric': 0.22965299684542587, 'fraction_numerical': 0.04100946372239748, 'mean_word_length': 3.5314285714285716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4456731', 'n_tokens_mistral': 680, 'n_tokens_neox': 633, 'n_words': 153}