<commit_before>require File.dirname(__FILE__) + '/../spec_helper'

describe DataAverage do

  describe 'DataAverage calculate! average' do
    before(:each) do
      drop_data_stores
      @input = Input.new
      @input.create_data_store_tables('data_store_789')
     
      DataStore.create(:value => 1, :identified_by => 789)
      DataStore.create(:value => 2, :identified_by => 789)
    end

    it 'should do nothing if timeslot is nil' do
      DataAverage.calculate!(789, nil).should be_nil
    end

    it 'should calculate average! (one_min)' do
      Calculator.expects(:next).with(:one_min, anything).returns(nil)
      DataAverage.calculate!(789, :one_min)
      data = DataStore.from(789, :one_min).last
      data.value.should == 1.5
    end

    it 'should calculate average for every other timeslot' do
      Calculator.expects(:next).with(:four_hours, anything).returns(nil)
      DataAverage.calculate!(789, :four_hours)
      data = DataStore.from(789, :four_hours).last
      data.value.should == 1.5
    end

    it 'should calculate average! (one_min) if there is already another record stored' do
      DataStore.create(:value => 4.5, :identified_by => 789, :timeslot => :one_min)
      DataStore.any_instance.stubs(:created_at).returns(Time.now - 1.hour) #force calculating an average
      Calculator.expects(:next).with(:one_min, anything).returns(nil)
      DataAverage.calculate!(789, :one_min)
      data = DataStore.from(789, :one_min).last
      data.value.should == 1.5
    end

    after(:each) do
      drop_data_stores
    end
  end

end<commit_msg>Force assingment of created_at in spec, to prevent intermittent failures of spec<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

describe DataAverage do

  describe 'DataAverage' do
    before(:each) do
      drop_data_stores
      @input = Input.new
      @input.create_data_store_tables('data_store_789')
     
      DataStore.create!(:value => 1, :identified_by => 789, :created_at => '2012-08-07 11:01:58')
      DataStore.create!(:value => 2, :identified_by => 789, :created_at => '2012-08-07 11:01:59')
    end

    it 'should do nothing if timeslot is nil' do
      DataAverage.calculate!(789, nil).should be_nil
    end

    it 'should calculate average! (one_min)' do
      Calculator.expects(:next).with(:one_min, anything).returns(nil)
      DataAverage.calculate!(789, :one_min)
      data = DataStore.from(789, :one_min).last
      data.value.should == 1.5
    end

    it 'should calculate average for every other timeslot' do
      Calculator.expects(:next).with(:four_hours, anything).returns(nil)
      DataAverage.calculate!(789, :four_hours)
      data = DataStore.from(789, :four_hours).last
      data.value.should == 1.5
    end

    it 'should calculate average! (one_min) if there is already another record stored' do
      DataStore.create(:value => 4.5, :identified_by => 789, :timeslot => :one_min)
      DataStore.any_instance.stubs(:created_at).returns(Time.parse('2012-08-07 10:01:59')) #force calculating an average
      Calculator.expects(:next).with(:one_min, anything).returns(nil)
      DataAverage.calculate!(789, :one_min)
      data = DataStore.from(789, :one_min).last
      data.value.should == 1.5
    end

    after(:each) do
      drop_data_stores
    end
  end

end
{'fraction_non_alphanumeric': 0.12258454106280194, 'fraction_numerical': 0.03894927536231884, 'mean_word_length': 3.3764861294583883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5979978', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1064, 'n_words': 244}