Created
July 30, 2013 18:33
-
-
Save cvd/6115532 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
output = File.open('create_aps_flume.sql', 'w') | |
begin | |
CSV.foreach('bm_backfill.csv') do |row| | |
enrollment_id, user_id, activity_id, grade = row | |
sql = <<-SQL | |
INSERT INTO "activity_progresses" ("activity_id", "attempt", "created_at", "deleted_at", "enrollment_id", "grade", "passed", "status", "updated_at") | |
VALUES (#{activity_id}, 1, '2013-07-15 20:37:14', NULL, #{enrollment_id}, #{grade}, TRUE, NULL, '2013-07-15 20:37:14'); | |
SQL | |
# results = ActiveRecord::Base.connection.execute sql | |
output.puts sql #results.as_json.first["id"] | |
end | |
ensure | |
output.close | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
desc 'import scores from flume output' | |
task import_scores: :environment do | |
keys = ["aa010", "ba010", "ca010", "da010", "ia010", "ga010", "fa010", "ha010", "ea010"] | |
acts = Activity.where(curriculum_id: 5, assessment_key: keys) | |
activities = acts.inject({}) {|memo, act| memo[act.assessment_key] = act.id; memo } | |
outfile = File.open('flume_users_outfile.csv', 'w') | |
curr = Curriculum.fin_lit | |
%x[wc -l results-final.csv] =~ /(\d+)/ | |
count = $1.to_i | |
bar = RakeProgressbar.new(count) | |
begin | |
CSV.foreach('results-final.csv', headers: false) do |row| | |
begin | |
user_id, ass_key, grade = row | |
next if user_id.blank? | |
activity_id = activities[ass_key] | |
u = User.find(user_id) | |
if u && enr = u.enrollment_for_curriculum(curr) | |
outfile.puts CSV.generate_line [enr.id, user_id, activity_id, grade] | |
end | |
bar.inc | |
rescue ActiveRecord::RecordNotFound | |
bar.inc | |
end | |
end | |
ensure | |
bar.finish | |
outfile.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment