fix logic in ema calculations, and store histogram to database
algorithm modifications and testing
modify rake task