Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Console visualization option #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

<img width="702" alt="Screen Shot 2020-10-07 at 1 41 22 PM" src="https://user-images.githubusercontent.com/7887319/95315175-36fa5900-08a3-11eb-87cd-f48e5cf36f14.png">

## 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 :)
Expand Down
61 changes: 61 additions & 0 deletions visualization/ruby/report_time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This script will output the accumulated time you've spend building projects on Xcode within the current day.
#
# 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

if seconds == 0 && minutes == 0
next
end
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