-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHRGenerator.rb
executable file
·241 lines (154 loc) · 6.88 KB
/
HRGenerator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env ruby
#Simon Moffatt Jan 2013
#Creates a CSV file of random user HR data. Useful for populating LDAP/databases for ACL testing
#Requires a unique names file with "firstname lastname" per each line
#requires
require 'rubygems'
require 'date'
require 'csv'
#Globals and constants#######################################################################
INPUT_FILE="100k_names.dat" #one name per line (firstname lastname)
OUTPUT_FILE="100k_HR_Users.csv"
@unique_employeeids = [] #initialized. contains newly created ids in order to manage uniqueness
@managers = {} #where manager to dept assignments are stored
@completed_users = [] #where all user arrays end up
#Org Data
COMPANY_NAME="OpenRock"
DEPTS=["IT","Finance","Sales","Engineering","Accounts","Marketing","Operations","Research", "Consulting", "Admin", "Partner",
"HR","Logistics", "Communications", "Facilities"]
TITLES={:IT => ["Developer-I","Developer-II","Developer-III","Analyst","Engineer", "Snr-Engineer"],
:Finance=>["Administrator-III","Administrator-II","Administrator-I","Payroll-Clerk","Reporting"],
:Sales=>["Rep-I","Rep-II","Rep-III","Field-Rep-I","Field-Rep-II","Field-Rep-III"],
:Engineering=>["Engineer","Snr-Engineer"], :Accounts=>["Payable-Clerk-I","Receivable-Clerk","Payable-Clerk-II","Payable-Clerk-III"],
:Marketing=>["Inbound-Exec-II","Inbound-Exec-I","Outbound-Exec-I","Outbound-Exec-II"],:Operations=>["Analyst1","Analyst2","Analyst3"],
:Research=>["Assistant","Supervisor"], :Consulting=>["Consultant","Snr-Consultant"], :Admin=>["Receptionist","Secretary"],
:Partner=>["Relations-Manager"], :HR=>["Exec-III","Exec-II","Exec-I"], :Logistics=>["Analyst-I", "Analyst-II"],
:"Communications"=>["Exec","Consultant", "Writer-Internal", "Writer-External"], :Facilities=>["Security-I", "Security-II", "Guard"] }
#Globals and constants#######################################################################
def init
@completed_users << "employeeid,fullname,firstname,lastname,email,department,job_title,manager,start_date,mobile,location"
end
def read_employees
puts "Reading input file..."
#iterate over csv of first and last names. Each row is passed to row[]
if File.exist?(INPUT_FILE)
#create the managers array for the first n number of employees where n = number of departments specified in global DEPTS array
i=0
managers_to_be = []
CSV.foreach(INPUT_FILE) do |employee|
break if (i == DEPTS.length) #only want to pull out enough managers to cover the depts
managers_to_be << employee
i += 1
end
#go and actually assign the managers to their depts
create_managers managers_to_be
#go and create HR records for all employees found in the employees csv
puts "Creating new HR records"
CSV.foreach(INPUT_FILE) do |employee|
create_HR_record employee
end
puts "\nCompleted creating HR records"
else
puts "#{INPUT_FILE} file not found!"
exit
end
end
#returns n digit number block
def get_number_block
block = rand(4**4)
#make sure block length is 3 chars
while block.to_s.length != 3
block = rand(4**4)
end
return block
end
#generates phone number
def get_phone
#Eg 123-456-789
number="#{get_number_block}-#{get_number_block}-#{get_number_block}"
end
#generates continent based location
def get_continent
continents = ["US", "EU", "ASIA"]
continent = continents[Kernel.rand(continents.length-1)]
end
#Creates single HR record with random data and pushes into COMPLETED_USERS array
def create_HR_record employee
processed_record = "."
firstname = employee[0].split(" ")[0]
lastname = employee[0].split(" ")[1]
fullname = employee[0]
dept = @managers.has_value?(fullname.to_s) ? @managers.key(fullname.to_s) : get_dept #check if employee fullname already exists in MANAGERS hash if so use dept
job_title = @managers.has_value?(fullname.to_s) ? "Manager" : get_title(dept) #check if employee fullname already exists in MANAGERS hash is so = manager
employeeid = get_employeeid firstname, lastname
email = get_email firstname, lastname
start_date = get_start_date
end_date = get_end_date #not implemented
manager = job_title == "Manager" ? "CEO" : @managers[dept.to_sym]
mobile = get_phone
location = get_continent
@completed_users << "#{employeeid},#{fullname},#{firstname},#{lastname},#{email},#{dept},#{job_title},#{manager},#{start_date},#{mobile},#{location}"
STDERR.print processed_record
end
#creates a single manager per business unit
def create_managers managers_to_be
i = 0
1.upto(managers_to_be.length-1) do
@managers[DEPTS[i].to_s.to_sym] = managers_to_be[i][0] #Eg. {:Finance => "Simon Moffatt"}
i += 1 #move on to next value
end
end
#creates random start_date DD/MM/YYYY
def get_start_date
start_of_date_range = "2005/01/01" #YYYY/MM/DD
end_of_date_range = "2013/01/01" #YYYY/MM/DD
#array of all dates in range
date_range = (Date.parse(start_of_date_range)..Date.parse(end_of_date_range)).to_a
#pulls out a random date based on the Kernel randomizer going now higher than the array length
date_range[Kernel.rand(date_range.length-1)].to_s
end
#creates random end date DD/MM/YYYY
def get_end_date
end
#creates email address
def get_email firstname, lastname
"#{firstname}.#{lastname}@#{COMPANY_NAME}.com"
end
#randomly pulls out a single dept
def get_dept
DEPTS[Kernel.rand(DEPTS.length-1)].to_s
end
#pulls out job title based on @dept value
def get_title dept
all_titles = TITLES[dept.to_sym]
all_titles[Kernel.rand(all_titles.length-1)]
end
#creates random and unique employeeid. Format=fl##### (f=firstname first char, l=lastname first char)
def get_employeeid firstname,lastname
employeeid = "#{firstname[0]}#{lastname[0]}#{Kernel.rand(99999)}"
while @unique_employeeids.include? employeeid #check to set if new employeeid hasn't already been assigned to someone
employeeid = "#{firstname[0]}#{lastname[0]}#{Kernel.rand(99999)}"
end
@unique_employeeids << employeeid #add accepted id to array of all ids
return employeeid
end
#writes out to new HR record
def write_data
puts "Writing out new HR data"
processed_record ="."
output_file = File.open(OUTPUT_FILE, 'w')
@completed_users.each do |user|
output_file.puts user.to_s
STDERR.print processed_record
end #basic puts but driven to open file
output_file.close #closes
puts "\nCompleted writing out new HR data \n#{@completed_users.length} records processed"
end
#Run Through
puts "#####################################################################################"
puts "Started HR Generator #{Time.now}"
init
read_employees
write_data
puts "Ended HR Generator #{Time.now}"
puts "#####################################################################################"