RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Australian Road Safety API

Australian Road Safety API

One of the projects were currently working on enjoys a working title of the Australian Security Journal. Located at police.com.au , the project is one that we're using as a security shopfront and magazine-style publication. We're of the opinion that any marketing company worth its weight will continue to have a significant portfolio of their own products and websites to demonstrate various concepts and expertise... and the Journal is just one of them. We plan on including as much dynamic information and crime data as possible, and one of those features - however morbid - is a count of deaths resulting from road accidents. This article introduces some of the basic features of the 'Road Safety' API we've built to support research necessary for article content, and data for display on the website.

Data sources described below are checked daily for updates. The API data returned is always sourcing the most up-to-date information.

Fatalities This Year

Data is sourced from The Bureau of Infrastructure, Transport and Regional Economics (BITRE) ... although they only update their database once per month. Heavy vehicle flags are only updated each quarter, and are only current to within two months. The date of crash has been removed, although the year, month and day of week are retained. So, generally speaking, real-time data is unreliable and incomplete but historical data, however incomplete, might be considered to be accurate.

The basic endpoint returns general statistics as follows:

1
Array
2
(
3
    [code] => 200
4
    [status] => 200
5
    [message] => OK
6
    [source] => The Bureau of Infrastructure, Transport and Regional Economics (BITRE)
7
    [data] => Array
8
        (
9
            [last_month_count] => 96
10
            [last_year_count] => 1132
11
            [this_month_last_year] => 88
12
            [this_year_so_far] => 96
13
            [valid] => Array
14
                (
15
                    [year] => 2018
16
                    [month] => January
17
                )
18
 
19
        )
20
 
21
)

Using the shortcode of [bmfatalities] we return the this_year_so_far count as [bmfatalities]. The valid array contains the validity of the data returned (again, the data isn't overly accurate, so the 'real-time' count is usually around a month old).

To show the count as I've demonstrated above, the following shortcode was used:

1
<?php 
2
/*
3
 Australian Road Safety API
4
 https://www.beliefmedia.com.au/road-safety-api
5
*/
6
 
7
function beliefmedia_police_fatalities($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'type' => 'summary',
11
    'apikey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
12
    'p' => 0,
13
    'cache' => 3600 * 24 * 5
14
  ), $atts);
15
 
16
  $transient = 'bmpfa_' . md5(serialize($atts));
17
  $cachedposts = get_transient($transient);
18
 
19
  if ($cachedposts !== false) {
20
   return $cachedposts;
21
 
22
  } else {
23
 
24
    /* Get Police Stats */
25
    $data = @file_get_contents('http://api.beliefmedia.com/police/police.php?type=' . $atts['type'] . '&apikey=' . $atts['apikey']);
26
    if ($data === false) return 'N/A';
27
 
28
    $data = json_decode($data, true);
29
    if ( ($data === false) || (empty($data)) || ($data['code'] != '200') ) return 'N/A';
30
 
31
    /* Data */
32
    $data = $data['data'];
33
 
34
    $return = $data['this_year_so_far'];
35
    if ($p) $return = '' . $return . '';
36
 
37
   /* Set transient chart data */
38
   set_transient($transient, $return, $atts['cache']);
39
   return $return;
40
 }
41
}
42
add_shortcode('bmfatalities', 'beliefmedia_police_fatalities');

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Historical Data

We can return historical data dating back to 1989 with the endpoint of http://api.beliefmedia.com/police/police.php?type=year&apikey=xxxx.

1
Array
2
(
3
    [code] => 200
4
    [status] => 200
5
    [message] => OK
6
    [current_page] => 1
7
    [total_page] => 1
8
    [results] => 30
9
    [source] => The Bureau of Infrastructure, Transport and Regional Economics (BITRE) | Australian Bureau of Statistics
10
    [data] => Array
11
        (
12
            [1989] => Array
13
                (
14
                    [fatal_count] => 2800
15
                    [year] => 1989
16
                    [population] => 16814416
17
                    [fatalities_per_1000] => 16.65
18
                    [fatal_crashes] => 2407
19
                )
20
 
21
            [------ SNIP ------]
22
 
23
            [2016] => Array
24
                (
25
                    [fatal_count] => 1293
26
                    [year] => 2016
27
                    [population] => 24210809
28
                    [fatalities_per_1000] => 5.34
29
                    [fatal_crashes] => 1199
30
                )
31
 
32
            [2017] => Array
33
                (
34
                    [fatal_count] => 1227
35
                    [year] => 2017
36
                    [population] => 24525809
37
                    [fatalities_per_1000] => 5
38
                    [fatal_crashes] => 1132
39
                )
40
 
41
            [2018] => Array
42
                (
43
                    [fatal_count] => 103
44
                    [year] => 2018
45
                    [population] => 24840809
46
                    [fatalities_per_1000] => NA
47
                    [fatal_crashes] => 96
48
                )
49
 
50
        )
51
 
52
)

Population data is sourced and updated as necessary from the Australian Bureau of Statistics. When full year statistics aren't available we use predictive data based on expected population growth. The fatalities_per_1000 value is only available when a full year of data is returned.

Date returned is updated only when required - which isn't very often. For this reason it's worth caching the data with Simple Cache and checking our API only occasionally for updates.

Querying Data

Data can be queried based upon any of the fields available in the source data. While queries may be grouped in a complex manner, the most basic query is described below.

month_start: The full month.
month_end: The full month.
year_start: The lowest year value.
year_end: The higher year value.
state: Query a specific state data.
crash_type:

  • 1- Single vehicle
  • 2 - Multiple vehicles
  • 3 - Pedestrian

bus: Use bus=yes to query only accidents involving buses.
rigid: Indicates involvement of a heavy rigid truck in the crash. Use rigid=yes.
articulate: Indicates involvement of an articulated truck in the crash.
speed_start: The lowest speed value.
speed_end: The higher speed value.
road_user:

  • 1- Driver
  • 2 - Passenger
  • 3 - Pedestrian
  • 4 - Motorcycle rider
  • 5 - Motorcycle pillion passenger
  • 6 - Bicyclist (includes pillion passengers)

gender: To split results, use the following:

  • 1- Male
  • 2 - Female
  • 3 - Unknown

age_start: Lower age limit.
age_end: Upper age limit.

The type attribute should be set to ?type=custom (if not provided we'll return only the basic statistical data). Additional parameters may be used to group results by any attribute, such as state, and this information is available within the client portal. Because of the large datasets returned, most results are paginated.

Considerations

  • An API Key is required. Clients can use their existing lifetime API key to access the information if required (however unlikely).
  • Data is sourced from the The Bureau of Infrastructure, Transport and Regional Economics (BITRE) and the Australian Bureau of Statistics. Where population data is unavailable we'll apply predictive growth rates based on migration numbers (usually around 3%).
  • The same data is returned for crashes (rather than fatalities). This information is returned via the crash endpoint and includes the age and sex of each individual.
  • If interested, we'll likely build a search and graphing feature on the ASJ website .
  • The API is new. If you encounter issues, errors, or you have any feature requests, please let us know.
  • There's about a dozen other databases we'll make available via an API. Subscribe to our mailing list or like us on Facebook to keep informed of changes.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment