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
7 changes: 6 additions & 1 deletion app/jobs/reports/monthly_key_metrics_report.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'csv'
require 'reporting/monthly_proofing_report'
require 'reporting/proofing_rate_report'

module Reports
class MonthlyKeyMetricsReport < BaseReport
Expand Down Expand Up @@ -53,7 +54,7 @@ def reports
active_users_count_report.active_users_count_emailable_report,
# Total Annual Users - LG-11150
total_user_count_report.total_user_count_emailable_report,
# Proofing rate(s) (tbd on this one pager) - LG-11152
proofing_rate_report.proofing_rate_emailable_report,
account_deletion_rate_report.account_deletion_emailable_report,
account_reuse_report.account_reuse_emailable_report,
account_reuse_report.total_identities_emailable_report,
Expand All @@ -77,6 +78,10 @@ def emails
emails
end

def proofing_rate_report
@proofing_rate_report ||= Reporting::ProofingRateReport.new(end_date: report_date)
end

def account_reuse_report
@account_reuse_report ||= Reporting::AccountReuseAndTotalIdentitiesReport.new(report_date)
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.

Not for this PR, but -- it is starting to feel really dirty that Reporting::AccountReuseAndTotalIdentitiesReport (and most other reports here) don't require an, erm, require, because they're local, but Reporting::ProofingRateReport does because it's in a separate reporting directory. I hope some day we can unify that.

end
Expand Down
4 changes: 3 additions & 1 deletion lib/reporting/identity_verification_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def initialize(
progress: false,
slice: 3.hours,
threads: 5,
data: nil
data: nil,
cloudwatch_client: nil
)
@issuers = issuers
@time_range = time_range
Expand All @@ -63,6 +64,7 @@ def initialize(
@slice = slice
@threads = threads
@data = data
@cloudwatch_client = cloudwatch_client
end

def verbose?
Expand Down
2 changes: 2 additions & 0 deletions lib/reporting/monthly_proofing_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def progress?
def document_upload_proofing_emailable_report
EmailableReport.new(
title: 'Document upload proofing rates',
float_as_percent: true,
precision: 4,
table: proofing_report,
filename: 'document_upload_proofing',
)
Expand Down
25 changes: 21 additions & 4 deletions lib/reporting/proofing_rate_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ def progress?
@progress
end

def proofing_rate_emailable_report
EmailableReport.new(
title: 'Proofing Rate Metrics',
float_as_percent: true,
precision: 2,
table: as_csv,
filename: 'proofing_rate_metrics',
)
end

# rubocop:disable Layout/LineLength
def as_csv
csv = []

csv << ['Metric', *DATE_INTERVALS.map { |days| "Trailing #{days}d" }]

csv << ['Start Date', *reports.map(&:time_range).map(&:begin)]
csv << ['End Date', *reports.map(&:time_range).map(&:end)]
csv << ['Start Date', *reports.map(&:time_range).map(&:begin).map(&:to_date)]
csv << ['End Date', *reports.map(&:time_range).map(&:end).map(&:to_date)]

csv << ['IDV Started', *reports.map(&:idv_started)]
csv << ['Welcome Submitted', *reports.map(&:idv_doc_auth_welcome_submitted)]
Expand Down Expand Up @@ -66,8 +76,7 @@ def reports
(end_date - slice_start.days).beginning_of_day,
(end_date - slice_end.days).beginning_of_day,
),
progress: false,
verbose: verbose?,
cloudwatch_client: cloudwatch_client,
).tap(&:data)
end
end
Expand Down Expand Up @@ -119,6 +128,14 @@ def industry_proofing_rates(reports)
)
end
end

def cloudwatch_client
@cloudwatch_client ||= Reporting::CloudwatchClient.new(
ensure_complete_logs: true,
progress: false,
logger: verbose? ? Logger.new(STDERR) : nil,
)
end
end
end

Expand Down
28 changes: 16 additions & 12 deletions spec/jobs/reports/monthly_key_metrics_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@
let(:report_folder) do
'int/monthly-key-metrics-report/2021/2021-03-02.monthly-key-metrics-report'
end
let(:account_reuse_s3_path) { "#{report_folder}/account_reuse.csv" }
let(:total_profiles_s3_path) { "#{report_folder}/total_profiles.csv" }
let(:document_upload_proofing_s3_path) { "#{report_folder}/document_upload_proofing.csv" }
let(:account_deletion_rate_s3_path) { "#{report_folder}/account_deletion_rate.csv" }
let(:total_user_count_s3_path) { "#{report_folder}/total_user_count.csv" }
let(:active_users_count_s3_path) { "#{report_folder}/active_users_count.csv" }

let(:expected_s3_paths) do
[
account_reuse_s3_path,
total_profiles_s3_path,
account_deletion_rate_s3_path,
total_user_count_s3_path,
document_upload_proofing_s3_path,
active_users_count_s3_path,
"#{report_folder}/account_reuse.csv",
"#{report_folder}/total_profiles.csv",
"#{report_folder}/document_upload_proofing.csv",
"#{report_folder}/account_deletion_rate.csv",
"#{report_folder}/total_user_count.csv",
"#{report_folder}/active_users_count.csv",
"#{report_folder}/proofing_rate_metrics.csv",
]
end
let(:s3_metadata) do
Expand All @@ -39,6 +35,12 @@
]
end

let(:mock_proofing_rate_data) do
[
['Metric', 'Trailing 30d', 'Trailing 60d', 'Trailing 90d'],
]
end

before do
allow(Identity::Hostdata).to receive(:env).and_return('int')
allow(Identity::Hostdata).to receive(:aws_account_id).and_return('1234')
Expand All @@ -54,6 +56,8 @@

allow(report.monthly_proofing_report).to receive(:proofing_report).
and_return(mock_proofing_report_data)
allow(report.proofing_rate_report).to receive(:as_csv).
and_return(mock_proofing_rate_data)
end

it 'sends out a report to the email listed with one total user' do
Expand Down
9 changes: 3 additions & 6 deletions spec/lib/reporting/proofing_rate_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,19 @@
expect(Reporting::IdentityVerificationReport).to have_received(:new).with(
time_range: (end_date - 30.days)..end_date,
issuers: nil,
verbose: false,
progress: false,
cloudwatch_client: report.cloudwatch_client,
).once

expect(Reporting::IdentityVerificationReport).to have_received(:new).with(
time_range: (end_date - 60.days)..(end_date - 30.days),
issuers: nil,
verbose: false,
progress: false,
cloudwatch_client: report.cloudwatch_client,
).once

expect(Reporting::IdentityVerificationReport).to have_received(:new).with(
time_range: (end_date - 90.days)..(end_date - 60.days),
issuers: nil,
verbose: false,
progress: false,
cloudwatch_client: report.cloudwatch_client,
).once
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/mailers/previews/report_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def warn_error
def monthly_key_metrics_report
monthly_key_metrics_report = Reports::MonthlyKeyMetricsReport.new(Time.zone.today)

stub_cloudwatch_client(monthly_key_metrics_report.proofing_rate_report)
stub_cloudwatch_client(monthly_key_metrics_report.monthly_proofing_report)

ReportMailer.tables_report(
Expand Down