Title: | Retrieval and Visualization of Mobility Data from 'Telraam' Sensors |
---|---|
Description: | Streamline the processing of 'Telraam' data, sourced from open data mobility sensors. These tools range from data retrieval (without the need for API knowledge) to data visualization, including data preprocessing. |
Authors: | Lilou Augeray [aut], Ulysse Caromel [aut], Ketsia Guichard [aut, cre] , Pascal Irz [aut] , Mijin Park [aut], Tanguy Richard [aut], Agis-ta-terre [cph, fnd] |
Maintainer: | Ketsia Guichard <[email protected]> |
License: | file LICENSE |
Version: | 1.1.1 |
Built: | 2024-11-24 04:56:43 UTC |
Source: | https://github.com/ketsiaguichard/telraamstats |
If you want to specify the IDs of your own sensors,
this function create a local configuration template file
in the \inst
directory, to edit with specific information.
By default, the function doesn't create the file in the project directory
but in a temp directory. If you want to have a permanent configuration,
please use .
create_config( segments = list(`segment-01` = "9000000000", `segment-02` = "9000000000"), create_directory = FALSE, overwrite = FALSE )
create_config( segments = list(`segment-01` = "9000000000", `segment-02` = "9000000000"), create_directory = FALSE, overwrite = FALSE )
segments |
Named List of segments ("name1" = "9000000000", ...). Default to the example version. |
create_directory |
Boolean: Does the file need to be created in the project directory? Default to FALSE. |
overwrite |
Boolean: if the file exist, should it be overwriten? Default to FALSE. |
If you use the temporary options, please fill directly the name and number of your sensors in the "segments" argument.
Boolean: TRUE if the file is created, FALSE overwise (config already exists for example).
create_config(create_directory=FALSE) list_of_segments = list("Burel"= "9000002156", "Vitre" = "9000001844") create_config(segments = list_of_segments, create_directory = FALSE, overwrite = TRUE) # the file already exists
create_config(create_directory=FALSE) list_of_segments = list("Burel"= "9000002156", "Vitre" = "9000001844") create_config(segments = list_of_segments, create_directory = FALSE, overwrite = TRUE) # the file already exists
Return the state of the 'Telraam' API. Determine if updates can be made.
get_api_state(key = get_telraam_token())
get_api_state(key = get_telraam_token())
key |
the API key (set by the set_telraam_token function - default -, or directly filled). |
Boolean: TRUE if the API responds well, FALSE otherwise.
my_token <- 'ThisIsNotAValidToken' get_api_state(my_token)
my_token <- 'ThisIsNotAValidToken' get_api_state(my_token)
Get the current authentication token for the 'Telraam' API
get_telraam_token()
get_telraam_token()
Token currently used, set by set_telraam_token()
my_token <- "MyTelraamToken" set_telraam_token(my_token) get_telraam_token()
my_token <- "MyTelraamToken" set_telraam_token(my_token) get_telraam_token()
Higher is the uptime average, higher is the quality of data. A null uptime means that the sensor wasn't available during this period.
gg_availability(enriched_data, date_range = NULL)
gg_availability(enriched_data, date_range = NULL)
enriched_data |
enriched data.frame containing all the data for all your sensors |
date_range |
Date vector. Example: c('2021-01-01','2022-01-01'). Full period if NULL. |
Graph showing availability and quality of sensors over the selected date range.
gg_availability(traffic)
gg_availability(traffic)
Histogram of car speed over a period, for a segment or a subset of segment.
gg_car_speed_histogram( enriched_data, date_range = NULL, segments = NULL, weekday = NULL, hours = NULL, aggregated_by = NULL )
gg_car_speed_histogram( enriched_data, date_range = NULL, segments = NULL, weekday = NULL, hours = NULL, aggregated_by = NULL )
enriched_data |
enriched data.frame containing all the data for all your sensors |
date_range |
Date vector. Example: c('2021-01-01','2022-01-01'). Full period if NULL (default). |
segments |
Character vector. Selected road segment, all if NULL (default). |
weekday |
Character vector. Weekday choosen. Default to the all week. |
hours |
Integer vector. Hours choosen, default to the all day. |
aggregated_by |
Character. Enables comparison with other segments or weekdays. Options are : 'segment_name', 'weekday', NULL (no comparison, default). |
Graph showing histogram of car speed over a period.
library(dplyr) subset_traffic <- traffic %>% filter(day < '2022-02-01', hour > 9) gg_car_speed_histogram(subset_traffic) gg_car_speed_histogram(subset_traffic, aggregated_by = 'segment_name') gg_car_speed_histogram(subset_traffic, weekday = c('monday','sunday'), segments = 'RteVitre-06', hours = 17:20, aggregated_by = "weekday")
library(dplyr) subset_traffic <- traffic %>% filter(day < '2022-02-01', hour > 9) gg_car_speed_histogram(subset_traffic) gg_car_speed_histogram(subset_traffic, aggregated_by = 'segment_name') gg_car_speed_histogram(subset_traffic, weekday = c('monday','sunday'), segments = 'RteVitre-06', hours = 17:20, aggregated_by = "weekday")
v85 is the estimated car speed limit in km/h that 85% of all cars respect. 15% of drivers drive faster than this v85 indicator.
gg_car_speed_v85( enriched_data, date_range = NULL, segments = NULL, weekday = NULL, hours = NULL, aggregated_by = NULL )
gg_car_speed_v85( enriched_data, date_range = NULL, segments = NULL, weekday = NULL, hours = NULL, aggregated_by = NULL )
enriched_data |
enriched data.frame containing all the data for all your sensors |
date_range |
Date vector. Example: c('2021-01-01','2022-01-01'). Full period if NULL (default). |
segments |
Character vector. Selected road segment, all if NULL (default). |
weekday |
Character vector. Weekday choosen. Default to the all week. |
hours |
Integer vector. Hours choosen, default to the all day. |
aggregated_by |
Character. Enables comparison with other segments or weekdays. Options are : 'segment_name', 'weekday', NULL (no comparison, default). |
Graph showing the average of v85 speed per hour.
library(dplyr) subset_traffic <- traffic %>% filter(day < '2022-02-01', hour > 9) gg_car_speed_histogram(subset_traffic[0:100,]) gg_car_speed_histogram(subset_traffic, aggregated_by = 'segment_name') gg_car_speed_histogram(subset_traffic, weekday = c('monday','sunday'), segments = 'RteVitre-06', hours = 17:20, aggregated_by = "weekday")
library(dplyr) subset_traffic <- traffic %>% filter(day < '2022-02-01', hour > 9) gg_car_speed_histogram(subset_traffic[0:100,]) gg_car_speed_histogram(subset_traffic, aggregated_by = 'segment_name') gg_car_speed_histogram(subset_traffic, weekday = c('monday','sunday'), segments = 'RteVitre-06', hours = 17:20, aggregated_by = "weekday")
A short description... Average of traffic during a week, over a period for a segment or a subset of segment, for a transportation mode or more, for a direction or both.
gg_traffic_avg( enriched_data, date_range = NULL, segments = NULL, modes = c("heavy", "car"), direction = "both", weekday = NULL, aggregated_by = "weekday" )
gg_traffic_avg( enriched_data, date_range = NULL, segments = NULL, modes = c("heavy", "car"), direction = "both", weekday = NULL, aggregated_by = "weekday" )
enriched_data |
enriched data.frame containing all the data for all your sensors |
date_range |
Date vector. example: c('2021-01-01','2022-01-01'). Full period if NULL (default). |
segments |
Character vector. Selected road segment, all if NULL (default). |
modes |
Character vector. Different modes of transportation aggregated (heavy, car, bike, pedestrian) . Default: heavy & car |
direction |
Character. Direction of the traffic (lft, rgt, both). Default to both. |
weekday |
Character vector. Weekday choosen. Default to the all week. |
aggregated_by |
Character. Options are: 'segment_name', 'weekday', 'direction', 'mode'. Default: 'weekday'. |
Graph showing weekly average evolution of traffic (for specified parameters) during the specified period.
gg_traffic_avg(traffic) gg_traffic_avg(traffic, date_range = c('2022-07-01','2022-09-01'), segment = 'RteVitre-06', mode = 'car', direction = 'rgt', weekday = c('monday','friday') )
gg_traffic_avg(traffic) gg_traffic_avg(traffic, date_range = c('2022-07-01','2022-09-01'), segment = 'RteVitre-06', mode = 'car', direction = 'rgt', weekday = c('monday','friday') )
Evolution of traffic (global, per mode ou per direction), smoothed traffic during a period.
gg_traffic_evolution( enriched_data, date_range = NULL, segments = NULL, modes = c("heavy", "car"), direction = "both", smoothed = TRUE, agg_day = TRUE )
gg_traffic_evolution( enriched_data, date_range = NULL, segments = NULL, modes = c("heavy", "car"), direction = "both", smoothed = TRUE, agg_day = TRUE )
enriched_data |
enriched data.frame containing all the data for all your sensors |
date_range |
Date vector. Example: c('2021-01-01','2022-01-01'). Full period if NULL (default). |
segments |
Character vector. Selected road segment by its name, all if NULL (default). |
modes |
Character vector. Different modes of transportation aggregated (heavy, car, bike, pedestrian) . Default: heavy & car |
direction |
Character. Direction of the traffic (lft, rgt, both). Default to both. |
smoothed |
Boolean. Should the smoothed traffic be plotted ? Default: True |
agg_day |
Boolean. Should the data be aggregated per day ? Default : True |
Graph showing the evolution of traffic (for specified parameters) during the specified period.
gg_traffic_evolution(traffic) gg_traffic_evolution(traffic, date_range = c('2022-01-01','2022-03-01'), segment = 'RteVitre-06', mode = c('car','pedestrian'), direction = 'lft', smoothed = FALSE, agg_day = FALSE)
gg_traffic_evolution(traffic) gg_traffic_evolution(traffic, date_range = c('2022-01-01','2022-03-01'), segment = 'RteVitre-06', mode = c('car','pedestrian'), direction = 'lft', smoothed = FALSE, agg_day = FALSE)
Imports data associated with a given list of sensor names from .RData files contained in a data directory. The main purpose of this function is to load the data saved with write update data.
import_sensor(list_sensor)
import_sensor(list_sensor)
list_sensor |
A character vector specifying the names of sensors to import data for. |
A dataframe containing the imported data.
## Not run: # This example requires a valid API key period <- as.Date(c('2022-01-01', '2022-12-31')) write_update_data('RteVitre-06', period[1], period[2]) write_update_data('ParisArcEnCiel-05', period[1], period[2]) import_sensor(c('RteVitre-06', 'ParisArcEnCiel-05')) ## End(Not run)
## Not run: # This example requires a valid API key period <- as.Date(c('2022-01-01', '2022-12-31')) write_update_data('RteVitre-06', period[1], period[2]) write_update_data('ParisArcEnCiel-05', period[1], period[2]) import_sensor(c('RteVitre-06', 'ParisArcEnCiel-05')) ## End(Not run)
Retrieves data associated with a sensor from the Telraam API.
The data is retrieved for a specified time period between start_date
and end_date
(inclusive).
retrieve_sensor(segment_name, start_date, end_date, key = get_telraam_token())
retrieve_sensor(segment_name, start_date, end_date, key = get_telraam_token())
segment_name |
Character. Name of the segment, as specified in config. |
start_date |
Date. Start date "aaaa-mm-jj", must be of the date type. |
end_date |
Date. End date "aaaa-mm-jj", must be of the date type. |
key |
the API key (set by the |
Dataframe from Telraam API, enriched with enrich_traffic()
function.
## Not run: # This function requires a valid API key period <- as.Date(c('2022-01-01', '2022-12-31')) retrieve_sensor('RteVitre-06', period[1], period[2]) ## End(Not run)
## Not run: # This function requires a valid API key period <- as.Date(c('2022-01-01', '2022-12-31')) retrieve_sensor('RteVitre-06', period[1], period[2]) ## End(Not run)
If you want to get this token after this instruction, please use get_telraam_token()
.
set_telraam_token(token)
set_telraam_token(token)
token |
a |
Boolean: TRUE if the token is correctly set
my_token <- "MyTelraamToken" set_telraam_token(my_token) get_telraam_token()
my_token <- "MyTelraamToken" set_telraam_token(my_token) get_telraam_token()
Telraam sensors continously monitor a street form a citizen window. They count heavy vehicules, cars, twok-wheelers and pedestrians, every hour. Châteaubourg is one of the city in France with the highest density of sensors This dataframe is a subset of sensors data in Châteaubourg for 2022. Additional properties are not present natively in the Telraam API but are added by the package.
traffic
traffic
traffic
A data frame with 16,729 rows and 22 columns:
Sensor number. Equals -1 if the API request was made for a road segment and not for a camera.
Road segment Telraam ID. Equals -1 if the API request was made for a camera and not for a road segment.
Additional property - Segment name specified in configuration file.
Additional property - Concatenation of the segment_id and the segment name specified in configuration.
date and UTC time of the reporting interval (beginning of the interval).
Additional property - Day of the reporting interval.
Additional property - Hour of the reporting interval.
Additional property - Weekday of the reporting interval.
Additional property - boolean, indicates whether this entry is during a French public holiday.
Indicates whether this entry is during a French vacation period, and if true, the vacation period name.
can be "hourly" or "daily" for hourly or daily aggregate data.
between 0 and 1, represents the portion of the reporting interval that was actively spent counting the traffic
Additional property - boolean, indicates whether this entry has an uptime greather or equal than 0.
number of heavy vehicles, total and in both directions.
number of cars, total and in both directions.
number of two-wheelers, total and in both directions.
number of pedestrians, total and in both directions.
1, internal consistency value for Telraam.
the estimated car speed distribution in 10 km/h bins from 0 to 70+ km/h or 120+ km/h (in percentage of the total 100%).
name of the Time zone where the segment can be found.
estimated car speed limit in km/h that 85% of all cars respect
Writes or updates the sensor data in the data folder.
It retrieves the data for the specified sensor between start_date
and end_date
(inclusive) using the retrieve_sensor
function,
and then converts certain columns to character strings before writing the data
to a RData file in the data
folder (if create_directory = TRUE
),
to a temporary folder otherwise.
write_update_data(segment_name, start_date, end_date, create_directory = FALSE)
write_update_data(segment_name, start_date, end_date, create_directory = FALSE)
segment_name |
Character. Name of the segment, as specified in config. |
start_date |
Date. Start date "aaaa-mm-jj" |
end_date |
Date. End date "aaaa-mm-jj" |
create_directory |
Boolean: Does the file need to be created in the project directory? Default to FALSE. |
Boolean: TRUE if the data is well saved/written, FALSE otherwise (no data for example)
## Not run: # This function requires a valid API key period <- as.Date(c('2022-01-01', '2022-12-31')) write_update_data('RteVitre-06', period[1], period[2]) ## End(Not run)
## Not run: # This function requires a valid API key period <- as.Date(c('2022-01-01', '2022-12-31')) write_update_data('RteVitre-06', period[1], period[2]) ## End(Not run)