def guess_from_thru
      begin
        @stat_thru = Time.parse(params[:thru]).to_date 
      rescue       
      end

      begin
        @stat_from = Time.parse(params[:from]).to_date 
      rescue
      end
      
      if @stat_from.nil? 
        if @stat_thru.nil?
          @stat_thru = Time.now.localtime.to_date - 1.day
        end
        @stat_from = @stat_thru - 1.week + 1.day
      else
        if @stat_thru.nil?
          @stat_thru = @stat_from + 1.week - 1.day
        end
      end
      
      @stat_step = 1.day
      
      duration = @stat_thru - @stat_from
      
      if duration < 90
        @stat_step = 12.hours
      end
      
      if duration < 30
        @stat_step = 6.hour
      end
      
      if duration < 10
        @stat_step = 1.hour
      end    
      
      #if @stat_thru - @stat_from > 12.month
      #  @stat_step = 4.week
      #end
    end
def guess_from_thru
      begin
        @stat_thru = Time.parse(params[:thru]).to_date 
      rescue       
      end

      begin
        @stat_from = Time.parse(params[:from]).to_date 
      rescue
      end
      
      if @stat_from.nil? 
        if @stat_thru.nil?
          @stat_thru = Time.now.localtime.to_date - 1.day
        end
        @stat_from = @stat_thru - 1.week + 1.day
      else
        if @stat_thru.nil?
          @stat_thru = @stat_from + 1.week - 1.day
        end
      end
      
      @stat_step = 1.day
      
      duration = @stat_thru - @stat_from
      
      if duration < 90
        @stat_step = 12.hours
      end
      
      if duration < 30
        @stat_step = 6.hour
      end
      
      if duration < 10
        @stat_step = 1.hour
      end    
      
      #if @stat_thru - @stat_from > 12.month
      #  @stat_step = 4.week
      #end
    end
Guess for which time range to display statistics