Now possible to have some overall score

This commit is contained in:
echarp 2022-12-12 21:05:06 +01:00
parent 9b749c54a8
commit ec97f64ba0
11 changed files with 108 additions and 7 deletions

View File

@ -17,7 +17,7 @@ choose() {
target=${target%)*}
target=${target#/pages}
echo "Choice => $target.md for user $user"
echo "Choice => $target for user $user"
mkdir -p "../content/users/$user${target%/*}/"
cp "../content/pages$target.md" "../content/users/$user${target%/*}/"
@ -27,6 +27,10 @@ choose() {
# Generate a result file
echo "$target" > "$dir/$page.result"
./_commands/default_actions.sh "$dir" "${target##*/}"
./_commands/count.sh "$dir" "${target##*/}" "${page}"
}
index=0

52
bin/_commands/count.sh Executable file
View File

@ -0,0 +1,52 @@
#!/bin/sh
dir=$1 file=$2 from=$3
dest_dir=${dir%%/content/users/*}/data/users/${dir##*/content/users/}
dest_file=$dest_dir/counters.yml
counter=${file%%.*}
if [ ! -e "$dir/_index.md" ]
then
echo "Creating $dir/_index.md"
echo "---
---
" > "$dir/_index.md"
fi
if ! grep -q "^ac_errors: " "$dir/_index.md"
then
sed -i "2,/---/s/---/ac_errors: 0\n---/" "$dir/_index.md"
fi
if ! grep -q "^ac_total: " "$dir/_index.md"
then
sed -i "2,/---/s/---/ac_total: 1\n---/" "$dir/_index.md"
fi
if [ ! -e "$dest_file" ]
then
mkdir -p "$dest_dir"
echo "Creating counter file for ${dir#*/content/}/$file, coming from: $from"
echo "$counter: 1" >> "$dest_file"
elif ! grep -q "$counter: " "$dest_file"
then
echo "$counter: 1" >> "$dest_file"
awk -i inplace "/ac_total: / {\$2=++\$2}; {print}" "$dir/_index.md"
else
# Increment counter
awk -i inplace "/$counter: / {\$2=++\$2}; {print}" "$dest_file"
fi
counter_from=$(grep -o "$from: .*" "$dest_file" | cut -d ' ' -f2)
counter_to=$(grep -o "$counter: .*" "$dest_file" | cut -d ' ' -f2)
echo "from $counter_from to $counter_to"
if [ "$counter_from" -lt "$counter_to" ]
then
echo "ERROR!!!"
awk -i inplace "/ac_errors: / {\$2=++\$2}; {print}" "$dir/_index.md"
fi

31
bin/_commands/count_test.bats Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env bats
setup() {
mkdir -p content/users/test
mkdir -p data/users/test
}
@test "Simple count" {
[ ! -e data/users/test/counters.md ]
bin/_commands/count.sh "$(pwd)/content/users/test" count_test.md start.md
[ -e data/users/test/counters.yml ]
[ -e content/users/test/_index.md ]
grep -o "errors: 0" content/users/test/_index.md
grep -o "count_test: 1" data/users/test/counters.yml
bin/_commands/count.sh "$(pwd)/content/users/test" count_test.md
grep -o "count_test: 2" data/users/test/counters.yml
bin/_commands/count.sh "$(pwd)/content/users/test" count_test_2.md
grep -o "count_test_2: 1" data/users/test/counters.yml
}
teardown() {
rm -rf content/users/test
rm -rf data/users/test
}

View File

@ -5,7 +5,7 @@
dir=$1 file=$2
echo "Default actions for $dir/$file"
echo "Default actions for ${dir##*/content/}/$file"
create() {
values=$(extract "$dir" "$file" ac_create)

View File

@ -3,7 +3,7 @@
# Routing acoeur commands to corresponding shell command
echo
echo "Triggering command for $1 $2"
echo "Triggering command for ${1##*/content/} $2"
cd "$(dirname "$0")" || exit

View File

@ -17,6 +17,12 @@
content: ">";
}
.notation {
right: 0;
bottom: 0;
position: absolute;
}
dl {
margin: 1em auto;
display: flex;

View File

@ -7,7 +7,7 @@ const tons = [264, 275, 297, 316.8, 330, 352, 371.25, 396, 412.5, 440, 475.2, 49
* Play one note
*/
note = (context, freq, counter) => {
console.log("Note n°", counter, freq)
// console.log("Note n°", counter, freq)
const oscil = context.createOscillator()
oscil.type = 'triangle'

View File

@ -1,6 +1,6 @@
{{ $featured_image := partial "func/GetFeaturedImage.html" . }}
<article class="bb b--black-10 w-100 mb4 bg-white pa3-ns flex flex-column flex-row-ns">
<article class="bb b--black-10 w-100 mb4 bg-white pa3-ns flex flex-column flex-row-ns relative">
{{$.Site.Language.LanguageDirection}}
{{ if $featured_image }}
{{/* Trimming the slash and adding absURL make sure the image works no matter where our site lives */}}
@ -33,4 +33,6 @@
{{ $.Param "read_more_copy" | default (i18n "readMore") | humanize }}
</a>
</div>
{{ partial "ac_notation" .Parent }}
</article>

View File

@ -0,0 +1,6 @@
{{ if gt .Params.ac_total 0 }}
<span class="notation">
{{ sub .Params.ac_total .Params.ac_errors }} / {{ .Params.ac_total }}
</span>
{{ end }}

View File

@ -1,7 +1,7 @@
<script>const file = '{{ .File }}'</script>
<script defer
src="https://unpkg.com/tinymce@6.2.0/tinymce.js"
src="https://unpkg.com/tinymce@6.3.0/tinymce.js"
referrerpolicy="origin"></script>
<script defer

@ -1 +1 @@
Subproject commit b393088d09300408281929f30427cdbfdad02009
Subproject commit a0c7382c597e817cb73c90684a32e14e74c33a28