Create a sqlite database and log all frames drawn to it. For keeping track of pen usage and creating a dataset from which to predict drawing times for future frames

This commit is contained in:
Matt McWilliams 2021-12-08 00:18:45 -05:00
parent f541a2d2db
commit 0e601ebb9a
5 changed files with 70 additions and 12 deletions

4
.gitignore vendored
View File

@ -3,4 +3,6 @@
*.webm *.webm
*.mkv *.mkv
test_svg test_svg
test_png test_png
draw.sqlite
.env

View File

@ -22,6 +22,10 @@ hashStr () {
echo -n "${1}" | sha256sum | awk '{print $1}' echo -n "${1}" | sha256sum | awk '{print $1}'
} }
hashFile () {
sha256sum "${1}" | awk '{print $1}'
}
uuid () { uuid () {
uuidgen | tr "[:upper:]" "[:lower:]" uuidgen | tr "[:upper:]" "[:lower:]"
} }
@ -38,15 +42,6 @@ askContinue () {
fi fi
} }
log () {
read loglines
file=$(echo "${loglines}" | grep 'FILE:' | awk -F'FILE:' '{print $2}')
drawn=$(echo "${loglines}" | grep 'Length of path drawn' | awk -F': ' '{print $2}' | awk '{print $1}')
moved=$(echo "${loglines}" | grep 'Total distance moved' | awk -F': ' '{print $2}' | awk '{print $1}')
#echo "${loglines}"
echo "$file,$drawn,$moved"
}
axdraw () { axdraw () {
file=$(realpath "${1}") file=$(realpath "${1}")
echo "FILE:${file}" echo "FILE:${file}"

View File

@ -15,6 +15,8 @@ if [[ "${1}" == "" ]]; then
exit 1 exit 1
fi fi
dbSetup
FRAMES=$(realpath "${1}")/ FRAMES=$(realpath "${1}")/
END=-1 END=-1
@ -48,6 +50,7 @@ for svg in "${FRAMES}"*.svg ; do
i=$((i+1)) i=$((i+1))
continue continue
fi fi
filename=`basename "${svg}"` filename=`basename "${svg}"`
name=`echo "${filename}" | cut -d'.' -f1` name=`echo "${filename}" | cut -d'.' -f1`
num=`echo "${name}" | awk -F'_' '{print $(NF)}'` num=`echo "${name}" | awk -F'_' '{print $(NF)}'`
@ -57,7 +60,7 @@ for svg in "${FRAMES}"*.svg ; do
number=`mktemp`.svg number=`mktemp`.svg
node ./numbers/ -n "${num}" -o "${number}" node ./numbers/ -n "${num}" -o "${number}"
ax "${number}" ax "${number}"
ax "${svg}" axdraw "${svg}" | bash ./log.sh
rm -f "${number}" rm -f "${number}"
bash position.sh reset bash position.sh reset

50
log.sh Normal file
View File

@ -0,0 +1,50 @@
#!/bin/bash
source ./common.sh
loglines="$(cat /dev/stdin)"
id=$(uuid)
file=$(echo "${loglines}" | grep 'FILE:' | awk -F'FILE:' '{print $2}')
starttime=$(echo "${loglines}" | grep 'START:' | awk -F':' '{print $2}')
endtime=$(echo "${loglines}" | grep 'END:' | awk -F':' '{print $2}')
pen=$(echo "${loglines}" | grep 'PEN:' | awk -F':' '{print $2}')
drawn=$(echo "${loglines}" | grep 'Length of path drawn' | awk -F':' '{print $2}' | awk '{print $1}')
moved=$(echo "${loglines}" | grep 'Total distance moved' | awk -F':' '{print $2}' | awk '{print $1}')
hash=$(hashFile "${file}")
info=$(svginfo "${file}")
paths=$(echo "$info" | grep -m 1 'number of paths' | awk -F': ' '{print $2}')
total=$(echo "$info" | grep 'total path length' | awk -F': ' '{print $2}')
ratio=$(echo "$info" | grep 'pen move ratio' | awk -F': ' '{print $2}')
bboxclean=$(echo "$info" | grep 'bbox' | awk -F ')' '{print $1}' | awk -F'(' '{print $2}')
xmin=$(echo "$bboxclean" | awk -F', ' '{print $1}')
xmax=$(echo "$bboxclean" | awk -F', ' '{print $2}')
ymin=$(echo "$bboxclean" | awk -F', ' '{print $3}')
ymax=$(echo "$bboxclean" | awk -F', ' '{print $4}')
if [[ "${pen}" != "" ]]; then
pen="'${pen}'"
else
pen=null
fi
query="INSERT OR IGNORE INTO svg (id, file, drawn, moved, starttime, endtime, pen, hash, paths, total, ratio, xmin, xmax, ymin, ymax) VALUES (\
'$id', \
'$file',\
$drawn,\
$moved,\
$starttime,\
$endtime,\
$pen,\
'$hash',\
$paths,\
$total,\
$ratio,\
$xmin,\
$xmax,\
$ymin,\
$ymax
);"
db "${query}"
echo "${loglines}"

View File

@ -5,5 +5,13 @@ CREATE TABLE IF NOT EXISTS svg (
endtime INTEGER, endtime INTEGER,
drawn REAL, drawn REAL,
moved REAL, moved REAL,
pen TEXT paths INTEGER,
total REAL,
ratio REAL,
xmin REAL,
xmax REAL,
ymin REAL,
ymax REAL,
pen TEXT,
hash TEXT
); );