Created
January 4, 2015 23:38
-
-
Save josephrexme/fe445701513a186bb43f to your computer and use it in GitHub Desktop.
Attendance Logic
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
| =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 |
Author
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
Adjusted the code to this:
But now get 0% on all