Skip to content

Instantly share code, notes, and snippets.

@cgsdev0
Created October 4, 2023 13:42
Show Gist options
  • Save cgsdev0/322578ae942df37bc7290a00326baac7 to your computer and use it in GitHub Desktop.
Save cgsdev0/322578ae942df37bc7290a00326baac7 to your computer and use it in GitHub Desktop.
LD54 analysis tools
#!/bin/bash
cd /var/lib/docker/volumes/root_ld54volume/_data
list_scores() {
for LEVEL in {0..14}; do
SCORE_AND_USER=$(sort $LEVEL -n | head -1)
SCORE=$(echo "$SCORE_AND_USER" | cut -d' ' -f1)
USER=$(echo "$SCORE_AND_USER" | cut -d' ' -f2)
FREQ=$(sort -u "$LEVEL" | grep -c '^'"$SCORE ")
printf "%s:%s:%s:%s" $LEVEL $FREQ $SCORE $USER
if [[ "$FREQ" == "1" ]]; then
printf "\t%s" "<-- SUSPICIOUS"
fi
printf "\n"
done
}
find_sus() {
while IFS= read line; do
LEVEL=$(echo "$line" | cut -d':' -f1)
BEST_SCORE=$(sort $LEVEL -n -u | head -1 | cut -d' ' -f1)
SCORE_AND_USER=$(echo "$line" | cut -d':' -f2-)
SCORE=$(echo "$SCORE_AND_USER" | cut -d' ' -f1)
USER=$(echo "$SCORE_AND_USER" | cut -d' ' -f2)
FREQ=$(grep -c '^'"$SCORE " $LEVEL)
STR="$(printf "%s\t%s:%s:%s" "$USER" "$LEVEL" "$FREQ" "$SCORE")"
if [[ "$FREQ" == "1" ]] && [[ "$SCORE" == "$BEST_SCORE" ]]; then
STR+="$(printf "\t%s" "<-- SUSPICIOUS")"
elif [[ "$SCORE" == "$BEST_SCORE" ]]; then
STR+="$(printf "\t%s" "<-- wr")"
fi
printf "%s\n" "$STR"
done < <(grep " $1" *)
}
case "$1" in
delete)
echo -n "Are you sure you want to delete scores from '$2'? (y/n) "
read -n1 char
echo
if [[ "$char" != "y" ]]; then
echo "Aborting!"
exit 0
fi
for LEVEL in {0..14}; do
mkdir -p ~/backup-ld54-scores
cp "$LEVEL" ~/"backup-ld54-scores/$LEVEL"
echo "Backing up level $LEVEL..."
done
TOTAL=0
for LEVEL in {0..14}; do
BEFORE=$(wc -l $LEVEL | cut -d' ' -f1)
sed -i "/$2/d" "$LEVEL"
AFTER=$(wc -l $LEVEL | cut -d' ' -f1)
REMOVED=$(( BEFORE - AFTER ))
TOTAL=$(( TOTAL + REMOVED ))
echo "Removed $REMOVED scores from level $LEVEL."
done
echo "Removed a total of $TOTAL scores."
;;
level)
LEVEL="$2"
SCORE_AND_USER=$(sort $LEVEL -n | head -1)
SCORE=$(echo "$SCORE_AND_USER" | cut -d' ' -f1)
(printf "\n\n%s\n\n" "Best score is $SCORE"; grep -E "$SCORE |$" $LEVEL --color=always) | less -R
;;
inspect)
DO_IT=$(find_sus "$2" | sort -n -k 2 | fzf)
if [[ ! -z "$DO_IT" ]]; then
$0 delete "$2"
fi
;;
*)
# default
USER=$(list_scores | fzf | cut -f1 | cut -d':' -f4-)
if [[ ! -z "$USER" ]]; then
$0 inspect "$USER"
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment