Skip to content

Instantly share code, notes, and snippets.

@arthur-abogadil
Created February 23, 2021 23:50
Show Gist options
  • Save arthur-abogadil/c37a83a23fcb2aa7e1e4608516317f37 to your computer and use it in GitHub Desktop.
Save arthur-abogadil/c37a83a23fcb2aa7e1e4608516317f37 to your computer and use it in GitHub Desktop.
def score
pass = 0
pass_or_fail = 0
results.each do |result|
if result.status == "1" || result.status == "0"
pass_or_fail += 1
pass += 1 if result.status == "1"
end
end
score = ((pass.to_f * 5) / pass_or_fail.to_f).to_f
# Get decimal part
integer_part = score.to_i
decimal_part = score - integer_part
if score % 1 == 0
decimal_part = 0
else
if decimal_part <= 0.5
decimal_part = 0.5
else
decimal_part = 1
end
end
integer_part + decimal_part
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment