Skip to content

Instantly share code, notes, and snippets.

@elepl94
Last active December 2, 2022 14:16
Show Gist options
  • Save elepl94/e6c5d55f94bd39dd3fffb718052a071a to your computer and use it in GitHub Desktop.
Save elepl94/e6c5d55f94bd39dd3fffb718052a071a to your computer and use it in GitHub Desktop.

Convert Pupil Time to System Time in RStudio

This script shows how to convert Pupil Time to System Time and store timestamps in DateTime format.

# Load packages
library(readr)
library(tidyr)
library(lubridate)
# Load the desired .csv and info.player.json files from Pupil Player exports
data <- read_csv("../../../../data.csv")
info_player <- read_csv("../../info.player.json")
start_time_system <- extract_numeric(info_player[9,]) #System Time at recording start
start_time_synced <- extract_numeric(info_player[8,]) #Pupil Time at recording start
# Calculate the fixed offset between System and Pupil Time
offset <- start_time_system - start_time_synced
# Add the fixed offset to the timestamp(s) we wish to convert
data$system_timestamp <- data$pupil_timestamp+offset
# Convert System Time timestamps in datetime format
data$datetime <- as_datetime(data$system_timestamp, tz="UTC") #change tz accordingly to your timezone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment