pageauc / speed-camera

A Unix, Windows, Raspberry Pi Object Speed Camera using python, opencv, video streaming, motion tracking. Includes a Standalone Web Server Interface, Image Search using opencv template match and a whiptail Admin Menu Interface Includes picam and webcam Plugins for motion track security camera configuration including rclone sync script. watch-app allows remotely controller camera configuration from a remote storage service name. Uses sqlite3 and gnuplot for reporting. Recently added openalpr license plate reader support.
Apache License 2.0
987 stars 173 forks source link

reporting stats on a day by day basis #98

Closed peterb99 closed 3 years ago

peterb99 commented 3 years ago

I've created a simple script to report data on a daily basis , over 35mph and over 40mph in 30mph zone, It assumes speed is in mph. AWK is used to get to the first line to get the top speed and to do the % calculations.

ROOT=/home/pi/speed-camera
mph20=`fgrep mph $ROOT/media/reports/speed_gt20_prev_1days.html | wc -l `
mph35=`fgrep mph $ROOT/media/reports/speed_gt35_prev_1days.html | wc -l `
mph40=`fgrep mph $ROOT/media/reports/speed_gt40_prev_1days.html | wc -l `
# Get max speed recorded for the day
filename="$ROOT/media/reports/speed_gt20_prev_1days.html"
DAY=$(date +%d)
DATE=$(date +%m-%Y)
awk -v mph20=$mph20 -v mph35=$mph35 -v mph40=$mph40 -v day=$DAY -v date=$DATE '
BEGIN { FS="<td>" } 

/mph/    { speed=$3 ; gsub("</td>"," ",speed) ;  
       printf ("%2d-%s: >mph20 %d ; >35mph %d ; %.1f%%; >40mph %d ; %.1f%% ; maximum speed %s\n",day-1,date,mph20,mph35,mph35*100/mph20,mph40,mph40*100/mph20,speed);
       exit;
}
' $filename  >> $ROOT/daily-report.csv

In combination with following crontab entries: 10 0 /home/pi/speed-camera/sql_speed_gt.py 20 1 12 0 /home/pi/speed-camera/sql_speed_gt.py 35 1 14 0 /home/pi/speed-camera/sql_speed_gt.py 40 1 16 0 /home/pi/speed-camera/daily_stat.sh

Also added newline write statement to create a single line per report entry in the html page in sql_speed_gt.py This for the wc -l to work. lines around 183

f.write(HTML_HEADER_1)
    f.write("\n")
    f.write(HTML_HEADER_2)
    f.write("\n")
    f.write(HTML_HEADER_3)
    f.write("\n")
    for item in html_table:
        f.write(item)
        f.write("\n")
    f.write(HTML_FOOTER)
    f.write("\n")