Skip to content

How to Generate Speed Camera Graphs

Claude Pageau edited this page Jan 5, 2022 · 36 revisions

Introduction

The python scripts below will read Data from the current sqlite3 speed camera database and generate matplotlib graphs that can be viewed using the webserver.

Note: Make sure enough speed data has been generated to make graphs meaningful for the period of time you are interested in.

Single graphs can be produced using command line parameters per -h parameter. Crontab entries can be used to automate production of a single graph or multiple commands can be put into an executable bash script with a crontab entry. If config.py variable GRAPH_ADD_DATE_TO_FILENAME = True then separate unique date stamped filenames will be generated otherwise if GRAPH_ADD_DATE_TO_FILENAME = False then previous graphs will be overwritten if they exist. Graphs will be save per config.py GRAPH_PATH variable.
or
Multiple graphs can be generated using config.py GRAPH variables when NO command line parameters are provided. Graphs will be generated on a frequency per GRAPH_RUN_TIMER_HOURS variable until ctrl-c is pressed to stop script.

Sample of config.py GRAPH settings

# matplotlib graph image settings
# -------------------------------
GRAPH_PATH = 'media/graphs'  # Directory path for storing graph images
GRAPH_ADD_DATE_TO_FILENAME = False  # True - Prefix graph image filenames with datetime default = False
GRAPH_RUN_TIMER_HOURS = 0.5   # Default= 0.5 Update Graphs every specified hours wait (Continuous).
# List of sql query Data for sql-make-graph-count-totals.py and sql-make-graph-speed-ave.py (with no parameters)
#                [[Group_By, Days_Prev, Speed_Over]]  where Group_By is 'hour', 'day' or 'month'
GRAPH_RUN_LIST = [
                 ['day', 28, 10],
                 ['hour', 28, 10],
                 ['hour', 7, 0],
                 ['hour', 2, 0]
                 ]

You can modify, add or remove GRAPH_RUN_LIST entries to customize graphs generation to your needs. You can also copy a script and modify to customize for displaying other criteria.

This script will query the speed camera sqlite3 database per config.py matplotlib settings or command line parameters. It will generate matplotlib graphs for total counts per specified hour, day, month for a specified number of days previous from present date. Graphs can be viewed in the webserver.

With Command Line Parameters

Run a single graph by passing parameters to this script. For details See

cd ~/speed-camera
./sql-make-graph-count-totals.py -h
./sql-make-graph-count-totals.py -s 0 -d 14 -t hour

matplotlib will then create jpg graph images to auto created filenames.

You can add optional datetime prefix to graph filename by setting config.py boolean variable

GRAPH_ADD_DATE_TO_FILENAME = True

Default is False (overwrites previous existing filenames) Graph will show record count totals for specified speeds over and days previous totaled by log_timestamp Grouping eg hour, day, month.

Without Command Line Parameters

If NO command line parameters are supplied then multiple graphs can be created per the speed camera config.py GRAPH_RUN_DATA list variable. This can generate multiple graph image files per specified list data criteria. See config.py comments for required GRAPH_RUN_DATA list values.

cd ~/speed-camera
./sql-make-graph-count-totals.py

This will run continuously per config.py GRAPH_RUN_TIMER_HOURS variable (default is 0.5 hours or 30 minutes). press ctrl-c to quit graph generation.

NOTE:
Edit config.py file to Change/Add/Remove Graphs per GRAPH_RUN_LIST variable under config.py matplotlib GRAPH variable settings. Graph Images can be viewed from Speed Camera Webserver.

This script will query the speed camera sqlite3 database per config.py settings or command line parameters. Graphs will display a summary of average speeds over specified speed totaled by hour, day or month for the specified number of previous days from now. It will then generate matplotlib graph images per command line parameter or config.py GRAPH_ variables and grouping values. Graphs can be viewed in the webserver.

With Command Line parameters

Selects Records per

-s speed over
-d days previous and groups counts by  
-t totals eg hour, day, month

matplotlib will then create jpg graph images to auto created filenames. You can add optional datetime prefix by setting config.py GRAPH_ADD_DATE_TO_FILENAME boolean variable. Default is False (overwrites previous existing filenames) Graph will show record count totals for specified speeds over and days previous totaled by log_timestamp Grouping eg hour, day, month.

Without Command Line Parameters

If NO command line parameters are supplied then multiple graphs can be created per the speed camera config.py GRAPH_RUN_DATA list variable. This can generate multiple graph image files per specified list data criteria. See config.py comments for required GRAPH_RUN_DATA list values.

NOTE:
Run a single graph by passing parameters to this script. For details See

./sql-make-graph-speed-ave.py -h

or Create Multiple Graphs from config.py
To Edit/Add/Remove Graph Images.

Edit config.py GRAPH_RUN_LIST variable under matplotlib settings. Graph Images can be viewed from Speed Camera WebPage

This python script will query the speed camera sqlite3 database and Generate html formatted reports with links to images. The output will be saved to media/reports folder. This script Can accept parameters or will prompt user if run from console with no parameters