Capabilities for time monitoring and administration

[This article was first published on modTools, and kindly contributed to R-bloggers]. (You may report challenge concerning the content material on this web page right here)


Wish to share your content material on R-bloggers? click on right here you probably have a weblog, or right here should you do not.

Particularly since I needed to begin working as a freelancer, it grew to become important to maintain an correct report of how a lot time I spend on every process and venture. I checked out some software program instruments out there on-line (specifically TimeCamp, which I’ve used for some time), however I made a decision to see if I may write my very own R capabilities for monitoring time use, particularly when working offline (a few of us nonetheless like or have to work offline typically!), and for producing some associated plots and analyses afterwards. Right here’s what I got here up with.

I first have to have a file named “PROJECTS.csv“, with a column named
venture” and a column named “process“, and the names of the tasks and duties I’ll be engaged on, like this:

kind venture process
consulting elephants evaluation
consulting elephants writing
consulting elephants revising
coaching R-GIS making ready
coaching R-GIS educating
experimenting timeman programming
experimenting timeman debugging

I can manually add tasks and duties to this desk at any time. Then I take advantage of the ‘start_task‘ and ‘stop_task‘ capabilities beneath so as to add entries to a different file, which is called “DONT-TOUCH_timeman_data.csv“, has 5 columns (proj, process, begin, cease, time) and will not be moved or modified manually:

tasks <- learn.csv("PROJECTS.csv")
tail(tasks) timeman_data <- learn.csv("DONT-TOUCH_timeman_data.csv", as.is = TRUE)
tail(timeman_data) start_task <- perform(proj, process, time = NULL) { if (nrow(timeman_data) > 0 && is.na(timeman_data[nrow(timeman_data), ncol(timeman_data)])) cease ("earlier process should be stopped earlier than beginning one other") if (!(proj %in% distinctive(tasks$venture))) cease ("proj should exist in 'PROJECTS.csv'") if (!(process %in% distinctive(tasks$process))) cease ("process should exist in 'PROJECTS.csv'") #if (!(proj %in% distinctive(timeman_data$projecto))) #timeman_data[nrow(timeman_data) + 1, "projecto"] <- proj if (is.null(time)) time <- Sys.time() timeman_data[nrow(timeman_data) + 1, 1:3] <- c(proj, process, time) timeman_data <<- timeman_data
} stop_task <- perform(time = NULL) { if (nrow(timeman_data) > 0 && !is.na(timeman_data[nrow(timeman_data), ncol(timeman_data)])) cease ("process should be began earlier than being stopped") if (is.null(time)) time <- Sys.time() #this_row <- which.max(timeman_data$projecto == proj) this_row <- nrow(timeman_data) timeman_data[this_row, "stop"] <- as.character(time) timeman_data[this_row, "time"] <- difftime(timeman_data[this_row, "stop"], timeman_data[this_row, "start"]) timeman_data <<- timeman_data write.csv(timeman_data, "DONT-TOUCH_timeman_data.csv", row.names = FALSE) cat("Displaying final rows in duties desk:nn") tail(timeman_data)
} current_task <- perform() { timeman_data[nrow(timeman_data), ]
}

I would like to make use of ‘start_task‘ each time I begin engaged on a process, after which ‘stop_task‘ each time I cease. This provides an entry with the beginning, stopping, and complete time spent in every occasion:

distinctive(tasks$proj)
distinctive(tasks$process)
distinctive(timeman_data$proj) # ADD START:
start_task(proj = "timeman", process = "debugging")
tail(timeman_data) # ADD STOP:
stop_task()
tail(timeman_data)

I can then apply all types of R analyses and plots to the time-tracking information, which is recorded within the timeman_data information body and CSV file. Nevertheless, these capabilities are actually removed from perfect, as they use “unsafe” operators (like ‘<<-‘) they usually depend on a file remaining untouched in its folder. It’s plain to see how issues may simply go incorrect at any second…. Recommendations welcome on how this may very well be improved and made safer! Whereas this was an attention-grabbing train, I believe I’ll simply keep on with TimeCamp in the interim 🙂

🙂



When you obtained this far, why not subscribe for updates from the positioning? Select your taste: e-mail, twitter, RSS, or fb

Leave a Reply

Your email address will not be published. Required fields are marked *