diff --git a/DESCRIPTION b/DESCRIPTION
index 3cbe5ec..bcf9375 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -14,10 +14,15 @@ Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Imports:
+ archive,
+ cli,
data.table,
dplyr,
httr2,
jsonlite,
+ lubridate,
sf,
- stringr
+ stringr,
+ tibble,
+ tidyr
URL: https://samherniman.github.io/autocruller/
diff --git a/NAMESPACE b/NAMESPACE
index e2f1e39..69f326d 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,3 +1,7 @@
# Generated by roxygen2: do not edit by hand
export(ac_get_co2)
+export(ac_get_co2_download)
+export(ac_get_co2_transit)
+export(ac_get_co2_web)
+export(ac_unnest_longer)
diff --git a/R/ac_get_co2.R b/R/ac_get_co2.R
index 0cc9d05..aedf1c4 100644
--- a/R/ac_get_co2.R
+++ b/R/ac_get_co2.R
@@ -1,44 +1,43 @@
#' Get data from indoorco2map.org
+#'
+#' @param x Character specifying which dataset to download one of c("web", "download", "transit")
#'
#' @returns A dataframe with up to date co2 measurements
#' @export
#'
#' @examples
#' \dontrun{
+#' # Get building data with one of three options
#' ac_df <- ac_get_co2()
+#' ac_df <- ac_get_co2("web")
+#' ac_df <- ac_get_co2("download")
+#'
+#' # Get transit data
+#' ac_df <- ac_get_co2("transit")
#' }
#'
-ac_get_co2 <- function() {
- measurements <- .id <- startTime <- NULL
+ac_get_co2 <- function(x = "web") {
- icm_response <-
- httr2::request("https://indoorco2map.com/chartdata/IndoorCO2MapData.json.gz") |>
- httr2::req_perform() |>
- httr2::resp_body_json()
+ if (!(x %in% c("web", "download", "transit"))) {
+ cli::cli_abort(c(
+ "Error while getting co2 data:",
+ "x must be either \"web\", \"download\", or \"transit\"",
+ "if you want building data, set x to \"web\"",
+ "if you want transit data, set x to \"transit\""
+ ))
+ }
+
+ if (x == "web") {
+ return(ac_get_co2_web())
+ }
- icm_response <-
- data.table::rbindlist(icm_response, idcol = TRUE) |>
- suppressWarnings()
+ if (x == "download") {
+ return(ac_get_co2_download())
+ }
- j_lst <- lapply(icm_response$measurements, jsonlite::fromJSON)
- j_lst <- lapply(j_lst, co2_to_numeric)
- j_lst <- data.table::rbindlist(j_lst, idcol = TRUE)
-
- ac_df <- icm_response |>
- dplyr::select(-measurements) |>
- dplyr::left_join(j_lst, by = dplyr::join_by(.id)) |>
- dplyr::mutate(
- # remove the last few digits from the unix time because they are in milliseconds and not needed
- date = stringr::str_sub(startTime, end = -4) |>
- as.numeric() |>
- as.POSIXct()
- ) |>
- sf::st_as_sf(
- coords = c("lon", "lat"),
- crs = sf::st_crs(4326)
- )
-
- return(ac_df)
+ if (x == "transit") {
+ return(ac_get_co2_transit())
+ }
}
#' Convert the co2 character array to a numeric list
diff --git a/R/ac_get_co2_download.R b/R/ac_get_co2_download.R
new file mode 100644
index 0000000..31018ee
--- /dev/null
+++ b/R/ac_get_co2_download.R
@@ -0,0 +1,39 @@
+
+#' Get data from indoorco2map.org - "download version"
+#'
+#' @returns A dataframe with co2 building measurements
+#'
+#' @details
+#' This function will download the version of building
+#' data that is available using the "download" button on
+#' the website
+#'
+#'
+#' @export
+#' @examples
+#'
+#' \dontrun{
+#' ac_df <- ac_get_co2_download()
+#' }
+ac_get_co2_download <- function() {
+ co2readingsAvg <- startOfMeasurement <- NULL
+ icm_response <-
+ archive::archive_extract(
+ "https://indoorco2map.com/chartdata/IndoorCO2MapData.zip",
+ files = 3
+ ) |>
+ jsonlite::fromJSON() |>
+ tibble::rowid_to_column("obs_number") |>
+ dplyr::mutate(
+ date = lubridate::as_datetime(startOfMeasurement),
+ day = lubridate::date(date)
+ ) |>
+ sf::st_as_sf(
+ coords = c("longitude", "latitude"),
+ crs = sf::st_crs(4326)
+ )
+ unlink('indoorco2mapData.json')
+
+ return(icm_response)
+}
+
diff --git a/R/ac_get_co2_transit.R b/R/ac_get_co2_transit.R
new file mode 100644
index 0000000..f06145b
--- /dev/null
+++ b/R/ac_get_co2_transit.R
@@ -0,0 +1,93 @@
+#' Get transit data from indoorco2map.org
+#'
+#' @returns A dataframe with up to date co2 transit measurements
+#'
+#' @export
+#' @examples
+#' \dontrun{
+#' ac_df <- ac_get_co2_transit()
+#' }
+ac_get_co2_transit <- function() {
+ icm_response <-
+ httr2::request("https://rkhby3mvq3.execute-api.eu-central-1.amazonaws.com/GetTransportCO2Data") |>
+ httr2::req_perform() |>
+ httr2::resp_body_json() |>
+ unlist() |>
+ lapply(jsonlite::fromJSON)
+
+ j_df <- do.call(rbind, icm_response) |>
+ tibble::rowid_to_column("uid")
+
+ j_df <- lapply(1:nrow(j_df), \(x) json_to_df(j_df[x,]))
+ j_df <-
+ do.call(rbind, j_df) |>
+ sf::st_as_sf(
+ coords = c("long_first", "lat_first"),
+ crs = sf::st_crs(4326)
+ ) |>
+ sf::st_make_valid()
+
+ return(j_df)
+}
+
+#' Turn a co2 json into a dataframe
+#'
+#' @param x A json
+#'
+#' @returns a dataframe
+json_to_df <- function(x) {
+ timestampArray <-
+ co2Array <-
+ longitudeArray <-
+ latitudeArray <-
+ startTime <-
+ uid <-
+ ppmAvg <-
+ NULL
+ x |>
+ dplyr::mutate(
+ timestampArray = split_to_numeric(timestampArray) |> range01() |> paste(collapse = ";"),
+ # mod_loess = list(train_loess(co2_vec = co2Array, time_vec = timestampArray)),
+ co2Array = stringr::str_replace_all(co2Array, ";", ","),
+ longitudeArray = stringr::str_remove_all(longitudeArray, "(0;|0$)") |>
+ stringr::str_replace_all(",", "\\.") |>
+ stringr::str_replace_all(";", ","),
+ latitudeArray = stringr::str_remove_all(latitudeArray, "(0;|0$)") |>
+ stringr::str_replace_all(",", "\\.") |>
+ stringr::str_replace_all(";", ","),
+ date = stringr::str_sub(startTime, end = -4) |>
+ as.numeric() |>
+ as.POSIXct()
+ ) |>
+ tidyr::separate_longer_delim(cols = c(co2Array), delim = ",") |>
+ dplyr::distinct() |>
+ dplyr::mutate(
+ long_first = stringr::str_split_i(longitudeArray, ",", 1) |> as.numeric(),
+ lat_first = stringr::str_split_i(latitudeArray, ",", 1) |> as.numeric()
+ ) |>
+ # sf::st_as_sf(coords = c("long_first", "lat_first"), crs = sf::st_crs(4326)) |>
+ dplyr::group_by(uid) |>
+ tibble::rowid_to_column("tsa") |>
+ dplyr::select(-ppmAvg) |>
+ tidyr::drop_na()
+}
+
+#' Create a vector of values evenly spaced between 0 and 1
+#'
+#' @param x vector of values
+#' @param ... other parameters passed to min() or max()
+#'
+#' @returns vector of values evenly spaced between 0 and 1 the same length as x
+range01 <- function(x, ...){(x - min(x, ...)) / (max(x, ...) - min(x, ...))}
+
+#' Split a string seperated by ";" into numbers
+#'
+#' @param x a string of numbers seperated by ";"
+#'
+#' @returns a numeric vector
+split_to_numeric <- function(x) {
+ x |>
+ strsplit(split = ";") |>
+ unlist() |>
+ as.numeric()
+}
diff --git a/R/ac_get_co2_web.R b/R/ac_get_co2_web.R
new file mode 100644
index 0000000..1561c51
--- /dev/null
+++ b/R/ac_get_co2_web.R
@@ -0,0 +1,64 @@
+#' Get data from indoorco2map.org
+#'
+#' @returns A dataframe with up to date co2 measurements - "web version"
+#' @export
+#'
+#' @details
+#' This function will download the version of building
+#' data that is displayed on the website map
+#'
+#'
+#' @examples
+#' \dontrun{
+#' ac_df <- ac_get_co2_web()
+#' }
+#'
+ac_get_co2_web <- function() {
+ measurements <- .id <- startTime <- obs_number <- co2array <- NULL
+
+ icm_response <-
+ httr2::request("https://indoorco2map.com/chartdata/IndoorCO2MapData.json.gz") |>
+ httr2::req_perform() |>
+ httr2::resp_body_json()
+
+ icm_response <-
+ data.table::rbindlist(icm_response, idcol = "obs_number") |>
+ suppressWarnings()
+
+ j_lst <- lapply(icm_response$measurements, jsonlite::fromJSON)
+ j_lst <- lapply(j_lst, co2_to_numeric)
+ j_lst <- data.table::rbindlist(j_lst, idcol = "obs_number")
+
+ ac_df <- icm_response |>
+ dplyr::select(-measurements) |>
+ dplyr::left_join(j_lst, by = dplyr::join_by(obs_number)) |>
+ dplyr::mutate(
+ # remove the last few digits from the unix time because they are in milliseconds and not needed
+ date = stringr::str_sub(startTime, end = -4) |>
+ as.numeric() |>
+ as.POSIXct()
+ ) |>
+ dplyr::select(-co2array) |>
+ sf::st_as_sf(
+ coords = c("lon", "lat"),
+ crs = sf::st_crs(4326)
+ )
+
+ return(ac_df)
+}
+
+#' Convert the co2 character array to a numeric list
+#'
+#' @param x a list containing measurements from json
+#'
+#' @returns list of co2 records
+#'
+co2_to_numeric <- function(x) {
+ x$co2readings <-
+ x$co2array |>
+ stringr::str_split(";", simplify = TRUE) |>
+ as.numeric() |>
+ list()
+
+ return(x)
+}
diff --git a/R/ac_unnest_longer.R b/R/ac_unnest_longer.R
new file mode 100644
index 0000000..f330cb9
--- /dev/null
+++ b/R/ac_unnest_longer.R
@@ -0,0 +1,27 @@
+#' Unnest a co2 df list-column into rows
+#'
+#' @param x a dataframe from ac_get_co2()
+#'
+#' @returns a dataframe in long format
+#'
+#' @export
+#' @examples
+#' ac_df <- ac_get_co2("download") |>
+#' ac_unnest_longer()
+ac_unnest_longer <- function(x) {
+ co2readings <- obs_number <- offset <- interval <- reading_index <- NULL
+ x_df <- x |> tidyr::unnest_longer(co2readings)
+
+ if (all(c("offset", "interval") %in% names(x))) {
+ x_df <- x_df |>
+ dplyr::group_by(obs_number) |>
+ dplyr::mutate(
+ reading_index = dplyr::row_number(),
+ date_time = lubridate::as_datetime(date) +
+ lubridate::dminutes(offset) +
+ lubridate::dminutes(interval * reading_index)
+ )
+ }
+
+ return(x_df)
+}
\ No newline at end of file
diff --git a/README.Rmd b/README.Rmd
index 4473931..1e6f718 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -58,7 +58,7 @@ Download the latest data with `ac_get_co2()`
```{r getco2}
library(autocruller)
-ac_df <- ac_get_co2()
+ac_df <- ac_get_co2("download")
```
That will give you a dataframe with all the current CO^2^ measurements.
@@ -67,10 +67,10 @@ That will give you a dataframe with all the current CO^2^ measurements.
dplyr::glimpse(ac_df)
```
-If you want the co2arrays to be in long format, you can do this:
+If you want the co2readingss to be in long format, you can do this:
```{r}
-ac_df_long <- tidyr::unnest_longer(ac_df, co2array)
+ac_df_long <- ac_unnest_longer(ac_df)
```
@@ -91,11 +91,11 @@ types_c <- c(
"music", "nightclub", "social_centre", "concert_hall"
)
ac_df |>
- dplyr::filter(osmtag %in% types_c) |>
+ dplyr::filter(osmTag %in% types_c) |>
tidyplot(
- x = ventilation,
- y = ppmavg,
- color = ppmavg
+ x = ventilationSystem,
+ y = co2readingsAvg,
+ color = co2readingsAvg
) |>
add_data_points_beeswarm(size = 3) |>
adjust_y_axis(transform = "log2") |>
@@ -112,14 +112,11 @@ And track things over time with the long format data
```{r}
ac_df_long |>
- dplyr::filter(.id == 127) |>
- dplyr::mutate(
- measurement_sequence = dplyr::row_number()
- ) |>
+ dplyr::filter(obs_number == 458) |>
tidyplot(
- x = measurement_sequence,
- y = co2array,
- color = co2array
+ x = reading_index,
+ y = co2readings,
+ color = co2readings
) |>
add_data_points() |>
adjust_size(width = NA, height = NA, unit = "cm") |>
@@ -127,6 +124,6 @@ ac_df_long |>
adjust_x_axis_title("Time") |>
adjust_y_axis_title("CO2 ppm") |>
remove_legend() |>
- adjust_title("CO2 measurements at recording 127") |>
+ adjust_title("CO2 measurements at recording 458") |>
adjust_caption("Data from indoorCO2map.com")
```
diff --git a/README.md b/README.md
index 3409a38..96c4315 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ Download the latest data with `ac_get_co2()`
``` r
library(autocruller)
-ac_df <- ac_get_co2()
+ac_df <- ac_get_co2("download")
```
That will give you a dataframe with all the current CO2
@@ -67,32 +67,36 @@ measurements.
``` r
dplyr::glimpse(ac_df)
-#> Rows: 10,660
-#> Columns: 18
-#> $ .id 1, 2, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12,…
-#> $ combined_id "n_10000066104", "n_10000660271", "n_10013427033", "n_1…
-#> $ osmtag "supermarket", "fast_food", "supermarket", "greengrocer…
-#> $ osmkey "shop", "amenity", "shop", "shop", "shop", "shop", "sho…
-#> $ countryid "DEU", "USA", "DEU", "DEU", "DEU", "DEU", "DEU", "AUT",…
-#> $ countryname "Germany", "United States of America", "Germany", "Germ…
-#> $ nuts3id "DEA1B", "", "DE712", "DEA2C", "DEA2C", "DEA2C", "DEA2C…
-#> $ nwrname "ALDI Süd", "Naya", "EDEKA Langanki", "Hofladen Schmitz…
-#> $ startTime 1.728744e+12, 1.746378e+12, 1.730192e+12, 1.730131e+12,…
-#> $ ppmavg 1795.4000, 613.8235, 579.3333, 608.6000, 484.6000, 832.…
-#> $ co2array <1623, 1699, 1745, 1805, 1836, 1831, 1854, 1860, 1842,…
-#> $ ventilation "False", "False", "False", "False", "False", "False", "…
-#> $ openwindows "False", "False", "False", "False", "False", "False", "…
-#> $ occupancylevel "undefined", "undefined", "undefined", "undefined", "un…
-#> $ customnotes "", "", "", "", "", "", "", "", "", "", "", "", "", "Ha…
-#> $ co2atlaskey "shop", "dining_drinking", "shop", "other", "other", "o…
-#> $ date 2024-10-12 15:32:07, 2025-05-04 17:55:28, 2024-10-29 0…
-#> $ geometry POINT (6.241554 51.5718), POINT (-73.99597 40.751…
+#> Rows: 11,250
+#> Columns: 22
+#> $ obs_number 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, …
+#> $ nwrtype "n", "n", "n", "w", "n", "n", "n", "w", "n", "w", "…
+#> $ nwrID 4436021034, 386028187, 1706619258, 248962888, 42717…
+#> $ name "Konsum", "Konsum Leipzig", "Konsum", "REWE", "Kons…
+#> $ countryID "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "D…
+#> $ countryName "Germany", "Germany", "Germany", "Germany", "German…
+#> $ nuts3ID "DED51", "DED51", "DED52", "DED51", "DED51", "DED51…
+#> $ nuts3Name "Leipzig, Kreisfreie Stadt", "Leipzig, Kreisfreie S…
+#> $ osmKey "shop", "shop", "shop", "shop", "shop", "amenity", …
+#> $ osmTag "supermarket", "supermarket", "supermarket", "super…
+#> $ brand "Konsum Leipzig", "Konsum Leipzig", "Konsum Leipzig…
+#> $ startOfMeasurement "2024-05-15T17:10:19.811", "2024-05-16T10:27:41.828…
+#> $ windowsOpen "False", "False", "True", "False", "False", "True",…
+#> $ ventilationSystem "True", "True", "True", "True", "True", "False", "T…
+#> $ customNotes "", "", "", "", "", "", "", "", "", "", "offenes kl…
+#> $ co2readings <544, 573, 547, 533, 595, 601>, <680, 672, 640, 66…
+#> $ offset 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
+#> $ interval 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
+#> $ co2readingsAvg 566, 661, 936, 1576, 724, 486, 726, 1475, 534, 1242…
+#> $ date 2024-05-15 17:10:19, 2024-05-16 10:27:41, 2024-05-…
+#> $ day 2024-05-15, 2024-05-16, 2024-05-17, 2024-04-15, 20…
+#> $ geometry POINT (12.36603 51.34016), POINT (12.39733 51…
```
-If you want the co2arrays to be in long format, you can do this:
+If you want the co2readingss to be in long format, you can do this:
``` r
-ac_df_long <- tidyr::unnest_longer(ac_df, co2array)
+ac_df_long <- ac_unnest_longer(ac_df)
```
## Make a graph
@@ -112,11 +116,11 @@ types_c <- c(
"music", "nightclub", "social_centre", "concert_hall"
)
ac_df |>
- dplyr::filter(osmtag %in% types_c) |>
+ dplyr::filter(osmTag %in% types_c) |>
tidyplot(
- x = ventilation,
- y = ppmavg,
- color = ppmavg
+ x = ventilationSystem,
+ y = co2readingsAvg,
+ color = co2readingsAvg
) |>
add_data_points_beeswarm(size = 3) |>
adjust_y_axis(transform = "log2") |>
@@ -135,14 +139,11 @@ And track things over time with the long format data
``` r
ac_df_long |>
- dplyr::filter(.id == 127) |>
- dplyr::mutate(
- measurement_sequence = dplyr::row_number()
- ) |>
+ dplyr::filter(obs_number == 458) |>
tidyplot(
- x = measurement_sequence,
- y = co2array,
- color = co2array
+ x = reading_index,
+ y = co2readings,
+ color = co2readings
) |>
add_data_points() |>
adjust_size(width = NA, height = NA, unit = "cm") |>
@@ -150,7 +151,7 @@ ac_df_long |>
adjust_x_axis_title("Time") |>
adjust_y_axis_title("CO2 ppm") |>
remove_legend() |>
- adjust_title("CO2 measurements at recording 127") |>
+ adjust_title("CO2 measurements at recording 458") |>
adjust_caption("Data from indoorCO2map.com")
```
diff --git a/man/ac_get_co2.Rd b/man/ac_get_co2.Rd
index 528863e..16cdca7 100644
--- a/man/ac_get_co2.Rd
+++ b/man/ac_get_co2.Rd
@@ -4,7 +4,10 @@
\alias{ac_get_co2}
\title{Get data from indoorco2map.org}
\usage{
-ac_get_co2()
+ac_get_co2(x = "web")
+}
+\arguments{
+\item{x}{Character specifying which dataset to download one of c("web", "download", "transit")}
}
\value{
A dataframe with up to date co2 measurements
@@ -14,7 +17,13 @@ Get data from indoorco2map.org
}
\examples{
\dontrun{
+# Get building data with one of three options
ac_df <- ac_get_co2()
+ac_df <- ac_get_co2("web")
+ac_df <- ac_get_co2("download")
+
+# Get transit data
+ac_df <- ac_get_co2("transit")
}
}
diff --git a/man/ac_get_co2_download.Rd b/man/ac_get_co2_download.Rd
new file mode 100644
index 0000000..cbec19e
--- /dev/null
+++ b/man/ac_get_co2_download.Rd
@@ -0,0 +1,25 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ac_get_co2_download.R
+\name{ac_get_co2_download}
+\alias{ac_get_co2_download}
+\title{Get data from indoorco2map.org - "download version"}
+\usage{
+ac_get_co2_download()
+}
+\value{
+A dataframe with co2 building measurements
+}
+\description{
+Get data from indoorco2map.org - "download version"
+}
+\details{
+This function will download the version of building
+data that is available using the "download" button on
+the website
+}
+\examples{
+
+\dontrun{
+ac_df <- ac_get_co2_download()
+}
+}
diff --git a/man/ac_get_co2_transit.Rd b/man/ac_get_co2_transit.Rd
new file mode 100644
index 0000000..cb3ef59
--- /dev/null
+++ b/man/ac_get_co2_transit.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ac_get_co2_transit.R
+\name{ac_get_co2_transit}
+\alias{ac_get_co2_transit}
+\title{Get transit data from indoorco2map.org}
+\usage{
+ac_get_co2_transit()
+}
+\value{
+A dataframe with up to date co2 transit measurements
+}
+\description{
+Get transit data from indoorco2map.org
+}
+\examples{
+\dontrun{
+ac_df <- ac_get_co2_transit()
+}
+}
diff --git a/man/ac_get_co2_web.Rd b/man/ac_get_co2_web.Rd
new file mode 100644
index 0000000..7630d1e
--- /dev/null
+++ b/man/ac_get_co2_web.Rd
@@ -0,0 +1,24 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ac_get_co2_web.R
+\name{ac_get_co2_web}
+\alias{ac_get_co2_web}
+\title{Get data from indoorco2map.org}
+\usage{
+ac_get_co2_web()
+}
+\value{
+A dataframe with up to date co2 measurements - "web version"
+}
+\description{
+Get data from indoorco2map.org
+}
+\details{
+This function will download the version of building
+data that is displayed on the website map
+}
+\examples{
+\dontrun{
+ac_df <- ac_get_co2_web()
+}
+
+}
diff --git a/man/ac_unnest_longer.Rd b/man/ac_unnest_longer.Rd
new file mode 100644
index 0000000..9168907
--- /dev/null
+++ b/man/ac_unnest_longer.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ac_unnest_longer.R
+\name{ac_unnest_longer}
+\alias{ac_unnest_longer}
+\title{Unnest a co2 df list-column into rows}
+\usage{
+ac_unnest_longer(x)
+}
+\arguments{
+\item{x}{a dataframe from ac_get_co2()}
+}
+\value{
+a dataframe in long format
+}
+\description{
+Unnest a co2 df list-column into rows
+}
+\examples{
+ac_df <- ac_get_co2("download") |>
+ac_unnest_longer()
+}
diff --git a/man/co2_to_numeric.Rd b/man/co2_to_numeric.Rd
index 4173182..7bd8718 100644
--- a/man/co2_to_numeric.Rd
+++ b/man/co2_to_numeric.Rd
@@ -1,17 +1,23 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/ac_get_co2.R
+% Please edit documentation in R/ac_get_co2.R, R/ac_get_co2_web.R
\name{co2_to_numeric}
\alias{co2_to_numeric}
\title{Convert the co2 character array to a numeric list}
\usage{
+co2_to_numeric(x)
+
co2_to_numeric(x)
}
\arguments{
\item{x}{a list containing measurements from json}
}
\value{
+list of co2 records
+
list of co2 records
}
\description{
+Convert the co2 character array to a numeric list
+
Convert the co2 character array to a numeric list
}
diff --git a/man/figures/README-unnamed-chunk-4-1.png b/man/figures/README-unnamed-chunk-4-1.png
index de890b5..fc9348f 100644
Binary files a/man/figures/README-unnamed-chunk-4-1.png and b/man/figures/README-unnamed-chunk-4-1.png differ
diff --git a/man/figures/README-unnamed-chunk-5-1.png b/man/figures/README-unnamed-chunk-5-1.png
index 6abae32..df5a2d5 100644
Binary files a/man/figures/README-unnamed-chunk-5-1.png and b/man/figures/README-unnamed-chunk-5-1.png differ
diff --git a/man/json_to_df.Rd b/man/json_to_df.Rd
new file mode 100644
index 0000000..7361063
--- /dev/null
+++ b/man/json_to_df.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ac_get_co2_transit.R
+\name{json_to_df}
+\alias{json_to_df}
+\title{Turn a co2 json into a dataframe}
+\usage{
+json_to_df(x)
+}
+\arguments{
+\item{x}{A json}
+}
+\value{
+a dataframe
+}
+\description{
+Turn a co2 json into a dataframe
+}
diff --git a/man/range01.Rd b/man/range01.Rd
new file mode 100644
index 0000000..b7ee1d9
--- /dev/null
+++ b/man/range01.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ac_get_co2_transit.R
+\name{range01}
+\alias{range01}
+\title{Create a vector of values evenly spaced between 0 and 1}
+\usage{
+range01(x, ...)
+}
+\arguments{
+\item{x}{vector of values}
+
+\item{...}{other parameters passed to min() or max()}
+}
+\value{
+vector of values evenly spaced between 0 and 1 the same length as x
+}
+\description{
+Create a vector of values evenly spaced between 0 and 1
+}
diff --git a/man/split_to_numeric.Rd b/man/split_to_numeric.Rd
new file mode 100644
index 0000000..f3865db
--- /dev/null
+++ b/man/split_to_numeric.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ac_get_co2_transit.R
+\name{split_to_numeric}
+\alias{split_to_numeric}
+\title{Split a string seperated by ";" into numbers}
+\usage{
+split_to_numeric(x)
+}
+\arguments{
+\item{x}{a string of numbers seperated by ";"}
+}
+\value{
+a numeric vector
+}
+\description{
+Split a string seperated by ";" into numbers
+}
diff --git a/tests/testthat/test-ac_get_co2.R b/tests/testthat/test-ac_get_co2.R
index 6d08ba1..546f2a4 100644
--- a/tests/testthat/test-ac_get_co2.R
+++ b/tests/testthat/test-ac_get_co2.R
@@ -1,6 +1,10 @@
-ac_df <- ac_get_co2()
+ac_df_web <- ac_get_co2()
+ac_df_dwn <- ac_get_co2("download")
test_that("ac_get_co2 works", {
- expect_length(ac_df, 18)
- testthat::expect_type(ac_df$co2array[[1]], "double")
+ expect_length(ac_df_web, 18)
+ testthat::expect_type(ac_df_web$co2readings[[1]], "double")
+
+ expect_length(ac_df_dwn, 22)
+ testthat::expect_type(ac_df_dwn$co2readings[[1]], "integer")
})
diff --git a/tests/testthat/test-ac_get_co2_download.R b/tests/testthat/test-ac_get_co2_download.R
new file mode 100644
index 0000000..1052fd1
--- /dev/null
+++ b/tests/testthat/test-ac_get_co2_download.R
@@ -0,0 +1,6 @@
+ac_df <- ac_get_co2_transit()
+
+test_that("ac_get_co2_download works", {
+ expect_length(ac_df, 16)
+ testthat::expect_type(ac_df$co2Array[[1]], "character")
+})
diff --git a/tests/testthat/test-ac_get_co2_transit.R b/tests/testthat/test-ac_get_co2_transit.R
new file mode 100644
index 0000000..8849056
--- /dev/null
+++ b/tests/testthat/test-ac_get_co2_transit.R
@@ -0,0 +1,3 @@
+test_that("multiplication works", {
+ expect_equal(2 * 2, 4)
+})
diff --git a/tests/testthat/test-ac_get_co2_web.R b/tests/testthat/test-ac_get_co2_web.R
new file mode 100644
index 0000000..8173d2c
--- /dev/null
+++ b/tests/testthat/test-ac_get_co2_web.R
@@ -0,0 +1,6 @@
+ac_df <- ac_get_co2_web()
+
+test_that("ac_get_co2_web works", {
+ expect_length(ac_df, 18)
+ testthat::expect_type(ac_df$co2readings[[1]], "double")
+})