#! /usr/bin/ruby require 'yaml' require 'times_models.rb' require 'optparse' $options = {} oparser = OptionParser.new oparser.on( '-H', '--host HOST', 'RDBMS host', String ) { |o| $options[:host] = o } oparser.on( '-u', '--user USERNAME', String ) { |o| $options[:user] = o } oparser.on( '-p', '--pass PASSWORD', String ) { |o| $options[:password] = o } oparser.on( '-t', '--table TABLE', 'Table to display', String ) { |o| $options[:table] = o } oparser.on( '-d', '--database DATABASE', 'Database name', String ) { |o| $options[:database] = o } oparser.on( '-D', '-v', '--debug' ) { |o| $options[:debug] = true } oparser.on( '-h', '-?', '--help' ) do |o| puts oparser.to_s exit( 0 ) end oparser.parse!( ARGV ) require 'clevic/db_options.rb' puts "using database #{ActiveRecord::Base.connection.raw_connection.db}" if $options[:debug] st = if ARGV[0].nil? raise ( "provide a yml file that looks like this: " + <|] 28-apr-2008: stackpro: - [20h01, 23h03, Research on using Matrices for stackpro] 29-apr-2008: stackpro: - [20h01, 22h43, Working on Stackpro] - [23h02, 23h30, More on test cases] clevic: - [22h43, 23h02, yaml for times] 30-apr-2008: stackpro: - [19h45, 21h10, Trying both directions] - [21h10, 21h59, Has to be a pull pipeline] - [21h59, 23h00, get 3 ops working] - [23h00, 23h55, do stack algorithm] 01-may-2008: stackpro: - [18h54, 20H34, fighting with eof] 02-may-2008: stackpro: - [07h50, 08h32, fighting with eof] - [19h23, 20h09, simplify testing] - [21h03, 22h30, do stackpro bin] 03-may-2008: stackpro: - [07h50, 08h32, fighting with eof] unwreck: - [12h50, 15h05, start project. Do some initial coding and testing.] 04-may-2008: unwreck: - [19h11, 19h31, find a way to store the jobs] - [21h15, 21h34, find a way to store the jobs] - [21h34, 23h01, Do DirectoryStorage. Improve sampling.] - [23h01, 23h18, Ask for force for pre-existing job.] 05-may-2008: unwreck: - [13h32, 14h15, build index] - [20h30, 22h05, fetch using index and compare] - [22h05, 22h53, doing file cleanups and serialisation] 19-may-2008: unwreck: - [12h30, 12h50, Travel to CIM (because Warren missed the meeting)] - [12h50, 13h20, Chat to Gavin, no] - [13h20, 15h40, Work on stackpro and unwreck] - [15h40, 16h05, Travel home] - [22h03, 22h42, Work on stackpro] 21-may-2008: unwreck: - [6h30, 7h21, start on header line] - [8h55, 10h36, finish header line] EOF else File.read( ARGV[0] ) end def process( data_structure ) Entry.transaction do coding = Activity.find_by_activity 'Coding' data_structure.keys.each do |key| date = Date.parse( key ) day = data_structure[key] day.keys.each do |project_key| project = Project.find_by_project project_key raise "project #{project_key} not in database" if project.nil? invoice = project.latest_invoice times = day[project_key] times.each do |entry_arr| entry = Entry.new( :project => project, :invoice => invoice, :date => date, :rate => project.rate ) entry.start = entry_arr[0] entry.end = entry_arr[1] entry.description = entry_arr[2] if entry_arr[3] == true || entry_arr[3] == false entry.charge = entry_arr[3] else entry.activity = entry_arr[3] || coding end entry.save puts "entry: #{entry.inspect}" end end end end end process( YAML.load( st ) )