Eddington {eddington} | R Documentation |
An R6 Class for Tracking Eddington Numbers for Cycling
Description
An R6 Class for Tracking Eddington Numbers for Cycling
An R6 Class for Tracking Eddington Numbers for Cycling
Details
The class will maintain the state of the algorithm, allowing for efficient updates as new rides come in.
Warnings
The implementation uses an experimental base R feature utils::hashtab.
Cloning of Eddington
objects is disabled. Additionally, Eddington
objects
cannot be serialized; they cannot be carried between sessions using
base::saveRDS or base::save and then loaded later using base::readRDS
or base::load.
Active bindings
current
The current Eddington number.
cumulative
A vector of cumulative Eddington numbers.
number_to_next
The number of rides needed to get to the next Eddington number.
n
The number of rides in the data.
hashmap
The hash map of rides above the current Eddington number.
Methods
Public methods
Method new()
Create a new Eddington object.
Usage
Eddington$new(rides, store.cumulative = FALSE)
Arguments
rides
A vector of rides
store.cumulative
logical, indicating whether to keep a vector of cumulative Eddington numbers
Returns
A new Eddington
object
Method print()
Print the current Eddington number.
Usage
Eddington$print()
Method update()
Add new rides to the existing Eddington
object.
Usage
Eddington$update(rides)
Arguments
rides
A vector of rides
Method getNumberToTarget()
Get the number of rides of a specified length to get to a target Eddington number.
Usage
Eddington$getNumberToTarget(target)
Arguments
target
Target Eddington number
Returns
An integer representing the number of rides of target length needed to achieve the target number.
Method isSatisfied()
Test if an Eddington number is satisfied.
Usage
Eddington$isSatisfied(target)
Arguments
target
Target Eddington number
Returns
Logical
Examples
# Randomly generate a set of 15 rides
rides <- rgamma(15, shape = 2, scale = 10)
# View the rides sorted in decreasing order
setNames(sort(rides, decreasing = TRUE), seq_along(rides))
# Create the Eddington object
e <- Eddington$new(rides, store.cumulative = TRUE)
# Get the Eddington number
e$current
# Update with new data
e$update(rep(25, 10))
# See the new data
e$cumulative