Last active
April 20, 2021 20:05
-
-
Save emailrhoads/70a926ed2814f786745a9d280f9edeb6 to your computer and use it in GitHub Desktop.
[CRA evaluate old vs new] #crape
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
| old_results = Crape::BatchLoanRun.all; | |
| with_attrs = old_results.map do |e| | |
| e.slice('loan_number') + e.loan_run.attributes | |
| end; | |
| CSV.open("old_cra_results.tsv", "w", write_headers: true, headers: with_attrs.first.keys, col_sep: "\t") do |csv| | |
| with_attrs.each do |h| | |
| csv << h.values | |
| end | |
| end; | |
| new_results = Crape::New::LoanRun.all.attributes; | |
| CSV.open("new_results.tsv", "w", write_headers: true, headers: new_results.first.keys, col_sep: "\t") do |csv| | |
| new_results.each do |h| | |
| csv << h.values | |
| end | |
| end; | |
| results = ActiveRecord::Base.connection.execute(<<~SQL.squish) | |
| SELECT | |
| (CASE | |
| WHEN | |
| COALESCE(lr.tract_income_category::text, 'NULL') = COALESCE(nlr.tract_income_category::text, 'NULL') | |
| AND | |
| COALESCE(lr.application_income_category::text, 'NULL') = COALESCE(nlr.appl_inc_perc_of_median::text, 'NULL') | |
| THEN 'Match' | |
| ELSE 'No Match' | |
| END) as reconciliation_status, | |
| blr.loan_number, | |
| lr.*, | |
| nlr.* | |
| FROM | |
| crape_batch_loan_runs blr | |
| JOIN crape_loan_runs lr ON blr.loan_run_id = lr.id | |
| FULL OUTER JOIN crape_new_loan_runs nlr | |
| ON nlr.loan_number = blr.loan_number | |
| AND lr.total_monthly_income_amount = nlr.total_monthly_income_amount | |
| SQL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment