Last active
August 29, 2015 14:16
-
-
Save rnelson/4194684d519fecc03185 to your computer and use it in GitHub Desktop.
togglpie - build a pie chart from toggl.com CSV export showing percentage of time spent on projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
# | |
# usage: ./togglpie.R Toggl_projects_2015-03-09_to_2015-03-15.csv week12.png | |
# | |
# Change "YOUR CLIENT HERE" to the name of the client. To do all clients, | |
# remove the if statement (leaving the two lines in the body) | |
# Read the command line arguments | |
args <- commandArgs(trailingOnly = TRUE) | |
input = args[1] | |
output = args[2] | |
# Read the data and strip out the Total: row | |
data <- read.csv(file=input, head=TRUE, as.is=TRUE, sep=",") | |
count <- length(data$Project) | |
data <- data[-c(count),] | |
count <- count - 1 | |
# Get all of our data into vectors | |
mat <- as.matrix(data) | |
clients <- c(mat[,1]) | |
projects <- c(mat[,2]) | |
totals <- c(mat[,11]) | |
# Gather information about the week | |
times <- c() | |
labels <- c() | |
for (i in seq(1:count)) { | |
client <- clients[i] | |
project <- projects[i] | |
total <- totals[i] | |
row = c(client, project, total) | |
if (grepl("YOUR CLIENT HERE", client)) { | |
times <- c(times, total) | |
labels <- c(labels, project) | |
} | |
} | |
# Convert hh:mm to decimal time | |
times <- sapply(strsplit(times, ":"), | |
function(x) { | |
x <- as.numeric(x) | |
x[1]+x[2]/60 | |
} | |
) | |
# Show percentages | |
pct <- round(times / sum(times, na.rm=TRUE) * 100) | |
labels <- paste(labels, pct) # add percents to labels | |
labels <- paste(labels, "%", sep="") # ad % to labels | |
# Create a pie chart | |
png(filename=output) | |
pie(times, labels=labels, col=rainbow(length(labels)), main="Work") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment