R/state.R

# Singlearity Baseball API
#
# Baseball optimization API using machine learning
#
# The version of the OpenAPI document: 0.1.1
# 
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title State
#'
#' @description State Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field on_1b On 1B character [optional]
#'
#' @field on_2b On 2B character [optional]
#'
#' @field on_3b On 3B character [optional]
#'
#' @field inning Inning integer [optional]
#'
#' @field outs Outs integer [optional]
#'
#' @field top Top character [optional]
#'
#' @field bat_score Bat Score integer [optional]
#'
#' @field fld_score Fld Score integer [optional]
#'
#' @field bat_lineup_order Bat Lineup Order integer [optional]
#'
#' @field fld_lineup_order Fld Lineup Order integer [optional]
#'
#' @field pitch_number Pitch Number integer [optional]
#'
#' @field frame_runs_scored Frame Runs Scored integer [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
State <- R6::R6Class(
  'State',
  public = list(
    `on_1b` = NULL,
    `on_2b` = NULL,
    `on_3b` = NULL,
    `inning` = NULL,
    `outs` = NULL,
    `top` = NULL,
    `bat_score` = NULL,
    `fld_score` = NULL,
    `bat_lineup_order` = NULL,
    `fld_lineup_order` = NULL,
    `pitch_number` = NULL,
    `frame_runs_scored` = NULL,
    initialize = function(
        `on_1b`=FALSE, `on_2b`=FALSE, `on_3b`=FALSE, `inning`=1, `outs`=0, `top`=TRUE, `bat_score`=0, `fld_score`=0, `bat_lineup_order`=1, `fld_lineup_order`=1, `pitch_number`=0, `frame_runs_scored`=0, ...
    ) {
      local.optional.var <- list(...)
      if (length(local.optional.var) > 0) {
        stop(paste("Unknown argument(s) in initialize of object State:", paste(names(local.optional.var), collapse=", "), collapse=" "))
      }
      if (!is.null(`on_1b`)) {
        self$`on_1b` <- `on_1b`
      }
      if (!is.null(`on_2b`)) {
        self$`on_2b` <- `on_2b`
      }
      if (!is.null(`on_3b`)) {
        self$`on_3b` <- `on_3b`
      }
      if (!is.null(`inning`)) {
        stopifnot(is.numeric(`inning`), length(`inning`) == 1)
        self$`inning` <- `inning`
      }
      if (!is.null(`outs`)) {
        stopifnot(is.numeric(`outs`), length(`outs`) == 1)
        self$`outs` <- `outs`
      }
      if (!is.null(`top`)) {
        self$`top` <- `top`
      }
      if (!is.null(`bat_score`)) {
        stopifnot(is.numeric(`bat_score`), length(`bat_score`) == 1)
        self$`bat_score` <- `bat_score`
      }
      if (!is.null(`fld_score`)) {
        stopifnot(is.numeric(`fld_score`), length(`fld_score`) == 1)
        self$`fld_score` <- `fld_score`
      }
      if (!is.null(`bat_lineup_order`)) {
        stopifnot(is.numeric(`bat_lineup_order`), length(`bat_lineup_order`) == 1)
        self$`bat_lineup_order` <- `bat_lineup_order`
      }
      if (!is.null(`fld_lineup_order`)) {
        stopifnot(is.numeric(`fld_lineup_order`), length(`fld_lineup_order`) == 1)
        self$`fld_lineup_order` <- `fld_lineup_order`
      }
      if (!is.null(`pitch_number`)) {
        stopifnot(is.numeric(`pitch_number`), length(`pitch_number`) == 1)
        self$`pitch_number` <- `pitch_number`
      }
      if (!is.null(`frame_runs_scored`)) {
        stopifnot(is.numeric(`frame_runs_scored`), length(`frame_runs_scored`) == 1)
        self$`frame_runs_scored` <- `frame_runs_scored`
      }
    },
    toJSON = function() {
      StateObject <- list()
      if (!is.null(self$`on_1b`)) {
        StateObject[['on_1b']] <-
          self$`on_1b`
      }
      if (!is.null(self$`on_2b`)) {
        StateObject[['on_2b']] <-
          self$`on_2b`
      }
      if (!is.null(self$`on_3b`)) {
        StateObject[['on_3b']] <-
          self$`on_3b`
      }
      if (!is.null(self$`inning`)) {
        StateObject[['inning']] <-
          self$`inning`
      }
      if (!is.null(self$`outs`)) {
        StateObject[['outs']] <-
          self$`outs`
      }
      if (!is.null(self$`top`)) {
        StateObject[['top']] <-
          self$`top`
      }
      if (!is.null(self$`bat_score`)) {
        StateObject[['bat_score']] <-
          self$`bat_score`
      }
      if (!is.null(self$`fld_score`)) {
        StateObject[['fld_score']] <-
          self$`fld_score`
      }
      if (!is.null(self$`bat_lineup_order`)) {
        StateObject[['bat_lineup_order']] <-
          self$`bat_lineup_order`
      }
      if (!is.null(self$`fld_lineup_order`)) {
        StateObject[['fld_lineup_order']] <-
          self$`fld_lineup_order`
      }
      if (!is.null(self$`pitch_number`)) {
        StateObject[['pitch_number']] <-
          self$`pitch_number`
      }
      if (!is.null(self$`frame_runs_scored`)) {
        StateObject[['frame_runs_scored']] <-
          self$`frame_runs_scored`
      }

      StateObject
    },
    fromJSON = function(StateJson) {
      StateObject <- jsonlite::fromJSON(StateJson)
      if (!is.null(StateObject$`on_1b`)) {
        self$`on_1b` <- StateObject$`on_1b`
      }
      if (!is.null(StateObject$`on_2b`)) {
        self$`on_2b` <- StateObject$`on_2b`
      }
      if (!is.null(StateObject$`on_3b`)) {
        self$`on_3b` <- StateObject$`on_3b`
      }
      if (!is.null(StateObject$`inning`)) {
        self$`inning` <- StateObject$`inning`
      }
      if (!is.null(StateObject$`outs`)) {
        self$`outs` <- StateObject$`outs`
      }
      if (!is.null(StateObject$`top`)) {
        self$`top` <- StateObject$`top`
      }
      if (!is.null(StateObject$`bat_score`)) {
        self$`bat_score` <- StateObject$`bat_score`
      }
      if (!is.null(StateObject$`fld_score`)) {
        self$`fld_score` <- StateObject$`fld_score`
      }
      if (!is.null(StateObject$`bat_lineup_order`)) {
        self$`bat_lineup_order` <- StateObject$`bat_lineup_order`
      }
      if (!is.null(StateObject$`fld_lineup_order`)) {
        self$`fld_lineup_order` <- StateObject$`fld_lineup_order`
      }
      if (!is.null(StateObject$`pitch_number`)) {
        self$`pitch_number` <- StateObject$`pitch_number`
      }
      if (!is.null(StateObject$`frame_runs_scored`)) {
        self$`frame_runs_scored` <- StateObject$`frame_runs_scored`
      }
      self
    },
    toJSONString = function() {
      jsoncontent <- c(
        if (!is.null(self$`on_1b`)) {
        sprintf(
        '"on_1b":
          "%s"
                ',
        self$`on_1b`
        )},
        if (!is.null(self$`on_2b`)) {
        sprintf(
        '"on_2b":
          "%s"
                ',
        self$`on_2b`
        )},
        if (!is.null(self$`on_3b`)) {
        sprintf(
        '"on_3b":
          "%s"
                ',
        self$`on_3b`
        )},
        if (!is.null(self$`inning`)) {
        sprintf(
        '"inning":
          %d
                ',
        self$`inning`
        )},
        if (!is.null(self$`outs`)) {
        sprintf(
        '"outs":
          %d
                ',
        self$`outs`
        )},
        if (!is.null(self$`top`)) {
        sprintf(
        '"top":
          "%s"
                ',
        self$`top`
        )},
        if (!is.null(self$`bat_score`)) {
        sprintf(
        '"bat_score":
          %d
                ',
        self$`bat_score`
        )},
        if (!is.null(self$`fld_score`)) {
        sprintf(
        '"fld_score":
          %d
                ',
        self$`fld_score`
        )},
        if (!is.null(self$`bat_lineup_order`)) {
        sprintf(
        '"bat_lineup_order":
          %d
                ',
        self$`bat_lineup_order`
        )},
        if (!is.null(self$`fld_lineup_order`)) {
        sprintf(
        '"fld_lineup_order":
          %d
                ',
        self$`fld_lineup_order`
        )},
        if (!is.null(self$`pitch_number`)) {
        sprintf(
        '"pitch_number":
          %d
                ',
        self$`pitch_number`
        )},
        if (!is.null(self$`frame_runs_scored`)) {
        sprintf(
        '"frame_runs_scored":
          %d
                ',
        self$`frame_runs_scored`
        )}
      )
      jsoncontent <- paste(jsoncontent, collapse = ",")
      paste('{', jsoncontent, '}', sep = "")
    },
    fromJSONString = function(StateJson) {
      StateObject <- jsonlite::fromJSON(StateJson)
      self$`on_1b` <- StateObject$`on_1b`
      self$`on_2b` <- StateObject$`on_2b`
      self$`on_3b` <- StateObject$`on_3b`
      self$`inning` <- StateObject$`inning`
      self$`outs` <- StateObject$`outs`
      self$`top` <- StateObject$`top`
      self$`bat_score` <- StateObject$`bat_score`
      self$`fld_score` <- StateObject$`fld_score`
      self$`bat_lineup_order` <- StateObject$`bat_lineup_order`
      self$`fld_lineup_order` <- StateObject$`fld_lineup_order`
      self$`pitch_number` <- StateObject$`pitch_number`
      self$`frame_runs_scored` <- StateObject$`frame_runs_scored`
      self
    }
  )
)
singlearity-sports/singlearity-R documentation built on April 21, 2022, 3:48 a.m.