Skip to content

Commit

Permalink
try HaaS again - no luck
Browse files Browse the repository at this point in the history
  • Loading branch information
temospena committed Oct 10, 2023
1 parent 4ea5f17 commit a01eb5b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
28 changes: 28 additions & 0 deletions HEAT/code/haas_reprex.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"))






Expand Down
20 changes: 10 additions & 10 deletions code/test-code/heat-prep.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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),
Expand All @@ -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)) %>%
Expand Down

0 comments on commit a01eb5b

Please sign in to comment.