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
11 changes: 11 additions & 0 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

class Profile < ApplicationRecord
# IDV levels equivalent to facial match
FACIAL_MATCH_IDV_LEVELS = %w[unsupervised_with_selfie in_person].to_set.freeze
# Facial match through IAL2 opt-in flow
FACIAL_MATCH_OPT_IN = %w[unsupervised_with_selfie].to_set.freeze

belongs_to :user
# rubocop:disable Rails/InverseOf
Expand Down Expand Up @@ -52,6 +55,14 @@ def self.verified
where.not(verified_at: nil)
end

def self.facial_match
where(idv_level: FACIAL_MATCH_IDV_LEVELS)
end

def self.facial_match_opt_in
where(idv_level: FACIAL_MATCH_OPT_IN)
end

def self.fraud_rejection
where.not(fraud_rejection_at: nil)
end
Expand Down
23 changes: 12 additions & 11 deletions app/services/reporting/agency_and_sp_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def agency_and_sp_emailable_report
end

def active_agencies
@active_agencies ||= Agreements::PartnerAccountStatus.find_by(name: 'active').
partner_accounts.
includes(:agency).
where('became_partner <= ?', report_date).
map(&:agency).
uniq
@active_agencies ||= Agency.joins(:partner_accounts).
where(partner_accounts: {
partner_account_status: Agreements::PartnerAccountStatus.find_by(name: 'active'),
became_partner: ..report_date,
}).
distinct
Copy link
Copy Markdown
Contributor Author

@MrNagoo MrNagoo Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has a 2x speed improvement

end

def service_providers
Expand All @@ -67,11 +67,12 @@ def service_providers
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
@facial_match_issuers ||= Reports::BaseReport.transaction_with_timeout do
Profile.active.facial_match_opt_in.
where('verified_at <= ?', report_date.end_of_day).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the verified scope on the prior line redundant with this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it can't be active without verified so idk why I am the way that I am.

distinct.
pluck(:initiating_service_provider_issuer)
end
end
end
end
24 changes: 11 additions & 13 deletions app/services/reporting/total_user_count_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,30 @@ def total_user_count

def verified_legacy_idv_user_count
Reports::BaseReport.transaction_with_timeout do
Profile.where(active: true).where(
'verified_at <= ?',
end_date,
Profile.active.where(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated most of this file to use the available class methods.

'verified_at <= ?', end_date
).count - verified_facial_match_user_count
end
end

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
Profile.active.facial_match_opt_in.where(
'verified_at <= ?', end_date
).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.active.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
Profile.active.facial_match_opt_in.where(verified_at: current_month).count
end
end

Expand All @@ -121,15 +118,16 @@ def annual_total_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.active.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
Profile.active.facial_match_opt_in.where(
verified_at: annual_start_date..annual_end_date,
).count
end
end

Expand Down
27 changes: 27 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helpful to not have to type 'bundle exec'

2 changes: 1 addition & 1 deletion spec/factories/profiles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
end

trait :facial_match_proof do
idv_level { :in_person }
idv_level { :unsupervised_with_selfie }
initiating_service_provider_issuer { 'urn:gov:gsa:openidconnect:inactive:sp:test' }
end

Expand Down