|
3 | 3 | # /example_data ---------------------------------------------------------------- |
4 | 4 |
|
5 | 5 | #* Example data for Abimo (Berlin, 2019) |
6 | | -#* @param n_records number of records (= input rows = "Blockteilflaechen"). |
7 | | -#* @param seed seed value for the random number generator used to randomly select rows |
8 | | -#* @param output_only whether to return only the data frame with example data (true, the default) or a list with inputs and output (false). |
9 | | -#* @post /example_data |
10 | | -function(req, n_records = 3L, seed = as.integer(Sys.time()), output_only = TRUE) |
| 6 | +#* @param n_records:int number of records (= input rows = "Blockteilflaechen"). |
| 7 | +#* @param seed seed:int value for the random number generator used to randomly select rows |
| 8 | +#* @param output_only:logical whether to return only the data frame with example data (true) or a list with inputs and output (false). |
| 9 | +#* @get /example_data |
| 10 | +function(n_records = 3L, seed = as.integer(Sys.time()), output_only = TRUE) |
11 | 11 | { |
12 | 12 | n_records <- as.integer(n_records) |
13 | 13 | seed <- as.integer(seed) |
@@ -38,28 +38,33 @@ function(req, n_records = 3L, seed = as.integer(Sys.time()), output_only = TRUE) |
38 | 38 | # /get_measure_stats ----------------------------------------------------------- |
39 | 39 |
|
40 | 40 | #* Statistics (mean, max) on measures within selected blocks |
41 | | -#* @param blocks_json Selected blocks |
42 | | -#* @param reference_system "Reference system" (1:old, 2:new = percentages of total area) |
| 41 | +#* @param blocks:data.frame Selected blocks |
| 42 | +#* @param max_only:logical whether or not to return only the "max" (and not also the "mean") values |
| 43 | +#* @param reference_system:int "Reference system" (1:old, 2:new = percentages of total area) |
| 44 | +#* @param safety_factor:float Factor that the "max" values are multiplied with to make them a bit smaller |
43 | 45 | #* @serializer unboxedJSON |
44 | 46 | #* @post get_measure_stats |
45 | | -function(req, blocks_json, reference_system = 2) |
| 47 | +function(blocks = data.frame(), max_only = TRUE, reference_system = 2L, safety_factor = 0.999) |
46 | 48 | { |
47 | | - blocks <- jsonlite::fromJSON(blocks_json) |
48 | | - kwb.rabimo::get_measure_stats(blocks, reference_system) |
| 49 | + stats <- kwb.rabimo::get_measure_stats(blocks, reference_system) |
| 50 | + |
| 51 | + if (max_only) { |
| 52 | + lapply(lapply(stats, `[[`, "max"), `*`, as.numeric(safety_factor)) |
| 53 | + } else { |
| 54 | + stats |
| 55 | + } |
49 | 56 | } |
50 | 57 |
|
51 | 58 | # /run_rabimo ------------------------------------------------------------------ |
52 | 59 |
|
53 | 60 | #' Run R-Abimo with data and config (optional) |
54 | | -#* @param data_json input data as json string, as returned by /example_data in "output" |
| 61 | +#* @param data:data.frame input data as json string, as returned by /example_data in "output" |
55 | 62 | #* @param measures_json Optional. Target values of measures, as json string, e.g. '{"green_roof":0.1, "unpaved":0.2, "to_swale":0.3}' |
56 | 63 | #* @param config_json Optional. Configuration as json string, as returned by /default_config |
57 | 64 | #* @serializer unboxedJSON |
58 | 65 | #* @post /run_rabimo |
59 | | -function(req, data_json, measures_json = "", config_json = "") |
| 66 | +function(data = data.frame(), measures_json = "", config_json = "") |
60 | 67 | { |
61 | | - data <- jsonlite::fromJSON(data_json) |
62 | | - |
63 | 68 | # Convert json string to data frame and set all columns to expected types |
64 | 69 | data <- kwb.rabimo:::check_or_convert_data_types( |
65 | 70 | data = data, |
@@ -93,6 +98,7 @@ function(req, data_json, measures_json = "", config_json = "") |
93 | 98 |
|
94 | 99 | list( |
95 | 100 | data = if (failed) NULL else output, |
| 101 | + measures = measures, |
96 | 102 | weighted_means = if (failed) NULL else { |
97 | 103 | areas <- output$area |
98 | 104 | cols <- 3:5 |
|
0 commit comments