Skip to content

Commit

Permalink
Create a clock slippage visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
huffyhenry committed Jul 15, 2020
1 parent 3316bbd commit 5dabe76
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
41 changes: 41 additions & 0 deletions R/slippage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
library(readr)
library(dplyr)
library(ggplot2)

# Source files
frames.file <- "../data/csv/frames.csv"
events.file <- "../data/csv/events.csv"
sync.file <- "../data/csv/sync.csv"

# File to save the plot to
out.file <- "../slippage.png"

# Build the plot
read_csv(frames.file, col_types=cols(), progress=FALSE) %>%
filter(object == 0) %>%
left_join(read_csv(sync.file, col_types=cols()), by="frame") %>%
inner_join(read_csv(events.file, col_types=cols()), by="event") %>%
transmute(
half.desc=ifelse(half == 1, "First half", "Second half"),
frame.clock=clock - 45*60*(half - 1),
event.clock=60*minute + second + 0.5 - 45*60*(half - 1),
) %>%
ggplot(aes(x=event.clock/60, y=event.clock-frame.clock)) +
geom_col(position="dodge") +
scale_x_continuous(breaks=c(0, 15, 30, 45), expand=expansion(add=1)) +
scale_y_continuous(breaks=seq(-3, 3, 1)) +
coord_cartesian(xlim=c(0, 50), ylim=c(-3.5, 3.5)) +
theme_bw() +
theme(
panel.grid.major.x=element_blank(),
panel.grid.minor.x=element_blank()
) +
labs(
title="Clock difference between aligned events and frames (seconds)",
x=NULL,
y=NULL
) +
facet_wrap(~half.desc, nrow=2, ncol=1, strip.position="right")

# Save the plot to file
ggsave(out.file)
5 changes: 3 additions & 2 deletions src/Csvs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import qualified NeedlemanWunsch as NW

events2Csv :: [F24.Event Tcb.Coordinates] -> String -> IO ()
events2Csv events filepath = do
let header = "event,x,y,event_type,team,minute,second"
let format = "%d,%d,%d,%s,%d,%d,%d"
let header = "event,x,y,event_type,team,half,minute,second"
let format = "%d,%d,%d,%s,%d,%d,%d,%d"
let e2record e = printf format (F24.eid e)
((Tcb.x . fromJust . F24.coordinates) e)
((Tcb.y . fromJust . F24.coordinates) e)
(F24.eventTypeName e)
(F24.team_id e)
(F24.period_id e)
(F24.min e)
(F24.sec e)
writeFile filepath (unlines (header : map e2record events))
Expand Down

0 comments on commit 5dabe76

Please sign in to comment.