Skip to content

Instantly share code, notes, and snippets.

@cavebatsofware
Last active March 31, 2017 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cavebatsofware/26ac9ec4e3271fb9c66f67b7c339d6a8 to your computer and use it in GitHub Desktop.
Save cavebatsofware/26ac9ec4e3271fb9c66f67b7c339d6a8 to your computer and use it in GitHub Desktop.
master_r4 = CSV.parse(File.read('/Users/grantdefayette/Documents/rails40-master-1.csv'))
master_r3 = CSV.parse(File.read('/Users/grantdefayette/Documents/rails31-master-1.csv'))
nf11481_r4 = CSV.parse(File.read('/Users/grantdefayette/Documents/general_comb_rails4.csv'))
nf11481_r3 = CSV.parse(File.read('/Users/grantdefayette/Documents/general_comb_rails3.csv'))
hash_ma4 = ma4.map { |r| h = Hash.new; h[r[2].to_i] = [r[8], r[4], r[8], r[3]]; h }
hash_ks4 = nf11481_r4.map { |r| h = Hash.new; h[r[0].to_i] = [r[1], r[2], r[3], r[4]]; h }
hhma4 = Hash.new; hma4.each { |h| hhma4[h.first.key] = h.first.value }
compare_ks_master_r4 = []; hhks4.keys.each { |k| compare_ks_master_r4 << ( hhks4[k][1].to_i == hhma4[k][1].to_i ? true : [k, hhma4[k], hhks4[k]] ) if hhks4[k] && hhma4[k] }
{
"list_configs": [
{
"outputfile": "sifter_lists_master_3.1",
"list_sql": "select distinct lists.id from lists inner join clauses on clauses.list_id = lists.id inner join field_categories on (field_categories.identifier = 'applicant_ethnicities' or field_categories.identifier like 'official%') inner join fields on (fields.id = clauses.field_id and field_categories.id = fields.field_category_id) where lists.user_identity_id is not null;"
}
]
}
{
"list_configs": [
{
"outputfile": "sifter_lists_master_4.0",
"list_sql": "select distinct lists.id from lists inner join clauses on clauses.list_id = lists.id inner join field_categories on (field_categories.identifier = 'applicant_ethnicities' or field_categories.identifier like 'official%') inner join fields on (fields.id = clauses.field_id and field_categories.id = fields.field_category_id) where lists.user_identity_id is not null;"
}
]
}
require 'json'
require 'pry'
class ::TestListRunner
def initialize(config_file = 'list_runner_config.json')
run(JSON.parse(File.read(config_file))['list_configs'])
end
def run(list_configs)
list_configs.each do |list_config|
run_lists(list_config)
end
end
def run_lists(list_config)
list_sql = list_config['list_sql']
list_ids = Lists::FieldList.connection.execute(list_sql).map { |row| row['id'].to_i }
lists = Lists::FieldList.where(id: list_ids)
outputfile = list_config['outputfile'] + '.csv'
save_row(['list_id', 'has_error', 'row_count', 'error'], outputfile)
lists.each do |list|
count = nil
error = nil
begin
count = list.run_for_user_identity(list.user_identity).count
rescue StandardError => e
error = e
ensure
error_string = error.nil? ? 'N/A' : "#{error.message} :---: \n#{error.backtrace.join}"
row = [list.id, !error.nil?, count, error_string]
save_row(row, outputfile)
end
end
end
def save_row(row, filename)
File.open(filename, 'a') do |f|
f.puts row.to_csv
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment