Stable image import

This commit is contained in:
Vincent Riquer 2015-02-06 09:40:30 +01:00
parent 951c2a2bac
commit b8e8b8395b
9 changed files with 63 additions and 17 deletions

View File

@ -22,6 +22,7 @@ for lib in lib/*
do do
source $lib source $lib
done done
import_images &
read_query_string read_query_string
send_headers <<-EOHead send_headers <<-EOHead

1
import
View File

@ -82,6 +82,7 @@ then
rrdtool update "$rrdfile" -t $template "${data//:0/:U}" 2>&1 rrdtool update "$rrdfile" -t $template "${data//:0/:U}" 2>&1
done <<<"${POST["data"]}" done <<<"${POST["data"]}"
else else
import_images &
send_headers <<-EOHead send_headers <<-EOHead
content-type: text/xml content-type: text/xml
EOHead EOHead

12
index
View File

@ -22,16 +22,16 @@ for lib in lib/*
do do
source $lib source $lib
done done
import_images &
read_query_string read_query_string
(( start >= end)) && (( end = start + 604800 )) (( start >= end)) && (( end = start + 604800 ))
if [ -z "$graph" ] if [ -z "$graph" ]
then then
import_images &
refresh=300 refresh=300
[[ -r .importing ]] && refresh=5 [[ -r .importing ]] && refresh=5
send_headers <<-EOHead send_headers $(( refresh - 1 )) <<-EOHead
content-type: application/xhtml+xml content-type: application/xhtml+xml
refresh: $refresh refresh: $refresh
EOHead EOHead
@ -112,6 +112,9 @@ then
</table> </table>
EOHTML EOHTML
show_current_level show_current_level
[[ -r .importing ]] && cat <<-EOHTML
<div class="updating">Importing $(<.importing)</div>
EOHTML
cat <<-EOHTML cat <<-EOHTML
</div> </div>
<div class="main"> <div class="main">
@ -389,6 +392,11 @@ then
</td> </td>
</tr> </tr>
</table> </table>
EOHTML
[[ -r .importing ]] && cat <<-EOHTML
<div class="updating">Importing $(<.importing)</div>
EOHTML
cat <<-EOHTML
</div> </div>
<div class="maingraph"> <div class="maingraph">
EOHTML EOHTML

View File

@ -59,6 +59,13 @@ td.submenu-inv {
background: #444; background: #444;
color: white color: white
} }
div.updating {
position: relative;
background: orange;
width: 100%;
text-align: center;
font-size: larger;
}
div.main { div.main {
position: absolute; position: absolute;

View File

@ -21,14 +21,31 @@ image() {
local timestamp=$2 local timestamp=$2
declare -A values declare -A values
tmpfile=$(mktemp --suffix=.png) tmpfile=$(mktemp --suffix=.tiff)
convert -contrast "$1" "$tmpfile" transform='-adaptive-resize 600%x400% -contrast -channel green -threshold 50%'
readarray -t tactout < <(tesseract -l eng -psm 4 "$tmpfile" stdout)
if (( debug >= 3 ))
then
readarray -t tactout < <(convert $transform "$1" -format tiff - | tee "${1%.png}.tiff" | tesseract -l eng -psm 4 stdin stdout)
else
readarray -t tactout < <(convert $transform "$1" -format tiff - | tesseract -l eng -psm 4 stdin stdout)
fi
if ((debug_import >=2 ))
then
for index in ${!tactout[@]}
do
echo "${tactout[index]}"
done > "${1%.png}.txt"
fi
rm "$tmpfile" rm "$tmpfile"
for line in "${tactout[@]}" for line in "${tactout[@]}"
do do
case "$line" in case "$line" in
'Error, please try again.')
# Ingress failed when generating image, ignore file.
return 3
;;
#14,522,411 AP 144mm AP #14,522,411 AP 144mm AP
*' AP'*) *' AP'*)
read value junk <<<"$line" read value junk <<<"$line"
@ -175,5 +192,11 @@ image() {
template="${!values[@]}" template="${!values[@]}"
updatevalues="${values[@]}" updatevalues="${values[@]}"
if ((debug_import))
then
echo $'\t'"$template"
echo $'\t'"$updatevalues"
fi
rrdtool update "$rrdfile" -t "${template// /:}" "$timestamp:${updatevalues// /:}" rrdtool update "$rrdfile" -t "${template// /:}" "$timestamp:${updatevalues// /:}"
} }

View File

@ -1,30 +1,33 @@
#!/bin/bash #!/bin/bash
import_images() { import_images() {
local starttime=$(date +%s) imagetime timestamp elapsed local starttime=$(date +%s) imagetime timestamp elapsed lasttime now
exec >> images.log exec >> images.log
exec 2>> images.log exec 2>> images.log
declare -r oldIFS="$IFS" declare -r oldIFS="$IFS"
[[ -r .importing ]] && return 2 [[ -r .importing ]] && return 2
[[ -w "$rrdfile" ]] || rrdcreate [[ -w "$rrdfile" ]] || rrdcreate
readlast readlast
for file in dav/* for file in dav/profile_*.png
do do
[[ -r "$file" ]] || continue [[ -r "$file" ]] || continue
(( count++ ))
IFS=_. IFS=_.
read junk date time junk <<<"$file" read junk date time junk <<<"$file"
IFS="$oldIFS" IFS="$oldIFS"
if (( $(date '+%Y%m%d%H%M%S' -d @${last[time]}) < $date$time )) if (( $(date '+%Y%m%d%H%M%S' -d "@${last[time]}") < $date$time ))
then then
[[ -r .importing ]] && return 2 lasttime=${now:-$starttime}
touch .importing echo "${file##*/}" > .importing
imagetime="${date:0:4}/${date:4:2}/${date:6:2} ${time:0:2}:${time:2:2}:${time:4:2}" imagetime="${date:0:4}/${date:4:2}/${date:6:2} ${time:0:2}:${time:2:2}:${time:4:2}"
echo "$(date +"%Y/%m/%d:%H:%M:%S") - $file: $imagetime" echo "$(date +"%Y/%m/%d:%H:%M:%S") - $file: $imagetime"
timestamp=$(date +%s -d "$imagetime") timestamp=$(date +%s -d "$imagetime")
image "$file" $timestamp image "$file" $timestamp
now=$(date +%s)
echo $'\tDuration: '$(( now - lasttime ))
fi fi
done done
elapsed=$(( $(date +%s) - starttime )) elapsed=$(( $(date +%s) - starttime ))
echo "$(date +"%Y/%m/%d:%H:%M:%S"): Spent $elapsed seconds" (( count )) && echo "$(date +"%Y/%m/%d:%H:%M:%S"): Spent $elapsed seconds"
rm .importing rm -f .importing
} }

View File

@ -5,14 +5,15 @@ readlast() {
index \ index \
indices \ indices \
lastupdatelines \ lastupdatelines \
time \
values \ values \
last["time"]=0
readarray -t lastupdatelines < <( readarray -t lastupdatelines < <(
rrdtool lastupdate $rrdfile rrdtool lastupdate $rrdfile
) )
indices=( ${lastupdatelines[0]} ) indices=( ${lastupdatelines[0]} )
last["time"]=${lastupdatelines[2]%:*} time=${lastupdatelines[2]%:*}
last["time"]=${time:-0}
values=( ${lastupdatelines[2]#*:} ) values=( ${lastupdatelines[2]#*:} )
for index in ${!indices[@]} for index in ${!indices[@]}
do do

View File

@ -2,9 +2,9 @@
send_headers() { send_headers() {
local timestamp do_exit header thisdate expiredate local timestamp do_exit header thisdate expiredate
read timestamp < <(stat -c %Y $0 settings "$rrdfile" lib/* |sort -r) read timestamp < <(stat -c %Y $0 settings "$rrdfile" lib/* .importing 2>/dev/null|sort -r)
thisdate=$(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d @$timestamp) thisdate=$(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d @$timestamp)
expiredate=$(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d '+1 minute') expiredate=$(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d "+${1:-60} second")
if [[ $thisdate == $HTTP_IF_MODIFIED_SINCE ]] if [[ $thisdate == $HTTP_IF_MODIFIED_SINCE ]]
then then
echo "Status: 304 Not Modified" echo "Status: 304 Not Modified"
@ -12,7 +12,7 @@ send_headers() {
fi fi
echo "Last-Modified: $thisdate" echo "Last-Modified: $thisdate"
echo "Expires: $expiredate" echo "Expires: $expiredate"
echo "Cache-Control: must-revalidate, max-age=60" echo "Cache-Control: must-revalidate, max-age=${1:-60}"
while read header while read header
do do
echo "$header" echo "$header"

View File

@ -8,6 +8,8 @@
# /cgi/$user/add.html # /cgi/$user/add.html
IFS=/ read garbage garbage webuser garbage <<<"$REQUEST_URI" IFS=/ read garbage garbage webuser garbage <<<"$REQUEST_URI"
debug_import=2
rrdfile=ingress.rrd rrdfile=ingress.rrd
graph_width=800 graph_width=800