tFix memelog from cache. Fix makefile forced execution. - bitreich-memestats - metrics and graphs for the bitreich meme collection
 (HTM) git clone git://src.adamsgaard.dk/bitreich-memestats
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit d8747a03518ac500b7027b3abe0fd2d29f110bd0
 (DIR) parent 726dbaf74c47d4260c83251a2145d780a5d15bc9
 (HTM) Author: Christoph Lohmann <20h@r-36.net>
       Date:   Sun, 29 Aug 2021 22:20:41 +0200
       
       Fix memelog from cache. Fix makefile forced execution.
       
       Diffstat:
         M Makefile                            |      12 ++++++------
         M media-stats.sh                      |      49 ++++++++++++++++++++++++++++---
       
       2 files changed, 51 insertions(+), 10 deletions(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       t@@ -3,24 +3,24 @@
        MEMECACHE = "/br/gopher/memecache"
        ANNNA = "/home/annna/bin"
        
       -memecount: plot-memecount.sh media-stats memecount_lin memecount_semilog
       +memecount: media-stats memecount_lin memecount_semilog
                cat memecount_lin media-stats memecount_semilog > $@
        
       -media-stats: media-stats.sh
       +media-stats:
                ./media-stats.sh $(MEMECACHE) > $@
        
       -memecount_lin: plot-memecount.sh memecount.log
       +memecount_lin: memecount.log
                ./plot-memecount.sh memecount.log > $@
        
       -memecount_semilog: plot-memecount.sh memecount.log
       +memecount_semilog: memecount.log
                ./plot-memecount.sh memecount.log semilog > $@
        
        # output format: date<tab>commit<tab>n_memes
       -memecount.log: extract-memecount.sh
       +memecount.log:
                ./extract-memecount.sh $(ANNNA) $@
        
        clean:
                rm -f media-stats
                rm -f memecount{,.log,_lin,_semilog}
        
       -.PHONY: clean
       +.PHONY: clean memecount.log media-stats
 (DIR) diff --git a/media-stats.sh b/media-stats.sh
       t@@ -1,6 +1,8 @@
        #!/bin/sh
        # output formatted table with memecache media statistics
        
       +set -x
       +
        # estimated average image viewing time [s]
        img_viewing_time=5
        
       t@@ -9,18 +11,56 @@ if [ $# -ne 1 ]; then
                exit 1
        fi
        
       +oldpathfile="memecache_pathcache.txt.old"
       +touch "${oldpathfile}"
       +oldstatusfile="${oldpathfile}.status"
       +todofile="memecache_pathcache.txt.todo"
       +touch "${todofile}"
       +pathfile="memecache_pathcache.txt"
       +
       +find "$1" \
       +        -maxdepth 1 \
       +        -type f \
       +        \! \( -name '*.orig' \
       +                -o -name '*.nochip' \
       +                -o -name '*.txt' \
       +                -o -name '*.meme' \
       +                -o -name '*.pdf' \
       +        \) \
       +        | sort > "${pathfile}"
       +comm -3 "${pathfile}" "${oldpathfile}" > "${todofile}"
       +
        i=0
        sum=0.0
       -for f in "$1"/*.{mkv,mp4,webm,mp3,ogg}; do
       +# Get state.
       +if [ -e "${oldstatusfile}" ]; then
       +        sum="$(head -n 1 "${oldstatusfile}")"
       +        i="$(tail -n 1 "${oldstatusfile}")"
       +fi
       +
       +# Old work on diff.
       +fifofile="$(mktemp -u media-stats.fifo.XXXXXX)"
       +mkfifo ${fifofile}
       +grep '.*mkv$\|.*mp4$\|.*webm$\|.*mp3$\|.*ogg$' "${todofile}" \
       +        2>/dev/null >${fifofile} &
       +while read -r f; do
                i=$((i+=1))
                new_sum="$(printf '%f + %f\n' \
                        "$(ffprobe -v error -show_entries format=duration \
                           -of default=noprint_wrappers=1:nokey=1 "$f")" "$sum" 2>/dev/null | \
                           bc -l)"
                sum="$new_sum"
       -done
       -n_img="$(ls "$1"/*.{png,jpg,JPG,gif} | wc -l)"
       -n_vid="$(ls "$1"/*.{mkv,mp4,webm,mp3,ogg} | wc -l)"
       +done < ${fifofile}
       +rm -f ${fifofile}
       +
       +# Store state.
       +cp "${pathfile}" "${oldpathfile}"
       +printf "%f\n%i\n" "${sum}" "${i}" > "${oldstatusfile}"
       +
       +n_img="$(grep '.*png$\|.*jpg$\|.*JPG$\|.*gif$' "${pathfile}" \
       +        2>/dev/null | wc -l)"
       +n_vid="$(grep '.*mkv$\|.*mp4$\|.*webm$\|.*mp3$|.*ogg$' "${pathfile}" \
       +        2>/dev/null | wc -l)"
        
        printf '\n                      '
        printf '+----- statistics (%s) ------+\n' "$(date '+%Y-%m-%d')"
       t@@ -41,3 +81,4 @@ printf '| total movie length:   %10.1f h |\n' \
                "$(printf '%s/3600\n' "$sum" | bc -l)"
        printf '                      '
        printf '+------------------------------------+\n'
       +