Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion app/services/reporting/agency_and_sp_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ def initialize(report_date = Time.zone.today)

def agency_and_sp_report
idv_sps, auth_sps = service_providers.partition { |sp| sp.ial.present? && sp.ial >= 2 }

idv_agency_ids = idv_sps.map(&:agency_id).uniq
idv_agencies, auth_agencies = active_agencies.partition do |agency|
idv_agency_ids.include?(agency.id)
end

idv_sps_facial_match, idv_sps_legacy = idv_sps.partition do |sp|
facial_match_issuers.include?(sp.issuer)
end

idv_agency_facial_match_ids = idv_sps_facial_match.map(&:agency_id)
idv_facial_match_agencies, idv_legacy_agencies = idv_agencies.partition do |agency|
idv_agency_facial_match_ids.include?(agency.id)
end

[
['', 'Number of apps (SPs)', 'Number of agencies and states'],
['Auth', auth_sps.count, auth_agencies.count],
['IDV', idv_sps.count, idv_agencies.count],
['IDV (Legacy IDV)', idv_sps_legacy.count, idv_legacy_agencies.count],
['IDV (Facial matching)', idv_sps_facial_match.count, idv_facial_match_agencies.count],
['Total', auth_sps.count + idv_sps.count, auth_agencies.count + idv_agencies.count],
]
rescue ActiveRecord::QueryCanceled => err
Expand Down Expand Up @@ -54,5 +65,13 @@ def service_providers
ServiceProvider.where(issuer: issuers).active.external
end
end

def facial_match_issuers
@facial_match_issuers ||= Profile.where(active: true).where(
'verified_at <= ?',
report_date.end_of_day,
).where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).
pluck(:initiating_service_provider_issuer).uniq
end
end
end
75 changes: 62 additions & 13 deletions app/services/reporting/total_user_count_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,43 @@ def initialize(report_date = Time.zone.today)

def total_user_count_report
[
['Metric', 'All Users', 'Verified users', 'Time Range Start', 'Time Range End'],
['All-time count', total_user_count, verified_user_count, '-', report_date.to_date],
['All-time fully registered', total_fully_registered, '-', '-', report_date.to_date],
[
'Metric',
'All Users',
'Verified users (Legacy IDV)',
'Verified users (Facial Matching)',
'Time Range Start',
'Time Range End',
],
[
'All-time count',
total_user_count,
verified_legacy_idv_user_count,
verified_facial_match_user_count,
'-',
report_date.to_date,
],
[
'All-time fully registered',
total_fully_registered,
'-',
'-',
'-',
report_date.to_date,
],
[
'New users count',
new_user_count,
new_verified_user_count,
new_verified_legacy_idv_user_count,
new_verified_facial_match_user_count,
current_month.begin.to_date,
current_month.end.to_date,
],
[
'Annual users count',
annual_total_user_count,
annual_verified_user_count,
annual_verified_legacy_idv_user_count,
annual_verified_facial_match_user_count,
annual_start_date.to_date,
annual_end_date.to_date,
],
Expand Down Expand Up @@ -58,15 +81,35 @@ def total_user_count
end
end

def verified_user_count
def verified_legacy_idv_user_count
Reports::BaseReport.transaction_with_timeout do
Profile.where(active: true).where('verified_at <= ?', end_date).count
Profile.where(active: true).where(
'verified_at <= ?',
end_date,
).count - verified_facial_match_user_count
end
end

def new_verified_user_count
def verified_facial_match_user_count
@verified_facial_match_user_count ||= Reports::BaseReport.transaction_with_timeout do
Profile.where(active: true).where(
'verified_at <= ?',
end_date,
).where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).count
end
end

def new_verified_legacy_idv_user_count
Reports::BaseReport.transaction_with_timeout do
Profile.where(active: true).where(verified_at: current_month).count
Profile.where(active: true).where(verified_at: current_month).count -
new_verified_facial_match_user_count
end
end

def new_verified_facial_match_user_count
@new_verified_facial_match_user_count ||= Reports::BaseReport.transaction_with_timeout do
Profile.where(active: true).where(verified_at: current_month).
where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).count
end
end

Expand All @@ -76,11 +119,17 @@ def annual_total_user_count
end
end

def annual_verified_user_count
def annual_verified_legacy_idv_user_count
Reports::BaseReport.transaction_with_timeout do
Profile.where(active: true).
where(verified_at: annual_start_date..annual_end_date).
count
Profile.where(active: true).where(verified_at: annual_start_date..annual_end_date).count -
annual_verified_facial_match_user_count
end
end

def annual_verified_facial_match_user_count
@annual_verified_facial_match_user_count ||= Reports::BaseReport.transaction_with_timeout do
Profile.where(active: true).where(verified_at: annual_start_date..annual_end_date).
where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).count
end
end

Expand Down
35 changes: 28 additions & 7 deletions spec/services/reporting/agency_and_sp_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
[
header_row,
['Auth', 1, 1],
['IDV', 0, 0],
['IDV (Facial matching)', 0, 0],
['IDV (Legacy IDV)', 0, 0],
['Total', 1, 1],
]
end
Expand All @@ -69,7 +70,8 @@
[
header_row,
['Auth', 0, 1],
['IDV', 0, 0],
['IDV (Facial matching)', 0, 0],
['IDV (Legacy IDV)', 0, 0],
['Total', 0, 1],
]
end
Expand All @@ -94,7 +96,8 @@
[
header_row,
['Auth', 1, 1],
['IDV', 0, 0],
['IDV (Facial matching)', 0, 0],
['IDV (Legacy IDV)', 0, 0],
['Total', 1, 1],
]
end
Expand All @@ -103,7 +106,8 @@
[
header_row,
['Auth', 1, 0],
['IDV', 1, 1],
['IDV (Facial matching)', 0, 0],
['IDV (Legacy IDV)', 1, 1],
['Total', 2, 1],
]
end
Expand All @@ -127,7 +131,7 @@
end

context 'when adding an IDV SP' do
let!(:idv_sp) do
let!(:idv_legacy_sp) do
create(
:service_provider,
:external,
Expand All @@ -138,15 +142,32 @@
)
end

let!(:idv_facial_match_sp) do
create(
:service_provider,
:external,
:idv,
:active,
agency:,
identities: [build(:service_provider_identity, service_provider: 'https://facialmatch.com')],
)
end

let(:expected_report) do
[
header_row,
['Auth', 0, 0],
['IDV', 1, 1],
['Total', 1, 1],
['IDV (Facial matching)', 1, 1],
['IDV (Legacy IDV)', 1, 0],
['Total', 2, 1],
]
end

before do
allow_any_instance_of(Reporting::AgencyAndSpReport).to receive(:facial_match_issuers).
and_return([idv_facial_match_sp.issuer])
end

it 'counts the SP and its Agency as IDV' do
expect(subject).to match_array(expected_report)
end
Expand Down
Loading