Skip to content

[Feature suggestion] save a csv log of wins and playing time #73

@Felipe-noob

Description

@Felipe-noob

Hello,

I quite appreciate this little game, so I made a little wrapper script to log wins and playing time. It is available in my private github, so I paste the whole thing here. Feel free to include this under in the project if you wish.

#!/usr/bin/sh

DATABASE_PATH=~/.local/state/ttysolitaire
DATABASE=$DATABASE_PATH/db
mkdir -p $DATABASE_PATH
touch $DATABASE

FILE_RESULT=$(mktemp)
FILE_TIME=$(mktemp)

/usr/bin/time -f "%e" -o $FILE_TIME sh -c "ttysolitaire | tee $FILE_RESULT"

RESULT=$(grep "You won" $FILE_RESULT | wc -l)
GAME_TIME=$(cat $FILE_TIME)

echo $RESULT $GAME_TIME >> $DATABASE
rm -fr $FILE_TIME $FILE_RESULT

# Treating the database
GAME_TOTAL=$(cat $DATABASE | wc -l)
GAME_WINS=$(cut --delimiter " " --fields 1 $DATABASE | grep 1 | wc -l)
TIME_AVERAGE=$(grep '^1' $DATABASE | cut --delimiter " " --fields 2 | datamash mean 1)
echo Win Rate $GAME_WINS/$GAME_TOTAL $(echo "scale=2; 100 * $GAME_WINS / $GAME_TOTAL" | bc)% 
if [ $RESULT -eq 1 ]; then
	echo Time/Average $GAME_TIME/$TIME_AVERAGE
fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions