|
1 | | -# RateParser |
| 1 | +RateParser |
| 2 | +================ |
2 | 3 |
|
3 | 4 | [](https://travis-ci.org/California-Data-Collaborative/RateParser) [](https://codecov.io/gh/California-Data-Collaborative/RateParser) |
4 | 5 |
|
| 6 | +RateParser is an R package to parse files written using the [Open Water Rate Specification (OWRS)](https://github.com/California-Data-Collaborative/Open-Water-Rate-Specification) and use them to calculate water bills. |
5 | 7 |
|
6 | | -Interpret [OWRS files](https://github.com/California-Data-Collaborative/Open-Water-Rate-Specification) and calculate water bills. |
| 8 | +Installation |
| 9 | +------------ |
| 10 | + |
| 11 | +To install the latest version from Github, sinply run the following from an R console: |
| 12 | + |
| 13 | +``` r |
| 14 | +if (!require("devtools")) |
| 15 | + install.packages("devtools") |
| 16 | +devtools::install_github("California-Data-Collaborative/RateParser") |
| 17 | +``` |
| 18 | + |
| 19 | +Getting Started |
| 20 | +--------------- |
| 21 | + |
| 22 | +This section demonstrates how to apply RateParser to calculate water bills given a dataframe of publicly available [billing data](https://data.smgov.net/Public-Services/Water-Usage/4nnq-5vzx) from the City of Santa Monica. |
| 23 | + |
| 24 | +First we load the RateParser package and read in the example OWRS file. |
| 25 | + |
| 26 | +``` r |
| 27 | +library(RateParser) |
| 28 | + |
| 29 | +# read in example OWRS file |
| 30 | +owrs_file <- read_owrs_file("examples/smc-2016-03-01.owrs") |
| 31 | + |
| 32 | +# view residential single-family rates |
| 33 | +owrs_file$rate_structure$RESIDENTIAL_SINGLE |
| 34 | +``` |
| 35 | + |
| 36 | + ## $tier_starts |
| 37 | + ## [1] 0 15 41 149 |
| 38 | + ## |
| 39 | + ## $tier_prices |
| 40 | + ## [1] 2.87 4.29 6.44 10.07 |
| 41 | + ## |
| 42 | + ## $commodity_charge |
| 43 | + ## [1] "Tiered" |
| 44 | + ## |
| 45 | + ## $bill |
| 46 | + ## [1] "commodity_charge" |
| 47 | + |
| 48 | +Not all of the data columns needed to calculate their water bills are included in the public data, so instead we need to assign some default values. |
| 49 | + |
| 50 | +``` r |
| 51 | +santamonica$meter_size <- '5/8"' |
| 52 | +santamonica$water_type <- 'POTABLE' |
| 53 | +``` |
| 54 | + |
| 55 | +Our dataframe currently contains an "OTHER" class (a byproduct of the author's inability to properly classify some of the rate codes). Our sample OWRS file, on the other hand, contains no information for "OTHER" customer class, so we need to filter those out. |
| 56 | + |
| 57 | +Finally we can pass our dataframe and our OWRS file as inputs into the `calculate_bill` function. |
| 58 | + |
| 59 | +``` r |
| 60 | +library(dplyr, warn.conflicts = FALSE) |
| 61 | + |
| 62 | +# filter out "OTHER" class |
| 63 | +filtered <- dplyr::tbl_df(santamonica) %>% dplyr::filter(cust_class != "OTHER") |
| 64 | + |
| 65 | +# calculate water bills |
| 66 | +calced <- calculate_bill(filtered, owrs_file) |
| 67 | +``` |
| 68 | + |
| 69 | +The results in a number of additional columns being appended to the original dataframe. Note that the first 9 columns are the original input columns, while the rest have been added by `calculate_bills`. |
| 70 | + |
| 71 | +In particular, |
| 72 | + |
| 73 | +- `bill` is the water bill (in dollars) for that customer in that month |
| 74 | +- `Xn` is the amount of water use (in billing units) in the *nth* rate tier |
| 75 | +- `XRn` is the amount of revenue (in dollars) generated by the *nth* rate tier |
| 76 | + |
| 77 | +``` r |
| 78 | +glimpse(calced) |
| 79 | +``` |
| 80 | + |
| 81 | + ## Observations: 217,256 |
| 82 | + ## Variables: 21 |
| 83 | + ## $ cust_id (int) 25886, 74585, 57854, 58210, 25002, 68393, 257... |
| 84 | + ## $ usage_ccf (dbl) 388, 9, 73, 22, 11, 84, 670, 170, 0, 102, 107... |
| 85 | + ## $ usage_month (int) 3, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 1, 4, ... |
| 86 | + ## $ usage_year (int) 2014, 2015, 2015, 2015, 2015, 2015, 2015, 201... |
| 87 | + ## $ cust_class (chr) "COMMERCIAL", "COMMERCIAL", "COMMERCIAL", "CO... |
| 88 | + ## $ usage_date (chr) "2014-03-01", "2015-01-01", "2015-01-01", "20... |
| 89 | + ## $ rate_code (chr) "WANR5", "WANR2", "WANR3", "WANR1", "WANR2", ... |
| 90 | + ## $ meter_size (chr) "5/8\"", "5/8\"", "5/8\"", "5/8\"", "5/8\"", ... |
| 91 | + ## $ water_type (chr) "POTABLE", "POTABLE", "POTABLE", "POTABLE", "... |
| 92 | + ## $ tier_starts (chr) "0\n211", "0\n211", "0\n211", "0\n211", "0\n2... |
| 93 | + ## $ tier_prices (chr) "4.07\n10.03", "4.07\n10.03", "4.07\n10.03", ... |
| 94 | + ## $ X1 (dbl) 210, 9, 73, 22, 11, 84, 210, 170, 0, 102, 210... |
| 95 | + ## $ X2 (dbl) 178, 0, 0, 0, 0, 0, 460, 0, 0, 0, 865, 0, 0, ... |
| 96 | + ## $ XR1 (dbl) 854.70, 36.63, 297.11, 89.54, 44.77, 341.88, ... |
| 97 | + ## $ XR2 (dbl) 1785.34, 0.00, 0.00, 0.00, 0.00, 0.00, 4613.8... |
| 98 | + ## $ commodity_charge (dbl) 2640.04, 36.63, 297.11, 89.54, 44.77, 341.88,... |
| 99 | + ## $ bill (dbl) 2640.04, 36.63, 297.11, 89.54, 44.77, 341.88,... |
| 100 | + ## $ X3 (dbl) NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N... |
| 101 | + ## $ X4 (dbl) NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N... |
| 102 | + ## $ XR3 (dbl) NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N... |
| 103 | + ## $ XR4 (dbl) NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N... |
0 commit comments