Permalink
Browse files

updated import of v1 files

  • Loading branch information...
1 parent bccb836 commit a06c1e93f4616c7c8641aeb26756cd73f2f3896c @sundbp committed Nov 19, 2009
Showing with 77 additions and 48 deletions.
  1. +5 −9 convert_to_csv-v1.rb
  2. +20 −0 generate_13_weeks_for_bh.rb
  3. +19 −15 import_legacy_data.rb
  4. +15 −13 merge_dumps.rb
  5. +18 −11 parse_csv-v1.rb
View
@@ -1,25 +1,21 @@
require 'rubygems'
require 'roo'
-files = [
- '01 Worklog RAW DATA - 28.07.09 to 03.01.09_HL.xls',
- '02 Worklog RAW DATA - 03.01.09 to 04.04.09_HL.xls',
- '03 Worklog RAW DATA - 04.04.09 to 27.06.09_HL.xls'
-];
+tabs_to_convert = ["JH", "AB", "JO", "RH", "ES", "HL", "NK", "MS", "GB", "AC", "DY", "MW"];
-tabs_to_convert = ["JH", "AB", "JO", "RH", "ES", "HL", "NK", "MS", "GB", "AC"];
-
-files.each do |fname|
+counter = 1
+Dir[File.join(ARGV[0],'*.xls')].each do |fname|
doc = Excel.new(fname)
tabs_to_convert.each do |tab|
begin
doc.default_sheet = tab
- doc.to_csv("output/" + tab + " - " + fname[0..-4]+"csv")
+ doc.to_csv(ARGV[0]+"/output/" + tab + " - " + counter.to_s + ".csv")
rescue Exception => e
print e.to_s + "\n"
next
end
end
print "Converted file: " + fname + "\n"
+ counter += 1
end
@@ -0,0 +1,20 @@
+#!/usr/bin/env /Users/patrik/RubymineProjects/jrbh-worklog/script/runner -e production
+
+USER = "BH"
+COMMIT = false
+
+u = User.find_by_alias("BH")
+t = WorklogTask.find_by_name("Spring Break")
+s = Date.new(2009,5,25).to_time
+e = Date.new(2009,8,17).to_time
+
+(s..e).step(7.days) do |x|
+ start_t = x.to_time + 9.hours
+ end_t = start_t + 8.hours
+ print "\n(#{start_t}-#{end_t}) #{u.alias} - #{t.name}\n"
+ WorkPeriod.create(:user_id => u.id, :worklog_task_id => t.id, :start => start_t, :end => end_t, :comment => "2days a week import") if COMMIT
+ start_t += 1.day
+ end_t += 1.day
+ print "(#{start_t}-#{end_t}) #{u.alias} - #{t.name}\n"
+ WorkPeriod.create(:user_id => u.id, :worklog_task_id => t.id, :start => start_t, :end => end_t, :comment => "2days a week import") if COMMIT
+end
View
@@ -1,5 +1,11 @@
#!/usr/bin/env /Users/patrik/RubymineProjects/jrbh-worklog/script/runner -e production
+USER = "all-users"
+PRINT = true
+COMMIT = false
+D_START = Date.new(2008,7,28)
+D_END = Date.new(2009,7,4)
+
# change this path to where your dump is
data_dump_file = "/Users/patrik/Documents/Worklog/worklog_total.dump"
task_company_file = "/Users/patrik/Documents/Worklog/worklog_task_company.dump"
@@ -21,7 +27,7 @@
alias_to_user.each_pair do |key,value|
next if User.find_by_alias(key)
admin = admins.include? key
- #User.create(:login => value, :alias => key, :admin => admin)
+ User.create(:login => value, :alias => key, :admin => admin) if COMMIT
print "Created user '#{key}'\n"
end
@@ -33,15 +39,15 @@
#create companies
task_to_company.values.uniq.sort.each do |c|
next if Company.find_by_name(c)
- #Company.create(:name => c)
+ Company.create(:name => c) if COMMIT
print "Created company '#{c}'\n"
end
#create worklog tasks
task_to_company.each_pair do |task,company|
next if WorklogTask.find_by_name(task)
c = Company.find_by_name(company)
- #WorklogTask.create(:name => task, :company_id => c.id)
+ WorklogTask.create(:name => task, :company_id => c.id) if COMMIT
print "Created worklog task '#{task}'\n"
end
@@ -50,26 +56,24 @@
data = Marshal.load(f)
end
-USER = "JH"
-COMMIT = false
-D_START = Date.new(2009,2,28)
-D_END = Date.new(2009,3,14)
i = 0
data.each do |x|
- next unless x.user == USER and x.start >= D_START and x.end <= D_END
- t = WorklogTask.find_by_name(x.task)
- print "(#{x.start}-#{x.end}) #{x.user} - #{x.task}\n"
- next unless COMMIT
+ if USER == "all-users"
+ next unless x.start >= D_START and x.end <= D_END
+ else
+ next unless x.user == USER and x.start >= D_START and x.end <= D_END
+ end
+ t = WorklogTask.find_by_name(x.task)
+ print "(#{x.start}-#{x.end}) #{x.user} - #{x.task}\n" if PRINT
- u = User.find_by_alias(x.user)
+ u = User.find_by_alias(x.user)
unless u
- User.create(:login => x.user+"login", :alias => x.user, :admin => false)
+ User.create(:login => x.user+"login", :alias => x.user, :admin => false) if COMMIT
u = User.find_by_alias(x.user)
end
-
- WorkPeriod.create(:user_id => u.id, :worklog_task_id => t.id, :start => x.start, :end => x.end, :comment => x.comment)
+ WorkPeriod.create(:user_id => u.id, :worklog_task_id => t.id, :start => x.start, :end => x.end, :comment => x.comment) if COMMIT
i = i + 1
end
print "Creataed #{i} work periods.\n"
View
@@ -1,22 +1,24 @@
WorkPeriodStruct = Struct.new(:start,:end,:user,:task,:comment)
-o1 = nil
-o2 = nil
-File.open("worklog-v1-data/worklog1.dump") do |f|
- o1 = Marshal.load(f)
+dumps = []
+Dir['*/*.dump'].each do |fname|
+ print "adding #{fname}:\n"
+ File.open(fname) do |f|
+ dumps << Marshal.load(f)
+ end
end
-File.open("worklog-v2-data/worklog2.dump") do |f|
- o2 = Marshal.load(f)
+dumps.each do |o|
+ o.sort! do |a,b| a.start <=> b.start end
+ print "Range of data is: " + o[0].start.to_s + " - " + o[-1].end.to_s + "\n"
end
-o1.sort! do |a,b| a.start <=> b.start end
-o2.sort! do |a,b| a.start <=> b.start end
-print "Range of data is: " + o1[0].start.to_s + " - " + o1[-1].end.to_s + "\n"
-print "Range of data is: " + o2[0].start.to_s + " - " + o2[-1].end.to_s + "\n"
-
-data = o1.concat(o2)
+data = dumps.first
+dumps.each do |o|
+ next if data == o
+ data = data.concat(o)
+end
data.sort! do |a,b| a.start <=> b.start end
print "We have " + data.size.to_s + " records of data\n"
@@ -37,7 +39,7 @@
end
-File.open('worklog_total.dump', "w+" ) do |f|
+File.open(ARGV[0], "w+" ) do |f|
Marshal.dump(data, f)
end
View
@@ -3,7 +3,7 @@
WorkPeriodStruct = Struct.new(:start,:end,:user,:task,:comment)
-relative_path = "./output/"
+relative_path = File.join(ARGV[0],"output")
parsed_data = []
@@ -24,7 +24,7 @@
ends = []
tasks = []
comments = []
- File.new(relative_path+fname).each_line do |line|
+ File.new(File.join(relative_path, fname)).each_line do |line|
parts = line.split(',')
if found_week_start
if skip_1 > 0
@@ -72,14 +72,16 @@
#starts.each {|x| p x.to_s }
#p "ends"
#ends.each {|x| p x.to_s }
-
+
+ separators = ["1", "0.5"]
# create a WorkPeriod object
(1..parts.size-1).each do |d|
- if parts[d] == "0.5"
+ if separators.include? parts[d]
+ separator = parts[d]
tasks << parts[d-1].gsub('"', "")
comment_parts = [];
x = d-2;
- while parts[x] != "0.5" and not parts[x].match(/\d+.\d+-\d+.\d+/)
+ while parts[x] != separator and not parts[x].match(/\d+.\d+-\d+.\d+/)
comment_parts << parts[x].gsub('"', "")
x = x-1
end
@@ -103,12 +105,12 @@
d = nil
if matchdata
date_strings << parts
- if parts[0].match(/"WEEK COMMENCING - (\d\d.\d\d.\d\d)"/)
- mdata = parts[0].match(/"WEEK COMMENCING - (\d\d.\d\d.\d\d)"/)
+ if parts[0].match(/"WEEK COMMENCING.*(\d\d.\d\d.\d\d)"/)
+ mdata = parts[0].match(/"WEEK COMMENCING.*(\d\d.\d\d.\d\d)"/)
d = Date.strptime(mdata[1], '%d.%m.%y')
all_dates << d
- elsif parts[0].match(/"WEEK COMMENCING - (\d\d.\d\d.\d\d\d\d)"/)
- mdata = parts[0].match(/"WEEK COMMENCING - (\d\d.\d\d.\d\d\d\d)"/)
+ elsif parts[0].match(/"WEEK COMMENCING.*(\d\d.\d\d.\d\d\d\d)"/)
+ mdata = parts[0].match(/"WEEK COMMENCING.*(\d\d.\d\d.\d\d\d\d)"/)
d = Date.strptime(mdata[1], '%d.%m.%Y')
all_dates << d
elsif parts[2].match(/(\d\d\d\d-\d\d-\d\d)/)
@@ -131,6 +133,9 @@
raise "Bad date!"
end
dates << a
+ #if a > Date.new(2009,3,1) and a < Date.new(2009,3,3)
+ # print "Found one instance in #{fname} - '#{parts[0]}'!\n"
+ #end
end
found_week_start = true
end
@@ -147,7 +152,9 @@
"admin" => "Admin",
"JRBH review" => "JRBH Review",
"P3 Universal" => "C-P3 Universal",
- "New Client" => "Educor 2"
+ "New Client" => "Educor 2",
+ "pring Break" => "Spring Break",
+ "NBd" => "NBD"
]
parsed_data.each do |x|
if task_map.has_key? x.task
@@ -188,7 +195,7 @@
end
end
parsed_data = tmp
-File.open('worklog1.dump', "w+" ) do |f|
+File.open(File.join(ARGV[0], ARGV[1]), "w+" ) do |f|
Marshal.dump(parsed_data, f)
end

0 comments on commit a06c1e9

Please sign in to comment.