Skip to content

Instantly share code, notes, and snippets.

@seandavi
Last active July 26, 2025 16:44
Show Gist options
  • Save seandavi/72e3333ca027af489bd94984311f4378 to your computer and use it in GitHub Desktop.
Save seandavi/72e3333ca027af489bd94984311f4378 to your computer and use it in GitHub Desktop.
Orchestra platform workshop pricing calculator
#' Workshop cost calculator
#'
#' This cost calculator give the **minimum** cost for a workshop of the
#' requested size, number or participants, and hours.
#'
#' @param vcpu numeric() amount of virtual cpu requested (can be fractional)
#' @param memory numeric() in GB the amount of requested memory
#' @param hours numeric() the number of hours for each instance to run
#' The workshops will run for this amount of time even if a participant
#' is not using it. So, every launch results in a cost.
#' @param participants numeric() number of participants who launch a workshop
#' @param storage numeric() amount of disk storage requested
#'
#' @seealso
#' * https://cloud.google.com/kubernetes-engine/docs/concepts/autopilot-resource-requests#min-max-requests
#' * https://cloud.google.com/kubernetes-engine/pricing
#'
price_per_session = function(
vcpu=1, memory=2, hours=4, participants=20, storage=100
) {
# account for memory/cpu ratio
if(vcpu < 0.05) vcpu=0.05
if(vcpu > 20) vcpu=20
if(memory < 0.1) memory=0.1
if(memory>=110) {
stop("That amount of memory is not available.")
}
# account for memory/cpu ratio
# large memory will scale up vcpu
final_vcpu = vcpu
if(vcpu < memory/6) {
final_vcpu=memory/6
message(paste("vcpu request modified from", vcpu,"to", final_vcpu, "due to memory ratio."))
}
if(final_vcpu>30) {
stop('Memory of vcpu request would result in compute resources not available.')
}
hours*participants*(final_vcpu*0.0455 + 0.0049225*memory+0.0001389*storage)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment