-
Notifications
You must be signed in to change notification settings - Fork 167
Agnes/lg 13018 billing report v2 #10613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
020c14f
lg-13013-initial commit for branch name change
colter-nattrass c26711d
lg-13013-fixed branch naming
colter-nattrass 5b9042d
lg-13013-checking-in-for-samatha
colter-nattrass b49e218
lg-13013-fixed branch naming
colter-nattrass 715dd3e
lg-13013 updated specs and unqui_counts_by_partner helper
samathad2023 28120fe
lg-13013 removing unwanted updates
samathad2023 fdd7b60
lg-13013-modifying sql statements to bring in verification by year sums
colter-nattrass 4f73153
lg-13013 completed modifications to counts_by_partner module, working…
colter-nattrass 06c27ea
lg-13013- implemented changes from feedback
colter-nattrass e108978
lg-13013 stage everything for samatha, will remove binding.pry statem…
colter-nattrass 1a7c78d
lg-13013 adding changes to counts by partner class definition and spe…
colter-nattrass 7acaf2c
lg-13013 indentation lint fixes
colter-nattrass 9126824
lg-13018 created new billingv2 report
samathad2023 2e69293
lg-13018 combined invoice report v2 with partner
samathad2023 3755c9c
Remove Rubocop lint disabling by adding appropriate associations
zachmargolis 649b70d
PR comments
samathad2023 7c6b6cd
lint fix
samathad2023 882b8f7
Update service_provider.rb
ThatSpaceGuy c71217d
Update app/jobs/reports/combined_invoice_supplement_report_v2.rb
ThatSpaceGuy 723868e
Config cron run updates
samathad2023 2f42fb2
Update combined_invoice_supplement_report_v2_spec.rb
ThatSpaceGuy d5268fe
Merge remote-tracking branch 'origin/main' into agnes/lg-13018-billin…
samathad2023 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
app/jobs/reports/combined_invoice_supplement_report_v2.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'csv' | ||
|
|
||
| module Reports | ||
| class CombinedInvoiceSupplementReportV2 < BaseReport | ||
| REPORT_NAME = 'combined-invoice-supplement-report-v2' | ||
|
|
||
| def perform(_date) | ||
| csv = build_csv(IaaReportingHelper.iaas, IaaReportingHelper.partner_accounts) | ||
| save_report(REPORT_NAME, csv, extension: 'csv') | ||
| end | ||
|
|
||
| # @param [Array<IaaReportingHelper::IaaConfig>] iaas | ||
| # @param [Array<IaaReportingHelper::PartnerConfig>] partner_accounts | ||
| # @return [String] CSV report | ||
| def build_csv(iaas, partner_accounts) | ||
| by_iaa_results = iaas.flat_map do |iaa| | ||
| Db::MonthlySpAuthCount::UniqueMonthlyAuthCountsByIaa.call( | ||
| key: iaa.key, | ||
| issuers: iaa.issuers, | ||
| start_date: iaa.start_date, | ||
| end_date: iaa.end_date, | ||
| ) | ||
| end | ||
|
|
||
| by_issuer_results = iaas.flat_map do |iaa| | ||
| iaa.issuers.flat_map do |issuer| | ||
| Db::MonthlySpAuthCount::TotalMonthlyAuthCountsWithinIaaWindow.call( | ||
| issuer: issuer, | ||
| iaa_start_date: iaa.start_date, | ||
| iaa_end_date: iaa.end_date, | ||
| iaa: iaa.key, | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| by_partner_results = partner_accounts.flat_map do |partner_account| | ||
| Db::MonthlySpAuthCount::NewUniqueMonthlyUserCountsByPartner.call( | ||
| partner: partner_account.partner, | ||
| issuers: partner_account.issuers, | ||
| start_date: partner_account.start_date, | ||
| end_date: partner_account.end_date, | ||
| ) | ||
| end | ||
|
|
||
| combine_by_iaa_month( | ||
| by_iaa_results: by_iaa_results, | ||
| by_issuer_results: by_issuer_results, | ||
| by_partner_results: by_partner_results, | ||
| ) | ||
| end | ||
|
|
||
| def combine_by_iaa_month(by_iaa_results:, by_issuer_results:, by_partner_results:) | ||
| by_iaa_and_year_month = by_iaa_results.group_by do |result| | ||
| [result[:key], result[:year_month]] | ||
| end | ||
|
|
||
| by_issuer_iaa_issuer_year_months = by_issuer_results. | ||
| group_by { |r| r[:iaa] }. | ||
| transform_values do |iaa| | ||
| iaa.group_by { |r| r[:issuer] }. | ||
| transform_values { |issuer| issuer.group_by { |r| r[:year_month] } } | ||
| end | ||
|
|
||
| # rubocop:disable Metrics/BlockLength | ||
| CSV.generate do |csv| | ||
| csv << [ | ||
| 'iaa_order_number', | ||
| 'partner', | ||
| 'iaa_start_date', | ||
| 'iaa_end_date', | ||
|
|
||
| 'issuer', | ||
| 'friendly_name', | ||
|
|
||
| 'year_month', | ||
| 'year_month_readable', | ||
|
|
||
| 'iaa_ial1_unique_users', | ||
| 'iaa_ial2_unique_users', | ||
| 'iaa_ial1_plus_2_unique_users', | ||
| 'partner_ial2_new_unique_users_year1', | ||
| 'partner_ial2_new_unique_users_year2', | ||
| 'partner_ial2_new_unique_users_year3', | ||
| 'partner_ial2_new_unique_users_year4', | ||
| 'partner_ial2_new_unique_users_year5', | ||
| 'partner_ial2_new_unique_users_year_greater_than_5', | ||
| 'partner_ial2_new_unique_users_year_unknown', | ||
|
|
||
| 'issuer_ial1_total_auth_count', | ||
| 'issuer_ial2_total_auth_count', | ||
| 'issuer_ial1_plus_2_total_auth_count', | ||
|
|
||
| 'issuer_ial1_unique_users', | ||
| 'issuer_ial2_unique_users', | ||
| 'issuer_ial1_plus_2_unique_users', | ||
| 'issuer_ial2_new_unique_users', | ||
| ] | ||
| by_issuer_iaa_issuer_year_months.each do |iaa_key, issuer_year_months| | ||
| issuer_year_months.each do |issuer, year_months_data| | ||
| friendly_name = ServiceProvider.find_by(issuer: issuer).friendly_name | ||
| year_months = year_months_data.keys.sort | ||
|
|
||
| year_months.each do |year_month| | ||
| iaa_results = by_iaa_and_year_month[ [iaa_key, year_month] ] | ||
| issuer_results = year_months_data[year_month] | ||
| year_month_start = Date.strptime(year_month, '%Y%m') | ||
| iaa_start_date = Date.parse(iaa_results.first[:iaa_start_date]) | ||
| iaa_end_date = Date.parse(iaa_results.first[:iaa_end_date]) | ||
|
|
||
| partner_results = by_partner_results.find do |result| | ||
| result[:year_month] == year_month && result[:issuers]&.include?(issuer) | ||
| end || {} | ||
| csv << [ | ||
| iaa_key, | ||
| partner_results[:partner], | ||
| iaa_start_date, | ||
| iaa_end_date, | ||
|
|
||
| issuer, | ||
| friendly_name, | ||
|
|
||
| year_month, | ||
| year_month_start.strftime('%B %Y'), | ||
|
|
||
| (iaa_ial1_unique_users = extract(iaa_results, :unique_users, ial: 1)), | ||
| (iaa_ial2_unique_users = extract(iaa_results, :unique_users, ial: 2)), | ||
| iaa_ial1_unique_users + iaa_ial2_unique_users, | ||
| partner_results[:partner_ial2_new_unique_users_year1] || 0, | ||
| partner_results[:partner_ial2_new_unique_users_year2] || 0, | ||
| partner_results[:partner_ial2_new_unique_users_year3] || 0, | ||
| partner_results[:partner_ial2_new_unique_users_year4] || 0, | ||
| partner_results[:partner_ial2_new_unique_users_year5] || 0, | ||
| partner_results[:partner_ial2_new_unique_users_year_greater_than_5] || 0, | ||
| partner_results[:partner_ial2_new_unique_users_year_unknown] || 0, | ||
|
|
||
| (ial1_total_auth_count = extract(issuer_results, :total_auth_count, ial: 1)), | ||
| (ial2_total_auth_count = extract(issuer_results, :total_auth_count, ial: 2)), | ||
| ial1_total_auth_count + ial2_total_auth_count, | ||
|
|
||
| (issuer_ial1_unique_users = extract(issuer_results, :unique_users, ial: 1)), | ||
| (issuer_ial2_unique_users = extract(issuer_results, :unique_users, ial: 2)), | ||
| issuer_ial1_unique_users + issuer_ial2_unique_users, | ||
| extract(issuer_results, :new_unique_users, ial: 2), | ||
| ] | ||
| end | ||
| end | ||
| end | ||
| end | ||
| # rubocop:enable Metrics/BlockLength | ||
| end | ||
|
|
||
| def extract(arr, key, ial:) | ||
| arr.find { |elem| elem[:ial] == ial && elem[key] }&.dig(key) || 0 | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.