From ede171be4e62053d221a502eb8efdeb0342df682 Mon Sep 17 00:00:00 2001 From: Pol Quintana Date: Wed, 7 Oct 2020 13:34:37 +0400 Subject: [PATCH 1/4] Add script to continuously report to console --- scripts/report_time.rb | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 scripts/report_time.rb diff --git a/scripts/report_time.rb b/scripts/report_time.rb new file mode 100644 index 0000000..4525fbe --- /dev/null +++ b/scripts/report_time.rb @@ -0,0 +1,68 @@ +# This script will output the accumulated time you've spend building projects on Xcode within the current day. +# +# Output looks like: +# ********* +# You've spent 27min 24s building .xcworkspace today +# +# +# To use it: +# 1. Follow the installation process from https://github.com/PaulTaykalo/xcode-time-tracker +# 2. Copy this script to `~/.timecheck` folder. +# 3. Run `ruby ~/.timecheck/report_time.rb` +# +# This is a never ending script that will keep reporting updated times as soon as a build/run is finished. +# To stop it, just use Ctrl+C + +require 'Listen' +require 'Date' + +path = "#{Dir.home}/.timecheck" + +def report_time(path) + data = File.read("#{path}/results") + rows = data.split("\n") + + projects = {} + + for i in 0...rows.count + values = rows[i].split(",") + project = (values[0].include? "xcodeproj") ? values[0] : nil + workspace = (values[1].include? "xcworkspace") ? values[1] : nil + start = values[3] + event = values[4] + duration = values[5] + + object = { + "event": event, + "start": start, + "duration": duration + } + + project_name = project ||= workspace + projects[project_name] = (projects[project_name] ||= []).append(object) + end + + puts "*********" + projects.each do |project, events| + time_spent_on_build = 0 + for i in 0...events.count + event = events[i] + date = Date.strptime(event[:start].to_s, '%s') + if date == Date.today + time_spent_on_build += event[:duration].to_i + end + end + seconds = time_spent_on_build % 60 + minutes = time_spent_on_build / 60 + + puts "You've spent #{minutes}min #{seconds}s building #{project} today" + end +end + +report_time(path) + +listener = Listen.to(path) { |modified, added, removed| + report_time(path) +} +listener.start +sleep \ No newline at end of file From f058342d2976e417ec035ebd23188006ddd4e735 Mon Sep 17 00:00:00 2001 From: Pol Quintana Date: Wed, 7 Oct 2020 13:45:26 +0400 Subject: [PATCH 2/4] Update README with documentation --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 4d2fa3f..ffc67f3 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,17 @@ No project,HeyYouAreAwesome.xcworkspace,1597876725,1597876729,Build Succeeded,4 ``` # Visualization + +## Console +Run `ruby ~/.timecheck/report_time.rb` + +This script will output the accumulated time you've spend building projects on Xcode within the current day, separated by project. +It will keep reporting updated times as soon as a build/run is finished. +To stop it, just use `Ctrl+C` + +Screen Shot 2020-10-07 at 1 41 22 PM + +## Graphically The next step is to visualize this information. I used [R](https://www.r-project.org/about.html) language for that. But there's more coming This how it can look like if you'll be able to setup R correcly :) From 71f7199bba1ac6f512b185c9091927b51e17e313 Mon Sep 17 00:00:00 2001 From: Pol Quintana Date: Wed, 7 Oct 2020 13:49:39 +0400 Subject: [PATCH 3/4] Update report_time.rb --- scripts/report_time.rb | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/scripts/report_time.rb b/scripts/report_time.rb index 4525fbe..e4bb835 100644 --- a/scripts/report_time.rb +++ b/scripts/report_time.rb @@ -1,15 +1,5 @@ # This script will output the accumulated time you've spend building projects on Xcode within the current day. # -# Output looks like: -# ********* -# You've spent 27min 24s building .xcworkspace today -# -# -# To use it: -# 1. Follow the installation process from https://github.com/PaulTaykalo/xcode-time-tracker -# 2. Copy this script to `~/.timecheck` folder. -# 3. Run `ruby ~/.timecheck/report_time.rb` -# # This is a never ending script that will keep reporting updated times as soon as a build/run is finished. # To stop it, just use Ctrl+C @@ -65,4 +55,4 @@ def report_time(path) report_time(path) } listener.start -sleep \ No newline at end of file +sleep From d6bebac3b0dc93cae7ac3162e88e0bbebb696cb2 Mon Sep 17 00:00:00 2001 From: Pol Quintana Date: Tue, 8 Dec 2020 19:34:57 +0400 Subject: [PATCH 4/4] Update script to not show projects with accumlated time today --- {scripts => visualization/ruby}/report_time.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) rename {scripts => visualization/ruby}/report_time.rb (86%) diff --git a/scripts/report_time.rb b/visualization/ruby/report_time.rb similarity index 86% rename from scripts/report_time.rb rename to visualization/ruby/report_time.rb index e4bb835..c4254f3 100644 --- a/scripts/report_time.rb +++ b/visualization/ruby/report_time.rb @@ -42,10 +42,13 @@ def report_time(path) time_spent_on_build += event[:duration].to_i end end - seconds = time_spent_on_build % 60 - minutes = time_spent_on_build / 60 + seconds = time_spent_on_build % 60 + minutes = time_spent_on_build / 60 - puts "You've spent #{minutes}min #{seconds}s building #{project} today" + if seconds == 0 && minutes == 0 + next + end + puts "You've spent #{minutes}min #{seconds}s building #{project} today" end end @@ -55,4 +58,4 @@ def report_time(path) report_time(path) } listener.start -sleep +sleep \ No newline at end of file