|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Apprentice |
For some customers I need to provide daily totals in my weekly invoices. I put together a ruby script to process .bex files and return the daily totals per project. You need to export the projects you are interested in from the Billings2 interface and then edit the file name at the bottom of the script.
01/01 Tue Monitor production 0.75 01/02 Wed Scripting server 1.42 01/02 Wed Misc calls 1.90 I will post the script inline below, not sure how the system will handle this format. You can contact me at groupee@de-co-de.com if you want the code in a different format. require 'rexml/document' require 'time' include REXML # Parses a .bex file and groups time slips per project and date. # Outputs the total for the day. class Bi2Daily def initialize @timeSlips = Hash.new() end def processTimeSlip(ts) if ( ts.text == "TimeEntry" ) # find the time slip name timeSlipName = findTimeSlipName(ts) raise "No slip name" unless timeSlipName != nil (startDate, endDate ) = findTimeSlipTimes(ts) raise "Bad time elements" unless startDate != nil && endDate != nil accumulate( timeSlipName, startDate, endDate ) end end # Find the name of the parent project containing the current time slip def findTimeSlipName( ts ) ts.parent.parent.parent.each_element('key') {|k| if k.text == "name" # find the value of the next key bypassing the white space elName = k.next_sibling.next_sibling raise "Bad structure, slip name" unless elName != "string" timeSlipName = elName.text return timeSlipName end } return nil end def findTimeSlipTimes(ts) startDate = nil endDate = nil ts.parent.each_element('date') { |d| kind = d.previous_sibling.previous_sibling.text if kind == "startDateTime" #startDate = d.text[11..18] startDate = Time.parse(d.text) elsif kind == "endDateTime" endDate = Time.parse(d.text) end } return [startDate, endDate] end def accumulate ( timeSlipName, startDate, endDate ) diff = endDate - startDate #puts "Start Date #{startDate}, End Date #{endDate} diff #{diff/3600} }" key = startDate.strftime("%m/%d %a ") if @timeSlips[key] == nil @timeSlips[key] = Hash.new end if @timeSlips[key][timeSlipName] == nil @timeSlips[key][timeSlipName] = 0 end @timeSlips[key][timeSlipName] += diff end def outputDailyReport @timeSlips.sort.each { |a| key=a[0] value=a[1] value.each_pair{ |ts, dur| puts "#{key} #{sprintf("%-28s",ts)} #{sprintf("%.2f",dur/3600)}" } } end def process(filename) file = File.open( filename ); doc = Document.new(file) array = doc.root.elements[1].elements['array'] array.each_element('//dict/string') {|timeSlip| processTimeSlip(timeSlip) } file.close outputDailyReport end end m = Bi2Daily.new m.process("/Users/USER/Desktop/FILE.bex") |
||
|
| Previous Topic | Next Topic | powered by eve community |
| Please Wait. Your request is being processed... |
|

