<commit_before>#!/usr/bin/bash

get_config_value()
{
    sed 's/#.*//' "$1" | grep "$2" | cut -f2 -d= | sed -e 's/^\s*//' -e 's/\s*$//'
}

config_file="$1"
opening_moves="$2"
notes_file="$3"

if [[ -z "$config_file" ]]
then
    echo "Arguments: <gene pool config file> <moves in opening> <notes file>"
    echo "Only the first is required."
    exit 1
fi

if ! [[ -f "$config_file" ]]
then
    echo "Invalid gene pool configuration file: $config_file"
    exit 1
fi

if [[ -n "$notes_file" ]] && ! [[ -f "$notes_file" ]]
then
    echo "Invalid notes file: $notes_file"
    exit 1
fi

pool_file="$(get_config_value "$config_file" file)"
game_file="${pool_file}_games.pgn"
threshold_game_file="${game_file}_threshold.pgn"
opening_file="${game_file}_opening_list.txt"
octave analysis/gene_plots.m "$pool_file" "$notes_file" &
octave analysis/win_lose_draw_plotting.m "$game_file" "$notes_file" &

if [[ -f "$threshold_game_file" ]]
then
    echo "# Theshold game opponents:"
    grep '^\[White ' "$threshold_game_file" | cut -d\" -f2 | uniq -c
fi

# Second term here checks if argument is a number
if [[ -n "$opening_moves" ]] && [ "$opening_moves" -eq "$opening_moves" ]
then
    ./analysis/openings.sh "$game_file" "$opening_moves" && octave analysis/opening_plotting.m "$opening_file" "$notes_file" &<commit_msg>Print warning when opening analysis cannot be run<commit_after>#!/usr/bin/bash

get_config_value()
{
    sed 's/#.*//' "$1" | grep "$2" | cut -f2 -d= | sed -e 's/^\s*//' -e 's/\s*$//'
}

config_file="$1"
opening_moves="$2"
notes_file="$3"

if [[ -z "$config_file" ]]
then
    echo "Arguments: <gene pool config file> <moves in opening> <notes file>"
    echo "Only the first is required."
    exit 1
fi

if ! [[ -f "$config_file" ]]
then
    echo "Invalid gene pool configuration file: $config_file"
    exit 1
fi

if [[ -n "$notes_file" ]] && ! [[ -f "$notes_file" ]]
then
    echo "Invalid notes file: $notes_file"
    exit 1
fi

pool_file="$(get_config_value "$config_file" file)"
game_file="${pool_file}_games.pgn"
threshold_game_file="${game_file}_threshold.pgn"
opening_file="${game_file}_opening_list.txt"
octave analysis/gene_plots.m "$pool_file" "$notes_file" &
octave analysis/win_lose_draw_plotting.m "$game_file" "$notes_file" &

if [[ -f "$threshold_game_file" ]]
then
    echo "# Theshold game opponents:"
    grep '^\[White ' "$threshold_game_file" | cut -d\" -f2 | uniq -c
fi

# Second term here checks if argument is a number
if [[ -n "$opening_moves" ]] && [ "$opening_moves" -eq "$opening_moves" ]
then
    ./analysis/openings.sh "$game_file" "$opening_moves" && octave analysis/opening_plotting.m "$opening_file" "$notes_file" &
else
    echo "Invalid argument for openings analysis: $opening_moves"
{'fraction_non_alphanumeric': 0.17283046503112412, 'fraction_numerical': 0.007323324789454412, 'mean_word_length': 4.213740458015267, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '943439', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1001, 'n_words': 264}