-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
18758 - split notebooks for different partners, update vs queries
- Loading branch information
Showing
7 changed files
with
577 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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
File renamed without changes.
260 changes: 260 additions & 0 deletions
260
jobs/notebook-report/daily/vs_reconciliation_details.ipynb
This file contains 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,260 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": false, | ||
"editable": true, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"# Invoice Reconciliation Daily Stats" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"editable": true, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
}, | ||
"pycharm": { | ||
"is_executing": false, | ||
"name": "#%%\n" | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"from datetime import datetime, timedelta\n", | ||
"from config import Config\n", | ||
"\n", | ||
"%load_ext sql\n", | ||
"%config SqlMagic.displaylimit = 5" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [ | ||
"parameters" | ||
] | ||
}, | ||
"source": [ | ||
"# Parameters cell for external parameters via papermill (job running this notebook will insert a parameter cell below this). This cell has a tag of with the name \"parameters\" that is used by papermill\n", | ||
"\n", | ||
"e.g.\n", | ||
"param1 = \"some_value\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": false, | ||
"editable": true, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"This will create the connection to the database and prep the jupyter magic for SQL" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"editable": true, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
}, | ||
"pycharm": { | ||
"is_executing": false, | ||
"name": "#%%\n" | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%sql $Config.SQLALCHEMY_DATABASE_URI" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": false, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
} | ||
}, | ||
"source": [ | ||
"Simplest query to run to ensure our libraries are loaded and our DB connection is working" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
}, | ||
"pycharm": { | ||
"is_executing": false, | ||
"name": "#%%\n" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%sql\n", | ||
"select now() AT TIME ZONE 'PST' as current_date" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": false, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
} | ||
}, | ||
"source": [ | ||
"Daily query for details data." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"editable": true, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
}, | ||
"pycharm": { | ||
"is_executing": false, | ||
"name": "#%%\n" | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%sql daily_reconciliation_details <<\n", | ||
"SELECT i.created_on, i.updated_on, i.id, ir.invoice_number, (i.total - i.service_fees) AS subtotal, i.service_fees, i.total, i.disbursement_status_code, i.payment_method_code, i.invoice_status_code, i.corp_type_code\n", | ||
"FROM invoices i join invoice_references ir on ir.invoice_id = i.id\n", | ||
"WHERE i.corp_type_code = :partner_code\n", | ||
"AND i.invoice_status_code IN ('PAID', 'REFUNDED', 'CANCELLED', 'CREDITED')\n", | ||
"AND i.payment_method_code IN ('PAD','EJV', 'DRAWDOWN')\n", | ||
"AND date(i.created_on) > date(current_date - 1 - interval '1 days')\n", | ||
"AND date(i.created_on) <= date(current_date - 1)\n", | ||
"ORDER BY 1;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": false, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
} | ||
}, | ||
"source": [ | ||
"Save to CSV" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false, | ||
"editable": true, | ||
"jupyter": { | ||
"outputs_hidden": false | ||
}, | ||
"pycharm": { | ||
"is_executing": false, | ||
"name": "#%%\n" | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"filename = os.path.join(os.getcwd(), r'data/')+partner_code+'_daily_reconciliation_' + datetime.strftime(datetime.now()-timedelta(1), '%Y-%m-%d') +'.csv'\n", | ||
"df = daily_reconciliation_details.DataFrame()\n", | ||
"\n", | ||
"with open(filename, 'w') as f:\n", | ||
" f.write('Daily Reconciliation Details:\\n\\n')\n", | ||
" if df.empty:\n", | ||
" f.write('No Data Retrieved')\n", | ||
" else:\n", | ||
" df.to_csv(f, sep=',', encoding='utf-8', index=False)\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"celltoolbar": "Tags", | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.4" | ||
}, | ||
"pycharm": { | ||
"stem_cell": { | ||
"cell_type": "raw", | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"source": [] | ||
} | ||
}, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "fcb35bce15c55b4cacb5112e543368f86c7f98ed17acd45e6841ee83ed1df6e3" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
File renamed without changes.
Oops, something went wrong.