Refactored statistics caclulation

This commit is contained in:
Sergei Tsoganov 2023-12-14 13:26:31 +02:00
parent bd12a73898
commit e73faae879
4 changed files with 111 additions and 29 deletions

View file

@ -12,7 +12,7 @@ shop:
period: 1
period_unit: m
uuid: 1b3ee442-e8fe-4922-9492-8fcb9dccc69c
created_at: <%= 2.days.ago.to_s :db %>
created_at: <%= 2.months.ago.to_s :db %>
airport:
name: airport.test
@ -51,7 +51,7 @@ metro:
period: 1
period_unit: m
uuid: ef97cb80-333b-4893-b9df-163f2b452798
created_at: <%= 2.days.ago.to_s :db %>
created_at: <%= 3.months.ago.to_s :db %>
hospital:
name: hospital.test

View file

@ -5,4 +5,50 @@ one:
object:
registrant_id: <%= ActiveRecord::FixtureSet.identify(:john) %>
updated_at: <%= Time.zone.parse('2010-07-05') %>
created_at: <%= Time.zone.parse('2010-07-05') %>
created_at: <%= Time.zone.parse('2010-07-05') %>
transfer_one:
item_id: <%= ActiveRecord::FixtureSet.identify(:shop) %>
item_type: Domain
event: update
object:
name: 'shop.test'
object_changes:
registrar_id: [<%= ActiveRecord::FixtureSet.identify(:goodnames) %>, <%= ActiveRecord::FixtureSet.identify(:bestnames) %>]
created_at: <%= 2.days.ago.to_s :db %>
create_one:
item_id: 1111111
item_type: Domain
event: create
object_changes:
name: [null, 'deleted.test']
registrar_id: [null, <%= ActiveRecord::FixtureSet.identify(:goodnames) %>]
created_at: <%= 3.months.ago.to_s :db %>
destroy_one:
item_id: 1111111
item_type: Domain
event: destroy
object_changes:
name: ['deleted.test', null]
registrar_id: [<%= ActiveRecord::FixtureSet.identify(:goodnames) %>, null]
created_at: <%= 2.days.ago.to_s :db %>
create_two:
item_id: <%= ActiveRecord::FixtureSet.identify(:library) %>
item_type: Domain
event: create
object_changes:
name: [null, 'library.test']
registrar_id: [null, <%= ActiveRecord::FixtureSet.identify(:bestnames) %>]
created_at: <%= 2.days.ago.to_s :db %>
create_three:
item_id: <%= ActiveRecord::FixtureSet.identify(:airport) %>
item_type: Domain
event: create
object_changes:
name: [null, 'airport.test']
registrar_id: [null, <%= ActiveRecord::FixtureSet.identify(:bestnames) %>]
created_at: <%= 2.days.ago.to_s :db %>

View file

@ -19,8 +19,8 @@ class ReppV1StatsMarketShareTest < ActionDispatch::IntegrationTest
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
assert json[:data].is_a? Array
assert json[:data][0].is_a? Hash
assert_equal json[:data], [{ name: @user.registrar.name, y: 4, sliced: true, selected: true },
{ name: 'Good Names', y: 2 }]
end
def test_shows_market_share_growth_rate_data
@ -34,10 +34,11 @@ class ReppV1StatsMarketShareTest < ActionDispatch::IntegrationTest
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
data = json[:data]
assert data[:data].is_a? Hash
assert data[:prev_data].is_a? Hash
assert_equal data[:data][:name], @today
assert data[:data][:domains].is_a? Array
assert_equal json[:data], prev_data: { name: prev_date,
domains: [['Best Names', 1], ['Good Names', 2]],
market_share: [['Best Names', 33.3], ['Good Names', 66.7]] },
data: { name: @today,
domains: [['Best Names', 4], ['Good Names', 2]],
market_share: [['Best Names', 66.7], ['Good Names', 33.3]] }
end
end
end