hawkinR

Get your data from the Hawkin Dynamics API

hawkinR provides simple functionality with Hawkin Dynamics API. These functions are for use with ‘Hawkin Dynamics Beta API’ version 1.14-beta. You must be an Hawkin Dynamics user with active integration account to utilize functions within the package.

Installation

You can install the development version of hawkinR from GitHub with:

# install.packages("devtools")
# devtools::install_github("HawkinDynamics/hawkinR")
install.packages("hawkinR", repos = c('https://hawkindynamics.r-universe.dev', 'https://cloud.r-project.org'))

Functions

This API is designed to get data out of your Hawkin Dynamics database into your own database. It is not designed to be accessed from client applications directly. There is a limit on the amount of data that can be returned in a single request. As your database grows, it will be necessary to use the from and to parameters to limit the size of the responses. Responses that exceed the memory limit will fail. It is advised that you design your client to handle this from the beginning. A recommended pattern would be to have two methods of fetching data. A scheduled pull that uses the from and to parameters to constrain the returned data to only tests that have occurred since the last fetch e.g. every day or every 5 minutes. And then a pull that fetches the entire database since you began testing that is only executed when necessary. A recommended way of doing this is to generate the from and to parameters for each month since you started and send a request for each either in parallel or sequentially.

This package was meant to help execute requests to the Hawkin Dynamics API with a single line of code. There are 11 functions to help execute 4 primary objectives:

Get Access

Get Test Types

Get Organization Data

Get Test Data

Previous variations of get_tests_ (found in versions < hawkinR v1.1.0) have been deprecated and are to be phased out in future updates. See get_tests() for the preferred function.

Example

This is a basic example which shows common workflow:

library(hawkinR) 


#------------------------------------------------------------------------------------#
# 1. Get access to your site
#------------------------------------------------------------------------------------#


## Store you secret API key
refreshToken <- 'your-secret-api-key'

## Get access token. When successful, access token is stored for use in the session.
get_access("refreshToken", region = "Americas")


#------------------------------------------------------------------------------------#
# 2. Get Org data
#------------------------------------------------------------------------------------#

## Team data frame
teamList <- get_teams()

## Create list of teams
teamIds <- paste0(teamList$id[1],teamList$id[3],teamList$id[4])

## Athlete data frame
athList <- get_athletes()

## Create athleteId
athId <- athList$id[6]

#------------------------------------------------------------------------------------#
# 3. Get Test Data
#------------------------------------------------------------------------------------#

## Initial test call
allTests <- get_tests()

## Create last test or sync date
lastSync <- max(allTests$lastSyncTime)

## Create phase to review with timestamp from records
phaseDate1 <- allTests$timestamp[30] # from dateTime
phaseDate2 <- allTests$timestamp[10] # to dateTime

## Dates can also be entered as character strings in "YYYY-MM-DD" format
phaseDate1_string <- "2024-01-01"
phaseDate2_string <- "2024-06-01"

## Sync tests since a time point.
df_SyncFrom <- get_tests(from = lastSync, sync = TRUE)

## Get tests by athlete in time frame.
df_athTests <- get_tests(athleteId = athId, from = phaseDate1, to = phaseDate2)

## Get all tests by team
df_teamTests <- get_tests(teamId = teamIds)

## Get test force-time data
df_forceData <- get_forcetime(testId = df_athTests$id[10])