# Problem with mysql & Rails for stats

**URL:** <https://www.ruby-forum.com/t/problem-with-mysql-rails-for-stats/126566>\
**Category:** Rails\
**Created:** [January 19, 2008, 6:08pm UTC](https://www.ruby-forum.com/t/problem-with-mysql-rails-for-stats/126566 "2008-01-19T18:08:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marsenio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@marsenio](https://www.ruby-forum.com/u/marsenio)\
**Post date:** [January 19, 2008, 6:08pm UTC](https://www.ruby-forum.com/t/problem-with-mysql-rails-for-stats/126566/1 "2008-01-19T18:08:52Z")

</div>

Hi everybody

I have a ROR application which generates some stats taking data from a  
db table.  
To get the results I before create an array with all the values involved  
in the stats - each data stack label - … then calculate the time  
interval splited for week or month… and for each splitted interval I  
have an Activerecord calculte(:count) method in order to create - for  
each data stack - an array of values…

This seems to work done, but sometimes something goes wrong, couse I  
return empty or nil array of results. I fixed it with a control to avoid  
system errors. But Anyway it happens… And I loose some data in my  
stats.

Looking at the mysql query log, all the query are executed…  
How can I menage this situation? Is it possible to observ the  
ActiveRecord::calculate feedback to understand exactly what  
randomly happens with these query?

## here is an abstract of the code

## results=[] arr\_data\_stack.each do |x| values\_array = [] CalculateInterval.each do |interval| values\_array \<\< Log.calculate(:count, […]) if x end results[x] = (values\_array .empty? ? 0 : values\_array) end

the problem is the result[x] is sometimes empty or nil - I don’t know  
exactly - even if all the query were executed on db

let me know your opinion please

thanks a lot  
cheers

Marsenio
