Skip to content

Instantly share code, notes, and snippets.

@russellkt
Created August 4, 2016 19:31
Show Gist options
  • Save russellkt/d94c5c9eeb0db049b2ee7c68f5b9b1f5 to your computer and use it in GitHub Desktop.
Save russellkt/d94c5c9eeb0db049b2ee7c68f5b9b1f5 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
# Imports to make report run local and Report Runner
import os, sys
sys.path.append(os.path.join('bin'))
sys.path.append(os.path.join('lib'))
# Used for Report Runner
sys.path.append('/srv/britecore/lib')
sys.path.append('/srv/britecore/bin')
INPUT_DIR = '/tmp/input'
OUTPUT_DIR = '/tmp/output'
DF_PATH = '/tmp/df_cache_root' # Only needed if not using BriteDataFrame
DF_PREP_PATH = 'tmp/df_prep_cache_root'
sys.path.append(INPUT_DIR)
import numpy as np
import pandas as pd
from reports.utils import BriteDataFrame, PreparedDataFrame
bdf = BriteDataFrame()
pdf = PreparedDataFrame()
pmt_df = bdf.get_dataframe('policy_payments')
acct_df = pdf.get_dataframe('accounting')
term_df = bdf.get_dataframe('policy_terms')
pol_df = bdf.get_dataframe('policies')
pmt_acct = pd.merge(pmt_df, acct_df, left_on='policyPaymentId', right_on="paymentId", how='inner')
pmt_term = pd.merge(pmt_acct, term_df, on='policyTermId', how='inner')
pmt_pol = pd.merge(pmt_term, pol_df, on='policyId', how='inner')
nondeleted = pmt_pol[pmt_pol['deleted']==0]
nondeleted.replace(['Money Order'], ['Check'], inplace=True)
nondeleted['Transaction Date']=nondeleted['accountingTransactionDate'].dt.date
nondeleted = nondeleted[['policyNumber','Transaction Date','accountingTransactionDate','paymentAccountName','paymentMethod',
'changeInGrossPayments','changeInPaidSystemFee','changeInAdvancedPremium','changeInPaidPremium']]
nondeleted['Total Premium']=nondeleted['changeInAdvancedPremium']+nondeleted['changeInPaidPremium']
nondeleted.paymentMethod.fillna(nondeleted.paymentAccountName, inplace=True)
nondeleted.to_csv(os.path.join(OUTPUT_DIR,"payment_with_methods.csv"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment