Skip to content

Commit

Permalink
Improve USAGE file and improve disposition of table width for report
Browse files Browse the repository at this point in the history
  • Loading branch information
marklazz committed Jun 24, 2010
1 parent c0cb5ab commit a578fb6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 21 deletions.
56 changes: 47 additions & 9 deletions USAGE.txt
@@ -1,13 +1,51 @@

RTT is a tool for tracking time. It's primary extend is to be used from command line.
=====================================================================================

Usage:

rtt start <task-name>
rtt pause
rtt stop
rtt user <nickname>
rtt client <client-name>
rtt project <project-name>
rtt rename <new-name-current-task>
rtt list
rtt report <filename>.pdf
- rtt start <task-name> | rtt <task-name>

Starts a new task (or existing task with that name) for the current project/client/user.

- rtt pause

Pauses the current task.

- rtt resume

Resumes the last paused task.

- rtt stop

Stops the current task.

- rtt user <nickname>

Changes the current user. If there is no user with the nickname specified it ask for user information interactivly.

- rtt client <client-name>

Sets the current client with with name specified (creates one client if there no client stored with that name).

- rtt project <project-name>

Sets the current project with the specified name.

- rtt rename <new-name-current-task>

Rename current task

- CLIENT=some_client rtt list | CLIENT=some_client PROJECT=some_project rtt list | PROJECT=some_project rtt list

List all tasks created for the filters provided.

- rtt report <filename>

Generates a report to be stored on on the path specified.

- rtt configure (client|project|user|task)

Allows to change properties of current objects.

Enjoy!
39 changes: 27 additions & 12 deletions lib/rtt/report_generator.rb
Expand Up @@ -17,6 +17,17 @@ module ReportGenerator
'Duration' => Proc.new { |task| task.duration }
}

def column_widths(fixed_fields)
case fixed_fields.length
when 2
{ 0 => 360, 1 => 60, 2 => 60, 3 => 60 } # total = 540 px
when 1
{ 0 => 80, 1 => 290, 2 => 60, 3 => 50, 4 => 60 }
else
{ 0 => 80, 1 => 80, 2 => 210, 3 => 60, 4 => 50, 5 => 60 }
end
end

def custom_user_is_defined?
current_user.present? && current_user.nickname != Rtt::User::DEFAULT_NICK
end
Expand Down Expand Up @@ -99,21 +110,23 @@ def report options = {}

private

def amount(rate, h, m)
rate.to_f * (h.to_f + (m.to_f / 60))
def amount(rate, minutes)
rate.to_f * (minutes.to_f / 60)
end

def calculate_total_amount_hours_and_minutes(data)
data.inject([0, 0, 0]) do |totals, task|
total_a, total_h, total_m = totals
total_amount, total_minutes = data.inject([0, 0]) do |totals, task|
total_a, total_m = totals
if task[5 - fixed_fields_for_current_data.length].to_s.match(/^(\d+)h(\d+)m$/)
total_m += ($2.to_i % 60)
total_h += ($1.to_i + $2.to_i / 60)
minutes = $2.to_i
minutes += ($1.to_i * 60)
total_m += minutes
rate = task[4 - fixed_fields_for_current_data.length]
total_a += amount(rate, total_h, total_m)
total_a += amount(rate, minutes)
end
[ total_a, total_h, total_m ]
[ total_a, total_m ]
end
[total_amount, total_minutes / 60, total_minutes % 60]
end

def extract_fixed_fields(options)
Expand Down Expand Up @@ -156,21 +169,23 @@ def report_to_pdf output_path
font_size 16
move_down 30

report_generator.fixed_fields_for_current_data.each do |field|
fixed_fields = report_generator.fixed_fields_for_current_data
fixed_fields.each do |field|
text("#{field}: #{report_generator.fixed_value(field)}") unless report_generator.has_default_value?(field)
end

move_down(report_generator.custom_user_is_defined? ? 40 : 0)
move_down(report_generator.custom_user_is_defined? ? 50 : 0)

if data.present?
table data,
table(data,
:headers => columns,
:position => :left,
:border_width => 1,
:row_colors => [ 'fafafa', 'f0f0f0' ],
:column_widths => report_generator.column_widths(fixed_fields),
:font_size => 12,
:padding => 5,
:align => :left
:align => :left)
end

move_down 20
Expand Down

0 comments on commit a578fb6

Please sign in to comment.