Skip to content

Instantly share code, notes, and snippets.

@cvd
Created May 6, 2014 19:53
Show Gist options
  • Save cvd/dc43c45afd70342bf3c3 to your computer and use it in GitHub Desktop.
Save cvd/dc43c45afd70342bf3c3 to your computer and use it in GitHub Desktop.
@keys = Activity.where(curriculum_id: 4).pluck(:assessment_key).compact
@activities = Activity.where(curriculum_id: 4).inject({}) {|memo, a| memo[a.assessment_key] = a; memo }
def fix_page(page, e, b, school)
if page && page['data'] && page['data']['correct'] && page['data']['total']
grade = (page['data']['correct'] / page['data']['total'].to_f) * 100
act = @activities[page['id']]
unless e.activity_progresses.select {|ap| ap.activity_id == act.id && ap.grade == grade }.any?
passed = grade >= act.try(:passing_grade).to_i
e.activity_progresses.create(activity_id: act.id, grade: grade, passed: passed)
end
end
end
def fix_enrollment(e, school)
e.user.bookmarks.each do |b|
begin
pages = b.pages.select {|k,v| k.in?(@keys) }
pages.each {|k, p| fix_page(p, e, b, school) }
rescue JSON::ParserError
puts 'JSON PARSE ERROR'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment