Sleds/utils/sequencelogic-run-classification.sh

151 lines
3.7 KiB
Bash
Raw Normal View History

2025-03-13 21:28:38 +00:00
#!/bin/bash
# Usage: sequencelogic-run-classification.sh [--timeout seconds] [--pkgname pkgname] [--out {outputpath}] --frt {frtfilepath} --libindex {libraryindexpath}
# Where:
# {frtfilepath} is the .frt file resulting from OCR
# {libraryindexpath} is the library index file that enumerates the entire classification library
# {outputpath} is the optional output pathname; default is {frtfileparentpath}/classify.json
function usage(){
echo "Usage: sequencelogic-run-classification.sh [--timeout seconds] [--pkgname pkgname] [--out {outputpath}] --frt {frtfilepath} --libindex {libraryindexpath} --config {library config file}"
echo " Requires that ${SEQUENCELOGICHOME}/bin/scorepages exists and is executable"
echo " The --timeout arg option is used only for Linux"
echo " When run on Darwin then there is no ability (for now) to run scorepages and the results are assumed to be in:"
echo " /sequencelogic/SLSync/testdata/package/loan/classification/{pkgname}.json"
echo " Darwin requires the --pkgname pkgname argument"
exit 1
}
# setup
REDIR=/dev/null # use /dev/tty for debug
SCRIPT=$0
echo "[OK] Script: ${SCRIPT}" > ${REDIR}
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=`dirname ${SCRIPT}`
echo "[OK] This script is located at: $SCRIPTPATH" > ${REDIR}
if [ -f "${SCRIPTPATH}/sequencelogic-helpers.sh" ]; then
source ${SCRIPTPATH}/sequencelogic-helpers.sh > ${REDIR}
else
source ${SEQUENCELOGICHOME}/bin/sequencelogic-helpers.sh > ${REDIR}
fi
# get running bot count
BOTCNT=`countRunningBots`
CORECNT=`countCores`
MAXTHREADS=1
if [ "${BOTCNT}" -le "2" ]; then
MAXTHREADS=$(expr $CORECNT - 1)
else
MAXTHREADS=$(expr $(expr ${CORECNT} - ${BOTCNT}) / 2)
fi
if [ "${MAXTHREADS}" -le 3 ]; then
MAXTHREADS=4
fi
echo "There are ${BOTCNT} running robots and ${CORECNT} CPU cores on this machine; using ${MAXTHREADS} max threads"
IPADDR=`hostname -i`
echo "The address of this host is: $IPADDR"
echo " --------- Memory Info ----------- "
free -m
uptime
echo ""
# args
OUT=""
STAT=0
FRT=""
LIB=""
CONFIG=""
TIMEOUTPROG=""
if [ "$1" = "--timeout" ]; then
shift
TIMEOUTPROG="timeout $1"
shift
fi
CNAME=""
# Darwin only
if [ "$1" = "--pkgname" ]; then
shift
CNAME="$1"
shift
fi
if [ "$1" = "--out" ]; then
shift
OUT="$1"
shift
fi
if [ "$1" != "--frt" ]; then
echo "The --frt {frtpath} arg is required"
usage;
exit 1;
else
shift
FRT="$1"
shift
fi
if [ "$1" != "--libindex" ]; then
echo "The --libindex {indexfile} arg is required"
usage;
exit 1;
else
shift
LIB="$1"
shift
fi
if [ "$1" = "--config" ]; then
shift
CONFIG="$1"
shift
fi
if [ ! -f "${FRT}" ]; then
echo "--frt ${FRT} does not exist"
usage
exit 2;
fi
if [ ! -f "${LIB}" ]; then
echo "--libindex ${LIB} does not exist"
usage
exit 2;
fi
if [ "$OUT" = "" ]; then
OUT=`dirname "${FRT}"`/classify.json
fi
# There is no scorepages for Darwin :(
CPROG="${SEQUENCELOGICHOME}/bin/scorepages"
if [ "$PLATFORM" = "Darwin" -a ! -f "${CPROG}" ]; then
TDROOT="${SEQUENCELOGICHOME}/SLSync/testdata"
TESTOUT="${TDROOT}/package/loan/classification/${CNAME}.json"
if [ ! -f "$TESTOUT" ]; then
TESTOUT="${TDROOT}/NO_PI/classification/${CNAME}.json"
fi
echo "Looking for testdata in: $TESTOUT"
if [ -f "$TESTOUT" ]; then
cp "$TESTOUT" "$OUT"
else
STAT=-1
echo "Did not find testdata .json file"
fi
sleep 3
else
# The actual program is named: "scorepages" and must be in in ${SEQUENCELOGICHOME}/bin
if [ ! -x "$CPROG" ]; then
echo "$CPROG does not exist or is not executable"
exit 2;
fi
#export CHECKALL=${SEQUENCELOGICHOME}/SLSync/config/scorepages.env
$TIMEOUTPROG "$CPROG" -t ${MAXTHREADS} -c ${SEQUENCELOGICHOME}/SLSync/config/scorepages.bpf -j "${OUT}" "${FRT}" -f "${LIB}"
STAT=$?
fi
echo "Exit with status: $STAT"
exit $STAT