Last active
August 29, 2015 13:57
-
-
Save Chandler/9845333 to your computer and use it in GitHub Desktop.
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
class Api::StatsController < Api::ApiController | |
def self.timeseries(game_id) | |
data = [] | |
game = Game.find(game_id) | |
day = game.registration_start.to_date | |
# loop in 1 day increments from registration_start | |
# to game_end | |
while day < game.game_end.to_date | |
players = Player.where("game_id = ? AND created_at <= ?", game_id, day) | |
group = players.group_by { |player| player.true_status } | |
data << [ | |
day.to_time.to_i, | |
(group[:human] || {}).length, | |
(group[:zombie] || {}).length, | |
(group[:starved] || {}).length | |
] | |
day += 1.day | |
end | |
data | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment