Skip to content

Instantly share code, notes, and snippets.

@josephrexme
Created January 4, 2015 23:38
Show Gist options
  • Select an option

  • Save josephrexme/fe445701513a186bb43f to your computer and use it in GitHub Desktop.

Select an option

Save josephrexme/fe445701513a186bb43f to your computer and use it in GitHub Desktop.
Attendance Logic
=begin
Help with Logic
=end
allRecords = Attendance.pluck(:date, :presence).map { |attendance, presence| [attendance.strftime('%B'), presence] } #=> [['November',true],['November',false],['November',true],['December', true], ['December', false], ['January',false], ['January',true]]
monthFilter = allRecords.uniq.map { |month| [month[0]] } #=> ['November','November', 'November', 'December', 'December', 'January','January']
months = monthFilter.uniq #=> ['November','December','January']
# Expected To do the following:
# To fetch all the records and count the number of true presence with false presence per month. Then get a percentage of true / total in each month
@josephrexme
Copy link
Copy Markdown
Author

In the end, I realized it was the percentage logic that needed to be corrected. So I had this instead

[k, "#{(Float(trues.size)/ (Float(falses.size) + Float(trues.size)) * 100).round}%"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment