Skip to content

Instantly share code, notes, and snippets.

@cvd
Last active August 29, 2015 14:01
Show Gist options
  • Save cvd/2c45f74ca9c323bc28f8 to your computer and use it in GitHub Desktop.
Save cvd/2c45f74ca9c323bc28f8 to your computer and use it in GitHub Desktop.
@keys = Activity.where(curriculum_id: Curriculum.ignition).pluck(:assessment_key).compact
# @activities = Activity.where(activity_type: 'module', curriculum_id: Curriculum.ignition).inject({}) {|memo, a| memo[a.id] = a; memo }
@activities = Activity.where(curriculum_id: 3).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.any? {|ap| ap.activity_id == act.id && ap.grade == grade }
passed = grade >= @activities[act.id].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.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