dimfalk / netatmo.weather

R wrapper for Netatmo Weather API
GNU General Public License v3.0
3 stars 0 forks source link

`get_measure()`: allow to query longer periods exceeding 1024 values #61

Closed dimfalk closed 7 months ago

dimfalk commented 7 months ago
library(netatmo.weather)
#> 0.5.3

# set_credentials()
# fetch_token()

e <- get_extent("Dresden")

stations <- get_publicdata(e)

# define period exceeding allowed maximum
p <- get_period(c("2024-01-01", "2024-01-15"))
#> Warning:
#> In get_period(c("2024-01-01", "2024-01-15")) :
#>   Based on the defined period '2024-01-01/2024-01-15' and the chosen resolution '5 min',
#>   you are trying to access 4032 values. Allowed maximum is 1024. The result may be incomplete.

as.POSIXct(p, origin = "1970-01-01")
#> "2024-01-01 CET" "2024-01-15 CET"

# try to get observations for a single station 
obs <- get_measure(devices = stations[1, ], 
                   period = p, 
                   par = "temperature", 
                   res = 5)

# check xts index range
zoo::index(obs[[1]]) |> range()
#> "2024-01-01 00:00:00 CET" "2024-01-04 15:25:00 CET"

# check xts attributes
attr(obs[[1]], "TS_START")
#> "2024-01-01 CET"

attr(obs[[1]], "TS_END")
#> "2024-01-04 15:25:00 CET"
dimfalk commented 7 months ago
library(netatmo.weather)
#> 0.5.4

# set_credentials()
# fetch_token()

e <- get_extent("Dresden")

stations <- get_publicdata(e)

# define period exceeding allowed maximum
p <- get_period(c("2024-01-01", "2024-01-15"))

as.POSIXct(p, origin = "1970-01-01")
#> "2024-01-01 CET" "2024-01-15 CET"

# try to get observations for a single station 
obs <- get_measure(devices = stations[1, ], 
                   period = p, 
                   par = "temperature", 
                   res = 5)

# check xts index range
zoo::index(obs[[1]]) |> range()
#> "2024-01-01 00:00:00 CET" "2024-01-14 23:55:00 CET"

# check xts attributes
attr(obs[[1]], "TS_START")
#> "2024-01-01 CET"

attr(obs[[1]], "TS_END")
#> "2024-01-14 23:55:00 CET"