Compare commits
No commits in common. "b09eb2c473da0e72870f1558c3bd14198f0d37ba" and "1631c7aa20a9e7fba173e98365a7c113cdd32967" have entirely different histories.
b09eb2c473
...
1631c7aa20
10 changed files with 65 additions and 2402 deletions
|
|
@ -1,57 +0,0 @@
|
||||||
combine_station_payloads <- function(station_payloads, station_lookup) {
|
|
||||||
station_payloads <- Filter(function(x) !is.null(x) && nrow(x), station_payloads)
|
|
||||||
if (!length(station_payloads)) {
|
|
||||||
return(NULL)
|
|
||||||
}
|
|
||||||
|
|
||||||
combined <- do.call("rbind.data.frame", station_payloads)
|
|
||||||
station_column <- c("POSTE", "geo_id_insee")
|
|
||||||
station_column <- station_column[station_column %in% names(combined)][1]
|
|
||||||
|
|
||||||
if (is.na(station_column)) {
|
|
||||||
return(combined)
|
|
||||||
}
|
|
||||||
|
|
||||||
combined$Nom_usuel <- unname(station_lookup[as.character(combined[[station_column]])])
|
|
||||||
combined
|
|
||||||
}
|
|
||||||
|
|
||||||
# Define function
|
|
||||||
getAllFromCoord <- function(coord, start_date, end_date, allstations, N = 3, headers, base = "https://public-api.meteofrance.fr",btw_station_sleep = 1, within_statio_sleep=5,endpoint="public/DPClim/v1/") {
|
|
||||||
three_station = getIdFromCoords(coord, allstations, N = N)
|
|
||||||
alldata = lapply(three_station$Id_station, function(statid) {
|
|
||||||
print(paste("recuperer station", statid))
|
|
||||||
allstat = tryCatch(
|
|
||||||
getStationData(start_date = start_date, end_date = end_date, station_id = statid, headers = headers, base = base, timesleep=within_statio_sleep,dpclim=endpoint),
|
|
||||||
error = function(e) {print(e); NULL}
|
|
||||||
)
|
|
||||||
print(paste("done, sleep",btw_station_sleep,"sec"))
|
|
||||||
print(dim(allstat))
|
|
||||||
Sys.sleep(btw_station_sleep)
|
|
||||||
return(allstat)
|
|
||||||
})
|
|
||||||
|
|
||||||
ids = three_station$Nom_usuel
|
|
||||||
names(ids) = three_station$Id_station
|
|
||||||
combine_station_payloads(alldata, ids)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Define function
|
|
||||||
getAllFromCoordDPObs <- function(coord, start_date, end_date, allstations, N = 3, headers, base = "https://public-api.meteofrance.fr",btw_station_sleep = 1, within_statio_sleep=5,endpoint="public/DPClim/v1/") {
|
|
||||||
three_station = getIdFromCoords(coord, allstations, N = N)
|
|
||||||
alldata = lapply(three_station$Id_station, function(statid) {
|
|
||||||
print(paste("recuperer station", statid))
|
|
||||||
allstat = tryCatch(
|
|
||||||
getStationDataDPObs(start_date = start_date, end_date = end_date, station_id = statid, headers = headers, base = base, timesleep=within_statio_sleep,dpclim=endpoint),
|
|
||||||
error = function(e) {print(e); NULL}
|
|
||||||
)
|
|
||||||
print(paste("done, sleep",btw_station_sleep,"sec"))
|
|
||||||
print(dim(allstat))
|
|
||||||
Sys.sleep(btw_station_sleep)
|
|
||||||
return(allstat)
|
|
||||||
})
|
|
||||||
|
|
||||||
ids = three_station$Nom_usuel
|
|
||||||
names(ids) = three_station$Id_station
|
|
||||||
combine_station_payloads(alldata, ids)
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
getStationData <- function(start_date, end_date, station_id,headers ,dpclim = "public/DPClim/v1/",timesleep=5,base="https://public-api.meteofrance.fr") {
|
getStationData <- function(start_date, end_date, station_id,headers ,dpclim = "public/DPClim/v1/",timesleep=5,base="https://public-api.meteofrance.fr") {
|
||||||
start_date <- as.Date(start_date)
|
start_date <- as.Date(start_date)
|
||||||
end_date <- as.Date(end_date)
|
end_date <- as.Date(end_date)
|
||||||
url <- httr::modify_url(base,path = paste0(dpclim,"commande-station/infrahoraire-6m"))
|
url <- modify_url(base,path = paste0(dpclim,"commande-station/infrahoraire-6m"))
|
||||||
# Format dates in ISO8601 format
|
# Format dates in ISO8601 format
|
||||||
formatted_start_date <- format(start_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
formatted_start_date <- format(start_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
||||||
formatted_end_date <- format(end_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
formatted_end_date <- format(end_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
||||||
|
|
@ -9,34 +9,31 @@ getStationData <- function(start_date, end_date, station_id,headers ,dpclim = "p
|
||||||
parameters <- list("id-station" = station_id, "date-deb-periode" = formatted_start_date, "date-fin-periode" = formatted_end_date)
|
parameters <- list("id-station" = station_id, "date-deb-periode" = formatted_start_date, "date-fin-periode" = formatted_end_date)
|
||||||
|
|
||||||
# Create the URL with parameters to ask for the csv file
|
# Create the URL with parameters to ask for the csv file
|
||||||
url_query_file <- httr::modify_url(url, query = parameters)
|
url_query_file <- modify_url(url, query = parameters)
|
||||||
response <- request_api(url_query_file, headers=headers,code=202)
|
response <- request_api(url_query_file, headers=headers,code=202)
|
||||||
if(!is.null(response) && response$status_code == 202){
|
if(response$status_code == 202){
|
||||||
url_fichier <- httr::modify_url(base,path = paste0(dpclim,"commande/fichier"))
|
url_fichier <- modify_url(base,path = paste0(dpclim,"commande/fichier"))
|
||||||
parameters <- list("id-cmde" = httr::content(response)[[1]][[1]] )
|
parameters <- list("id-cmde" = content(response)[[1]][[1]] )
|
||||||
print(paste("Waiting for file",parameters[["id-cmde"]],"wait",timesleep,"secs"))
|
print(paste("Waiting for file",parameters[["id-cmde"]],"wait",timesleep,"secs"))
|
||||||
Sys.sleep(timesleep)
|
Sys.sleep(timesleep)
|
||||||
url_get_file <- httr::modify_url(url_fichier, query = parameters)
|
url_get_file <- modify_url(url_fichier, query = parameters)
|
||||||
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
||||||
while(!is.null(response) && response$status_code %in% c(204,500)){
|
while(response$status_code %in% c(204,500)){
|
||||||
print("file not ready yet, wait a minute more")
|
print("file not ready yet, wait a minute more")
|
||||||
Sys.sleep(60)
|
Sys.sleep(60)
|
||||||
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
||||||
if(!is.null(response) && response$status_code == 500){
|
if(response$status_code == 500){
|
||||||
print("problem with file generation, retry")
|
print("problem with file generation, retry")
|
||||||
response <- request_api(url_query_file, headers=headers,code=202)
|
response <- request_api(url_query_file, headers=headers,code=202)
|
||||||
if (is.null(response)) {
|
parameters <- list("id-cmde" = content(response)[[1]][[1]] )
|
||||||
break
|
|
||||||
}
|
|
||||||
parameters <- list("id-cmde" = httr::content(response)[[1]][[1]] )
|
|
||||||
print(paste("Waiting for file",parameters[["id-cmde"]],"wait 25 sec"))
|
print(paste("Waiting for file",parameters[["id-cmde"]],"wait 25 sec"))
|
||||||
Sys.sleep(25)
|
Sys.sleep(25)
|
||||||
url_get_file <- httr::modify_url(url_fichier, query = parameters)
|
url_get_file <- modify_url(url_fichier, query = parameters)
|
||||||
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!is.null(response) && response$status_code == 201){
|
if(response$status_code == 201){
|
||||||
return(read.csv(text=httr::content(response,as="text")[[1]],sep=";",header=T,dec = ","))
|
return(read.csv(text=content(response,as="text")[[1]],sep=";",header=T,dec = ","))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print("Failed to retrieve data from the API. Why? not sure..")
|
print("Failed to retrieve data from the API. Why? not sure..")
|
||||||
|
|
@ -47,7 +44,7 @@ getStationData <- function(start_date, end_date, station_id,headers ,dpclim = "p
|
||||||
getStationDataDPObs <- function(start_date, end_date, station_id,headers ,dpclim = "public/DPClim/v1/",timesleep=5,base="https://public-api.meteofrance.fr") {
|
getStationDataDPObs <- function(start_date, end_date, station_id,headers ,dpclim = "public/DPClim/v1/",timesleep=5,base="https://public-api.meteofrance.fr") {
|
||||||
start_date <- as.Date(start_date)
|
start_date <- as.Date(start_date)
|
||||||
end_date <- as.Date(end_date)
|
end_date <- as.Date(end_date)
|
||||||
url <- httr::modify_url(base,path = paste0(dpclim,"commande-station/infrahoraire-6m"))
|
url <- modify_url(base,path = paste0(dpclim,"commande-station/infrahoraire-6m"))
|
||||||
# Format dates in ISO8601 format
|
# Format dates in ISO8601 format
|
||||||
formatted_start_date <- format(start_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
formatted_start_date <- format(start_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
||||||
formatted_end_date <- format(end_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
formatted_end_date <- format(end_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
||||||
|
|
@ -55,34 +52,31 @@ getStationDataDPObs <- function(start_date, end_date, station_id,headers ,dpclim
|
||||||
parameters <- list("id-station" = station_id, "date-deb-periode" = formatted_start_date, "date-fin-periode" = formatted_end_date)
|
parameters <- list("id-station" = station_id, "date-deb-periode" = formatted_start_date, "date-fin-periode" = formatted_end_date)
|
||||||
|
|
||||||
# Create the URL with parameters to ask for the csv file
|
# Create the URL with parameters to ask for the csv file
|
||||||
url_query_file <- httr::modify_url(url, query = parameters)
|
url_query_file <- modify_url(url, query = parameters)
|
||||||
response <- request_api(url_query_file, headers=headers,code=202)
|
response <- request_api(url_query_file, headers=headers,code=202)
|
||||||
if(!is.null(response) && response$status_code == 202){
|
if(response$status_code == 202){
|
||||||
url_fichier <- httr::modify_url(base,path = paste0(dpclim,"commande/fichier"))
|
url_fichier <- modify_url(base,path = paste0(dpclim,"commande/fichier"))
|
||||||
parameters <- list("id-cmde" = httr::content(response)[[1]][[1]] )
|
parameters <- list("id-cmde" = content(response)[[1]][[1]] )
|
||||||
print(paste("Waiting for file",parameters[["id-cmde"]],"wait",timesleep,"secs"))
|
print(paste("Waiting for file",parameters[["id-cmde"]],"wait",timesleep,"secs"))
|
||||||
Sys.sleep(timesleep)
|
Sys.sleep(timesleep)
|
||||||
url_get_file <- httr::modify_url(url_fichier, query = parameters)
|
url_get_file <- modify_url(url_fichier, query = parameters)
|
||||||
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
||||||
while(!is.null(response) && response$status_code %in% c(204,500)){
|
while(response$status_code %in% c(204,500)){
|
||||||
print("file not ready yet, wait a minute more")
|
print("file not ready yet, wait a minute more")
|
||||||
Sys.sleep(60)
|
Sys.sleep(60)
|
||||||
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
||||||
if(!is.null(response) && response$status_code == 500){
|
if(response$status_code == 500){
|
||||||
print("problem with file generation, retry")
|
print("problem with file generation, retry")
|
||||||
response <- request_api(url_query_file, headers=headers,code=202)
|
response <- request_api(url_query_file, headers=headers,code=202)
|
||||||
if (is.null(response)) {
|
parameters <- list("id-cmde" = content(response)[[1]][[1]] )
|
||||||
break
|
|
||||||
}
|
|
||||||
parameters <- list("id-cmde" = httr::content(response)[[1]][[1]] )
|
|
||||||
print(paste("Waiting for file",parameters[["id-cmde"]],"wait 25 sec"))
|
print(paste("Waiting for file",parameters[["id-cmde"]],"wait 25 sec"))
|
||||||
Sys.sleep(25)
|
Sys.sleep(25)
|
||||||
url_get_file <- httr::modify_url(url_fichier, query = parameters)
|
url_get_file <- modify_url(url_fichier, query = parameters)
|
||||||
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!is.null(response) && response$status_code == 201){
|
if(response$status_code == 201){
|
||||||
return(read.csv(text=httr::content(response,as="text")[[1]],sep=";",header=T,dec = ","))
|
return(read.csv(text=content(response,as="text")[[1]],sep=";",header=T,dec = ","))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print("Failed to retrieve data from the API. Why? not sure..")
|
print("Failed to retrieve data from the API. Why? not sure..")
|
||||||
|
|
@ -92,7 +86,7 @@ getStationDataDPObs <- function(start_date, end_date, station_id,headers ,dpclim
|
||||||
getStationDataTemp <- function(start_date, end_date, station_id,headers ,dpclim = "public/DPClim/v1/",timesleep=5,base="https://public-api.meteofrance.fr") {
|
getStationDataTemp <- function(start_date, end_date, station_id,headers ,dpclim = "public/DPClim/v1/",timesleep=5,base="https://public-api.meteofrance.fr") {
|
||||||
start_date <- as.Date(start_date)
|
start_date <- as.Date(start_date)
|
||||||
end_date <- as.Date(end_date)
|
end_date <- as.Date(end_date)
|
||||||
url <- httr::modify_url(base,path = paste0(dpclim,"commande-station/infrahoraire-6m"))
|
url <- modify_url(base,path = paste0(dpclim,"commande-station/infrahoraire-6m"))
|
||||||
# Format dates in ISO8601 format
|
# Format dates in ISO8601 format
|
||||||
formatted_start_date <- format(start_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
formatted_start_date <- format(start_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
||||||
formatted_end_date <- format(end_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
formatted_end_date <- format(end_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
||||||
|
|
@ -100,34 +94,31 @@ getStationDataTemp <- function(start_date, end_date, station_id,headers ,dpclim
|
||||||
parameters <- list("id-station" = station_id, "date-deb-periode" = formatted_start_date, "date-fin-periode" = formatted_end_date)
|
parameters <- list("id-station" = station_id, "date-deb-periode" = formatted_start_date, "date-fin-periode" = formatted_end_date)
|
||||||
|
|
||||||
# Create the URL with parameters to ask for the csv file
|
# Create the URL with parameters to ask for the csv file
|
||||||
url_query_file <- httr::modify_url(url, query = parameters)
|
url_query_file <- modify_url(url, query = parameters)
|
||||||
response <- request_api(url_query_file, headers=headers,code=202)
|
response <- request_api(url_query_file, headers=headers,code=202)
|
||||||
if(!is.null(response) && response$status_code == 202){
|
if(response$status_code == 202){
|
||||||
url_fichier <- httr::modify_url(base,path = paste0(dpclim,"commande/fichier"))
|
url_fichier <- modify_url(base,path = paste0(dpclim,"commande/fichier"))
|
||||||
parameters <- list("id-cmde" = httr::content(response)[[1]][[1]] )
|
parameters <- list("id-cmde" = content(response)[[1]][[1]] )
|
||||||
print(paste("Waiting for file",parameters[["id-cmde"]],"wait",timesleep,"secs"))
|
print(paste("Waiting for file",parameters[["id-cmde"]],"wait",timesleep,"secs"))
|
||||||
Sys.sleep(timesleep)
|
Sys.sleep(timesleep)
|
||||||
url_get_file <- httr::modify_url(url_fichier, query = parameters)
|
url_get_file <- modify_url(url_fichier, query = parameters)
|
||||||
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
||||||
while(!is.null(response) && response$status_code %in% c(204,500)){
|
while(response$status_code %in% c(204,500)){
|
||||||
print("file not ready yet, wait a minute more")
|
print("file not ready yet, wait a minute more")
|
||||||
Sys.sleep(60)
|
Sys.sleep(60)
|
||||||
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
||||||
if(!is.null(response) && response$status_code == 500){
|
if(response$status_code == 500){
|
||||||
print("problem with file generation, retry")
|
print("problem with file generation, retry")
|
||||||
response <- request_api(url_query_file, headers=headers,code=202)
|
response <- request_api(url_query_file, headers=headers,code=202)
|
||||||
if (is.null(response)) {
|
parameters <- list("id-cmde" = content(response)[[1]][[1]] )
|
||||||
break
|
|
||||||
}
|
|
||||||
parameters <- list("id-cmde" = httr::content(response)[[1]][[1]] )
|
|
||||||
print(paste("Waiting for file",parameters[["id-cmde"]],"wait 25 sec"))
|
print(paste("Waiting for file",parameters[["id-cmde"]],"wait 25 sec"))
|
||||||
Sys.sleep(25)
|
Sys.sleep(25)
|
||||||
url_get_file <- httr::modify_url(url_fichier, query = parameters)
|
url_get_file <- modify_url(url_fichier, query = parameters)
|
||||||
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
response <- request_api(url_get_file, headers=headers,code=c(204,201,500))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!is.null(response) && response$status_code == 201){
|
if(response$status_code == 201){
|
||||||
return(read.csv(text=httr::content(response,as="text")[[1]],sep=";",header=T,dec = ","))
|
return(read.csv(text=content(response,as="text")[[1]],sep=";",header=T,dec = ","))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print("Failed to retrieve data from the API. Why? not sure..")
|
print("Failed to retrieve data from the API. Why? not sure..")
|
||||||
|
|
@ -138,7 +129,7 @@ getStationDataTemp <- function(start_date, end_date, station_id,headers ,dpclim
|
||||||
getStationDataDPObs <- function(start_date, end_date, station_id,headers ,dpclim = "public/DPObs/v1/",timesleep=5,base="https://public-api.meteofrance.fr") {
|
getStationDataDPObs <- function(start_date, end_date, station_id,headers ,dpclim = "public/DPObs/v1/",timesleep=5,base="https://public-api.meteofrance.fr") {
|
||||||
start_date <- as.Date(start_date)
|
start_date <- as.Date(start_date)
|
||||||
end_date <- as.Date(end_date)
|
end_date <- as.Date(end_date)
|
||||||
url <- httr::modify_url(base,path = paste0(dpclim,"station/infrahoraire-6m"))
|
url <- modify_url(base,path = paste0(dpclim,"station/infrahoraire-6m"))
|
||||||
# Format dates in ISO8601 format
|
# Format dates in ISO8601 format
|
||||||
formatted_start_date <- format(start_date, "%Y-%m-%dT12:00:00Z", tz = "GMT")
|
formatted_start_date <- format(start_date, "%Y-%m-%dT12:00:00Z", tz = "GMT")
|
||||||
formatted_end_date <- format(end_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
formatted_end_date <- format(end_date, "%Y-%m-%dT00:00:00Z", tz = "GMT")
|
||||||
|
|
@ -146,7 +137,7 @@ getStationDataDPObs <- function(start_date, end_date, station_id,headers ,dpclim
|
||||||
parameters <- list("id_station" = station_id, "date" = formatted_start_date,'format'='csv')
|
parameters <- list("id_station" = station_id, "date" = formatted_start_date,'format'='csv')
|
||||||
|
|
||||||
# Create the URL with parameters to ask for the csv file
|
# Create the URL with parameters to ask for the csv file
|
||||||
url_query_file <- httr::modify_url(url, query = parameters)
|
url_query_file <- modify_url(url, query = parameters)
|
||||||
response <- request_api(url_query_file, headers=headers,code=200)
|
response <- request_api(url_query_file, headers=headers,code=200)
|
||||||
print(response)
|
print(response)
|
||||||
#if(response$status_code == 202){
|
#if(response$status_code == 202){
|
||||||
|
|
@ -177,3 +168,4 @@ getStationDataDPObs <- function(start_date, end_date, station_id,headers ,dpclim
|
||||||
#print("Failed to retrieve data from the API. Why? not sure..")
|
#print("Failed to retrieve data from the API. Why? not sure..")
|
||||||
#return(NULL)
|
#return(NULL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
getStationInfo <- function(station, headers,infostat = "information-station",dpclim = "public/DPClim/v1/") {
|
getStationInfo <- function(station, headers,infostat = "information-station",dpclim = "public/DPClim/v1/") {
|
||||||
# Assuming 'base' and 'dpclim' are defined externally; include 'infostat' parameter appropriately
|
# Assuming 'base' and 'dpclim' are defined externally; include 'infostat' parameter appropriately
|
||||||
url <- httr::modify_url(base, path = paste0(dpclim, infostat), query = list("id-station" = station))
|
url <- modify_url(base, path = paste0(dpclim, infostat), query = list("id-station" = station))
|
||||||
response <- httr::GET(url, headers)
|
response <- GET(url, headers)
|
||||||
# Check if the request was successful
|
# Check if the request was successful
|
||||||
if (httr::http_status(response)$category == "Success") {
|
if (http_status(response)$category == "Success") { # Ensure 'success' is lowercase as typically returned by the http_status() function
|
||||||
# Properly parsing the content as CSV by directly reading the response text
|
# Properly parsing the content as CSV by directly reading the response text
|
||||||
data <- read.csv(text = httr::content(response, as = "text"), sep = ";", header = TRUE)
|
data <- read.csv(text = content(response, as = "text"), sep = ";", header = TRUE)
|
||||||
return(data)
|
return(data)
|
||||||
}
|
}
|
||||||
stop(sprintf("Failed to get station info from the API. Status code: %s", response$status_code))
|
stop(sprintf("Failed to get station info from the API. Status code: %s", response$status_code))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,15 @@
|
||||||
getStationPaquet <- function(
|
getStationPaquet <- function(id_station, format = "csv", headers = headersPaquet) {
|
||||||
id_station,
|
base_url <- modify_url(base, path = paste0(dpPaquetObs, "infrahoraire-6m"))
|
||||||
format = "csv",
|
url_with_params <- modify_url(base_url, query = list(id_station = id_station, format = format))
|
||||||
headers,
|
|
||||||
endpoint = paste0(dpPaquetObs, "infrahoraire-6m")
|
|
||||||
) {
|
|
||||||
url_with_params <- httr::modify_url(
|
|
||||||
base,
|
|
||||||
path = endpoint,
|
|
||||||
query = list(id_station = id_station, format = format)
|
|
||||||
)
|
|
||||||
|
|
||||||
response <- request_api(
|
response <- GET(url_with_params, add_headers(.headers = headers))
|
||||||
url_with_params = url_with_params,
|
|
||||||
headers = headers,
|
|
||||||
code = 200,
|
|
||||||
retry_limit = 3,
|
|
||||||
timesleep = 5
|
|
||||||
)
|
|
||||||
|
|
||||||
if (is.null(response)) {
|
if (response$status_code == 200) {
|
||||||
return(NULL)
|
# Successfully retrieved the data
|
||||||
|
return(read.csv(text = content(response, "text"), sep = ";", header = TRUE))
|
||||||
|
} else {
|
||||||
|
# If the request failed, it's useful to provide the status code in the error message for debugging
|
||||||
|
stop(sprintf("Failed to retrieve data as paquet from the API. Status code: %s", response$status_code))
|
||||||
}
|
}
|
||||||
|
|
||||||
read.csv(
|
|
||||||
text = httr::content(response, "text", encoding = "UTF-8"),
|
|
||||||
sep = ";",
|
|
||||||
header = TRUE,
|
|
||||||
stringsAsFactors = FALSE
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
getStations <- function(headers = headers,dpobs = "public/DPObs/v1/") {
|
getStations <- function(headers = headers,dpobs = "public/DPObs/v1/") {
|
||||||
# Ensure dpobs is defined externally or provide a default/argument for it
|
# Ensure dpobs is defined externally or provide a default/argument for it
|
||||||
url <- httr::modify_url(base, path = paste0(dpobs, "liste-stations"))
|
url <- modify_url(base, path = paste0(dpobs, "liste-stations"))
|
||||||
response <- httr::GET(url, httr::add_headers(.headers = headers))
|
response <- GET(url, add_headers(.headers = headers))
|
||||||
# Better error handling
|
# Better error handling
|
||||||
if (httr::http_status(response)$category == "Success") {
|
if (http_status(response)$category == "success") {
|
||||||
# Directly parse the content as a CSV
|
# Directly parse the content as a CSV
|
||||||
data <- httr::content(response, as = "text")
|
data <- content(response, as = "text")
|
||||||
# Return the data frame
|
# Return the data frame
|
||||||
return(read.csv(text = data, sep = ";", header = TRUE))
|
return(read.csv(text = data, sep = ";", header = TRUE))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -16,3 +16,4 @@ getStations <- function(headers = headers,dpobs = "public/DPObs/v1/") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ request_api <- function(url_with_params,headers,code,retry_limit=5,timesleep=20)
|
||||||
success <- FALSE
|
success <- FALSE
|
||||||
|
|
||||||
while(retry_count < retry_limit && !success) {
|
while(retry_count < retry_limit && !success) {
|
||||||
response <- tryCatch(httr::GET(url_with_params, headers),error=function(e){print(e);NULL})
|
response <- tryCatch(GET(url_with_params, headers),error=function(e){print(e);NULL})
|
||||||
print(response)
|
print(response)
|
||||||
if(!is.null(response) && (response$status_code %in% code)) {
|
if(!is.null(response) && (response$status_code %in% code)) {
|
||||||
success <- TRUE
|
success <- TRUE
|
||||||
|
|
@ -37,10 +37,11 @@ request_api <- function(url_with_params,headers,code,retry_limit=5,timesleep=20)
|
||||||
print(url_with_params)
|
print(url_with_params)
|
||||||
print(paste0("retry #",retry_count,"/",retry_limit))
|
print(paste0("retry #",retry_count,"/",retry_limit))
|
||||||
retry_count <- retry_count + 1
|
retry_count <- retry_count + 1
|
||||||
Sys.sleep(timesleep*(1+retry_count/retry_limit))
|
Sys.sleep(timesleep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!success) return(NULL)
|
if(!success) return(NULL)
|
||||||
else return(response)
|
else return(response)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
96
app.R
96
app.R
|
|
@ -1,96 +0,0 @@
|
||||||
# Load necessary libraries
|
|
||||||
library(shiny)
|
|
||||||
library(jsonlite)
|
|
||||||
library(httr)
|
|
||||||
library(shinycssloaders) # For the spinner
|
|
||||||
|
|
||||||
# Assuming you have your custom functions in a file called 'your_functions.R'
|
|
||||||
|
|
||||||
# List all R files in the directory and source them
|
|
||||||
|
|
||||||
|
|
||||||
lapply(list.files(path = "R", pattern = "\\.R$", full.names = T), source)
|
|
||||||
|
|
||||||
source("data/secrets")
|
|
||||||
|
|
||||||
# Create a Bearer token header
|
|
||||||
headers.default <- add_headers(
|
|
||||||
accept = "*/*",
|
|
||||||
apikey = token4
|
|
||||||
)
|
|
||||||
|
|
||||||
# Load station data
|
|
||||||
|
|
||||||
# Define UI for application
|
|
||||||
ui <- fluidPage(
|
|
||||||
tags$head(
|
|
||||||
tags$style(HTML("
|
|
||||||
#main {
|
|
||||||
height: 100vh; /* Full height of the viewport */
|
|
||||||
overflow-y: auto; /* Scroll if content overflows */
|
|
||||||
}
|
|
||||||
.container-fluid {
|
|
||||||
height: 100vh; /* Full height of the viewport */
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
.row {
|
|
||||||
flex-grow: 1;
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
.col-sm-8 {
|
|
||||||
flex-grow: 1; /* Allow the main panel to grow */
|
|
||||||
}
|
|
||||||
"))
|
|
||||||
),
|
|
||||||
|
|
||||||
# Application title
|
|
||||||
titlePanel("Beaumont aka SECMONT"),
|
|
||||||
|
|
||||||
# Sidebar for user inputs
|
|
||||||
sidebarLayout(
|
|
||||||
sidebarPanel(
|
|
||||||
width=2,
|
|
||||||
numericInput(inputId = "daysBefore", label = "Nb jour à check:", value=10, min=1)
|
|
||||||
),
|
|
||||||
|
|
||||||
# Main panel for displaying plot
|
|
||||||
mainPanel(
|
|
||||||
width = 6,
|
|
||||||
withSpinner( plotOutput("dataPlot"))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Define server logic required to generate and plot data
|
|
||||||
server <- function(input, output) {
|
|
||||||
# Reactive expression to fetch data based on input and display spinner while loading
|
|
||||||
|
|
||||||
|
|
||||||
# Render the plot
|
|
||||||
output$dataPlot <- renderPlot({
|
|
||||||
startdate <- format(Sys.Date() - input$daysBefore, "%Y-%m-%d")
|
|
||||||
vignass.coor=c(44.8550665,5.8441789)
|
|
||||||
allstations <- read.csv("data/allstations.csv")
|
|
||||||
test1 <- getAllFromCoord(vignass.coor, start_date = startdate, end_date = format(Sys.Date(), "%Y-%m-%d"), allstations, headers = headers.default,btw_station_sleep = .5,within_statio_sleep = 1)
|
|
||||||
|
|
||||||
# Prepare colors
|
|
||||||
cols <- palette.colors()[1:length(unique(test1$Nom_usuel))]
|
|
||||||
names(cols) <- unique(test1$Nom_usuel)
|
|
||||||
|
|
||||||
# Filter data
|
|
||||||
testsep <- test1
|
|
||||||
testsep[testsep[,3] == 0 & !is.na(testsep[,3]), c(3,4)] <- NA
|
|
||||||
|
|
||||||
plot(getDate(testsep[,2]), testsep[,3], pch = 20, col = adjustcolor(cols[testsep$Nom_usuel], .4), cex = 1.3, ylim = c(0, 8))
|
|
||||||
|
|
||||||
# Add legend
|
|
||||||
legend("topleft", col = cols, legend = names(cols), pch = 20, cex = 1)
|
|
||||||
|
|
||||||
# Highlight specific date
|
|
||||||
abline(v = as.numeric(as.POSIXlt("2024-08-07", format = "%Y-%m-%d")), lwd = 3, col = "red")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run the application
|
|
||||||
shinyApp(ui = ui, server = server)
|
|
||||||
2113
data/allstations.csv
2113
data/allstations.csv
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +0,0 @@
|
||||||
token2="eyJ4NXQiOiJZV0kxTTJZNE1qWTNOemsyTkRZeU5XTTRPV014TXpjek1UVmhNbU14T1RSa09ETXlOVEE0Tnc9PSIsImtpZCI6ImdhdGV3YXlfY2VydGlmaWN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B1YmxpcXVlc1BhcXVldE9ic2VydmF0aW9uIiwiY29udGV4dCI6IlwvcHVibGljXC9EUFBhcXVldE9ic1wvdjEiLCJwdWJsaXNoZXIiOiJiYXN0aWVuZyIsInZlcnNpb24iOiJ2MSIsInN1YnNjcmlwdGlvblRpZXIiOiI1MFBlck1pbiJ9XSwiZXhwIjoxODE4NDg1MTU5LCJ0b2tlbl90eXBlIjoiYXBpS2V5IiwiaWF0IjoxNzIzODEyMzU5LCJqdGkiOiI4ZGJiYmVkMy1lM2I3LTRmMDQtOTIwZi0wMDRkMzA2YmY0MzMifQ==.IBDs-9hHPJDCFAQVBFU1l8gWwsQcLGeo_pVwz4HTF-aLzPQS9F7P7Z8KxD1hAE6XabIICyci8iLHf7C-UM3lZaLX1j9ejeKkK-G9Haeh-Ufl_QAxs3jTamizwJT3-nieE6fMtBrWKXaSrzIc5Lg7ukRH1tU6_k1pIti1IExZS2t_vjUdGRqWhQaMLo6tyeSA-UopJAuiP7X_TBrphUp__EpFXreFTRZiT17Utzeoyr9eUt1RrD5F-KHb9sdO9zHQTFJ2beSpz9yvRn2MM9UAcO3QDrthgRZJvn0bjunilee_pNhVjEkpsmTEhax8HQuS02e5vImV36QjYLILEZldNg=="
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
test_that("sourced getStationData handles request failure without attached httr", {
|
|
||||||
helper_env <- new.env(parent = globalenv())
|
|
||||||
sys.source(testthat::test_path("..", "..", "R", "getStationData.R"), envir = helper_env)
|
|
||||||
|
|
||||||
helper_env$request_api <- function(...) NULL
|
|
||||||
|
|
||||||
expect_null(
|
|
||||||
helper_env$getStationData(
|
|
||||||
start_date = "2024-01-01",
|
|
||||||
end_date = "2024-01-02",
|
|
||||||
station_id = "12345678",
|
|
||||||
headers = list(),
|
|
||||||
timesleep = 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
test_that("getAllFromCoord returns NULL when every station fetch fails", {
|
|
||||||
helper_env <- new.env(parent = globalenv())
|
|
||||||
sys.source(testthat::test_path("..", "..", "R", "getAllFromCoord.R"), envir = helper_env)
|
|
||||||
|
|
||||||
helper_env$getIdFromCoords <- function(...) {
|
|
||||||
data.frame(
|
|
||||||
Id_station = c("1001", "1002"),
|
|
||||||
Nom_usuel = c("Station A", "Station B"),
|
|
||||||
stringsAsFactors = FALSE
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
helper_env$getStationData <- function(...) NULL
|
|
||||||
|
|
||||||
expect_null(
|
|
||||||
helper_env$getAllFromCoord(
|
|
||||||
coord = c(44.85, 5.84),
|
|
||||||
start_date = "2024-01-01",
|
|
||||||
end_date = "2024-01-02",
|
|
||||||
allstations = data.frame(),
|
|
||||||
headers = list(),
|
|
||||||
btw_station_sleep = 0,
|
|
||||||
within_statio_sleep = 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
Loading…
Reference in a new issue