diff --git a/HEAT/code/haas_reprex.R b/HEAT/code/haas_reprex.R index 4ef8e6e..5687f6b 100644 --- a/HEAT/code/haas_reprex.R +++ b/HEAT/code/haas_reprex.R @@ -48,6 +48,8 @@ resp <- # convert from "jsonl-serialized" to R format from_serialized_json <- jsonlite::unserializeJSON(httr::content(resp, "text")) + + str(from_serialized_json$results) # Check final result value @@ -76,6 +78,8 @@ resp <- # convert to R from_rds <- unserialize(httr::content(resp, "raw")) +# check the response +str(resp) # Check final result value res = as.numeric(gsub(" ","",from_rds$results$moneytotaldisc)) #remove spaces and convert to to numeric @@ -86,6 +90,30 @@ res[26]-res[27]-res[28]+res[29] # + # TRY TO USE OTHER VALUES +webapp_input[["raw_activemode_bike_ref_alltrips"]] # it use to be the sum of all TRIPS per day (not per person/day) + +totaltripspax = 2.6 +webapp_input[["raw_activemode_bike_ref_alltrips"]] = totaltripspax +webapp_input[["raw_activemode_bike_cf_alltrips"]] = totaltripspax +webapp_input[["raw_motorizedmode_car_ref_alltrips"]] = totaltripspax +webapp_input[["raw_motorizedmode_car_cf_alltrips"]] = totaltripspax + + +# DOESNT WORK +resp_reprex <- + httr::POST("https://api.heatwalkingcycling.org/apiv1/heat_5_0/calc_results?output_format=rds", + httr::set_cookies("user" = Sys.getenv("HEAT_COOKIE")), + body = jsonlite::toJSON( + list("webapp_input" = webapp_input, + "generic_data_relevant" = genericdata)), + encode = "multipart") + +# convert to R +from_rds_reprex <- unserialize(httr::content(resp_reprex, "raw")) + + + diff --git a/code/test-code/heat-prep.R b/code/test-code/heat-prep.R index 5f2443b..123761a 100644 --- a/code/test-code/heat-prep.R +++ b/code/test-code/heat-prep.R @@ -253,7 +253,7 @@ HEATbind_aml_PPP = HEATbind ## For Intermodality --------------------------------------------------------------------------- # RUN THIS AGAIN WHEN API GETS LIVE -Code_Hass = CENARIOS$Code[9:12] #fazer por enquanto só AML e senários 1 e 2 +Code_Hass = CENARIOS$Code[9:12] #fazer por enquanto só AML e senários 3 HEATbind_intermodal_correct = HEAT @@ -275,11 +275,11 @@ for (i in Code_Hass){ ungroup() %>% group_by(id) %>% # it shouldn't return two segments again. summarise(distance = sum(distance), # we need to put both segments distance together! - Bike = Bike, - Car = Car + CarP, - Total = Total, - Bikeper = Bike / Total) %>% - unique() |> # NOT THE IDEAL BUT WORKS FOR THE PURPUSE (this was missing in the first version 2023) + Bike = mean(Bike), + Car = mean(Car) + mean(CarP), + Total = mean(Total), + Bikeper = mean(Bike) / mean(Total)) %>% + # unique() |> # NOT THE IDEAL BUT WORKS FOR THE PURPUSE (this was missing in the first version 2023) ungroup() %>% mutate( cyc = ifelse(Bikeper >= HEAT$ENMAC, Bike, HEAT$ENMAC * Total), @@ -292,10 +292,10 @@ for (i in Code_Hass){ filter(id %in% unique(HEAT_bike$id)) %>% group_by(id) %>% summarise(distance = sum(distance), - Bike = Bike, - Car = Car + CarP, - Total = Total, - Bikeper = Bike / Total) %>% + Bike = mean(Bike), + Car = mean(Car) + mean(CarP), + Total = mean(Total), + Bikeper = mean(Bike) / mean(Total)) %>% mutate( cyc = ifelse(Bikeper >= HEAT$ENMAC, Bike, HEAT$ENMAC * Total), new_cyc = ifelse(Bikeper >= HEAT$ENMAC, 0, cyc - Bike)) %>%