Skip to content

Instantly share code, notes, and snippets.

@ctrombley
Last active June 1, 2016 22:00
Show Gist options
  • Save ctrombley/c31b8f2e3e9ff88a825dcb51b8eb5d9e to your computer and use it in GitHub Desktop.
Save ctrombley/c31b8f2e3e9ff88a825dcb51b8eb5d9e to your computer and use it in GitHub Desktop.
generate eligibility file
filename = "eligibility_file_scenario_1.csv"
headings = ['ValidationData',
'RelatedID',
'Birthdate',
'FirstName',
'LastName',
'Gender',
'Address',
'Address2',
'City',
'State',
'ZipCode',
'Country',
'PhoneNumber',
'EmailAddress',
'SSN',
'StructureLevel1',
'StructureLevel2',
'StructureLevel3',
'StructureLevel4',
'StructureLevel5',
'EnrolledPlan',
'EligiblePlan',
'SalaryBandID',
'SubscriberRelationship',
'CoverageStartDate',
'RewardsProgram',
'ExternalIdentifier',
]
constants = {
'Birthdate': '01011970',
'FirstName': 'TestFirstName',
'LastName': 'TestLastName',
'Gender': 'F',
'Address': '2701 NW Vaughn St',
'Address2': 'Suite 700',
'City': 'Portland',
'State': 'OR',
'ZipCode': '97210',
'Country': 'US',
'PhoneNumber': '(503) 555-2382',
'EmailAddress': 'pdxqatestmsg@webmd.net',
'SSN': '000111001',
'SubscriberRelationship': 'SubscriberRelationship',
'CoverageStartDate': '10-10-2002',
'ExternalIdentifier': 'member_groups_test_sm',
}
value_hash = {
StructureLevel1: ['Seattle', 'Portland'], # Location
StructureLevel2: ['Manager', 'Engineer'], # Role
StructureLevel3: ['HMO', 'PPO'], # Health Plan
StructureLevel4: ['75K-100K', '100K-125K'], # Salary Band
}
# (2 * 2 * 2 * 2) = 16
max_combinations = value_hash.inject(1){|total, (k,v)| total * v.length}
# 16 * 10000 = 160000 users
group_size = 80
offset = group_size / max_combinations
max_users = max_combinations * group_size
max_users_digits = max_users.to_s.length
padded_zeroes_format = "%0#{max_users_digits}d"
f = File.open(filename, 'w')
f.puts headings.join(",")
value_lengths = value_hash.values.map { |v| (0...v.length).to_a }
index_arrays = value_lengths.first.product(*value_lengths[1..-1])
rows_added = 0
index_arrays.each_with_index do |index_array, i|
offset_multiplier = (max_combinations/2) - i
offset_group_size = group_size + (offset * offset_multiplier)
#puts "group size: #{offset_group_size}"
offset_group_size.times do |j|
line = headings.map do |h|
if h == 'ValidationData'
username_suffix = padded_zeroes_format % rows_added
"memberGroupsUserSm#{ username_suffix }"
elsif constants.has_key?(h.to_sym)
constants[h.to_sym]
elsif value_hash.has_key?(h.to_sym)
value_hash[h.to_sym][index_array[value_hash.keys.find_index(h.to_sym)]]
else
""
end
end
rows_added = rows_added + 1
f.puts line.join(",")
end
end
f.close
puts "#{rows_added} rows created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment