<commit_before>#!/bin/bash
# Compare two output tsv files, showing summarizing questions
# by performance change.

Tred="$(tput setaf 1)"
Tgreen="$(tput setaf 2)"
Tdefault="$(setterm -default)"

fgained="$(mktemp)"
fbetter="$(mktemp)"
fworse="$(mktemp)"
flost="$(mktemp)"

showline() {
	id=$1; q0=$2; g0=$3; s0=$4; s1=$5
	line=$(echo -e "$id\t$q0\t$g0\t$s0\t$s1")
	if [ "$(echo "$s1 > $s0" | bc)" = 1 ]; then
		if [ "$(echo "$s1 == 1" | bc)" = 1 ]; then
			line="$Tgreen$line$Tdefault"
		fi
		if [ "$(echo "$s0 == 0" | bc)" = 1 ]; then
			echo "$line" >>"$fgained"
		else
			echo "$line" >>"$fbetter"
		fi
	elif [ "$(echo "$s1 < $s0" | bc)" = 1 ]; then
		if [ "$(echo "$s0 == 1" | bc)" = 1 ]; then
			line="$Tred$line$Tdefault"
		fi
		if [ "$(echo "$s1 == 0" | bc)" = 1 ]; then
			echo "$line" >>"$flost"
		else
			echo "$line" >>"$fworse"
		fi
	fi
}

# FIXME: The join here will not work on completely missing questions.
join -t $'\t' "$@" |
	while IFS=$'\t' read id t0 q0 s0 g0 a0 c00 c10 c20 c30 c40 t1 q1 s1 g1 a1 c01 c11 c21 c31 c41; do
		showline "$id" "$q0" "$g0" "$s0" "$s1"
	done

echo "------------------- Gained answer to:"
cat "$fgained"
echo
echo "------------------- Improved score for:"
cat "$fbetter"
echo
echo "------------------- Worsened score for:"
cat "$fworse"
echo
echo "------------------- Lost answer to:"
cat "$flost"
<commit_msg>tsvout-compare.sh: Show even questions appearing only in one of the sets<commit_after>#!/bin/bash
# Compare two output tsv files, showing summarizing questions
# by performance change.

Tred="$(tput setaf 1)"
Tgreen="$(tput setaf 2)"
Tdefault="$(setterm -default)"

fgained="$(mktemp)"
fbetter="$(mktemp)"
fworse="$(mktemp)"
flost="$(mktemp)"

showline() {
	id=$1; q0=$2; g0=$3; s0=$4; s1=$5
	line=$(echo -e "$id\t$q0\t$g0\t$s0\t$s1")
	if [ "$(echo "$s1 > $s0" | bc)" = 1 ]; then
		if [ "$(echo "$s1 == 1" | bc)" = 1 ]; then
			line="$Tgreen$line$Tdefault"
		fi
		if [ "$(echo "$s0 == 0" | bc)" = 1 ]; then
			echo "$line" >>"$fgained"
		else
			echo "$line" >>"$fbetter"
		fi
	elif [ "$(echo "$s1 < $s0" | bc)" = 1 ]; then
		if [ "$(echo "$s0 == 1" | bc)" = 1 ]; then
			line="$Tred$line$Tdefault"
		fi
		if [ "$(echo "$s1 == 0" | bc)" = 1 ]; then
			echo "$line" >>"$flost"
		else
			echo "$line" >>"$fworse"
		fi
	fi
}

join -t $'\t' "$@" |
	while IFS=$'\t' read id t0 q0 s0 g0 a0 c00 c10 c20 c30 c40 t1 q1 s1 g1 a1 c01 c11 c21 c31 c41; do
		showline "$id" "$q0" "$g0" "$s0" "$s1"
	done

join -t $'\t' -v 1 "$@" |
	while IFS=$'\t' read id t0 q0 s0 g0 a0 c00 c10 c20 c30 c40; do
		showline "$id" "$q0" "$g0" "$s0" "0.0"
	done
join -t $'\t' -v 2 "$@" |
	while IFS=$'\t' read id t1 q1 s1 g1 a1 c01 c11 c21 c31 c41; do
		showline "$id" "$q1" "$g1" "0.0" "$s1"
	done

echo "------------------- Gained answer to:"
cat "$fgained"
echo
echo "------------------- Improved score for:"
cat "$fbetter"
echo
echo "------------------- Worsened score for:"
cat "$fworse"
echo
echo "------------------- Lost answer to:"
cat "$flost"

{'fraction_non_alphanumeric': 0.260752688172043, 'fraction_numerical': 0.05913978494623656, 'mean_word_length': 2.821566110397946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '635397', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1222, 'n_words': 391}