Example #1
0
def current_loans_results():
    mform = cl_form(request.form) 
    if request.method == 'GET':
        mform = app.cl_form

    bool_vals = {'use_A':'A','use_B':'B','use_C':'C','use_D':'D',
                 'use_E':'E','use_F':'F'}
    constraints = {}
    constraints['use_grades'] = [bool_vals[key] for key in bool_vals.keys() \
                                if mform.data[key]]
    constraints['max_dp'] = mform.data['max_dp']
    
    allowed_loans = predictions[(predictions.dp <= constraints['max_dp']) & \
                                (predictions.grades.isin(constraints['use_grades']))]
    pick_K = min([mform.data['port_size'], len(allowed_loans)])

    loan_ids_string = ', '.join(allowed_loans[:pick_K]['ids'].values.astype(str))
    fig = LCP.make_dp_ret_figure(predictions, pick_K, allowed_loans)
    plt.savefig(fig_dir + 'cl_dp_ret.png', dpi=500, format='png')
    plt.close()
    
    if pick_K > 0:
        fig = LCP.make_return_dist_fig(sim_lookup, allowed_loans, pick_K)
        plt.savefig(fig_dir + 'cl_ret_dist.png', dpi=500, format='png')
        plt.close()
        
    return render_template('current_loan_results.html', cl_form=mform, 
                           pick_K=pick_K, rnum=np.random.randint(0,100000),
                           loan_ids=loan_ids_string) 
Example #2
0
def current_loans_results():
    mform = cl_form(request.form)
    if request.method == 'GET':
        mform = app.cl_form

    bool_vals = {
        'use_A': 'A',
        'use_B': 'B',
        'use_C': 'C',
        'use_D': 'D',
        'use_E': 'E',
        'use_F': 'F'
    }
    constraints = {}
    constraints['use_grades'] = [bool_vals[key] for key in bool_vals.keys() \
                                if mform.data[key]]
    constraints['max_dp'] = mform.data['max_dp']

    allowed_loans = predictions[(predictions.dp <= constraints['max_dp']) & \
                                (predictions.grades.isin(constraints['use_grades']))]
    pick_K = min([mform.data['port_size'], len(allowed_loans)])

    loan_ids_string = ', '.join(
        allowed_loans[:pick_K]['ids'].values.astype(str))
    fig = LCP.make_dp_ret_figure(predictions, pick_K, allowed_loans)
    plt.savefig(fig_dir + 'cl_dp_ret.png', dpi=500, format='png')
    plt.close()

    if pick_K > 0:
        fig = LCP.make_return_dist_fig(sim_lookup, allowed_loans, pick_K)
        plt.savefig(fig_dir + 'cl_ret_dist.png', dpi=500, format='png')
        plt.close()

    return render_template('current_loan_results.html',
                           cl_form=mform,
                           pick_K=pick_K,
                           rnum=np.random.randint(0, 100000),
                           loan_ids=loan_ids_string)
Example #3
0
def current_loans():
    global predictions, load_time
    
    cur_time = time.time()
    if (cur_time - load_time) > refresh_loan_time:       
        load_time = cur_time        
        print('Grabbing loan data at {}'.format(load_time))
        predictions = LCP.get_LC_loans(auth_keys['LC_auth_key'], model_data,
                                       zip3_loc_data, use_grades)
    
    mform = cl_form(request.form)          
    if request.method == 'POST':
        app.cl_form = mform
        return redirect('/current_loans_results') 
       
    else:
        fig = LCP.make_dp_ret_figure(predictions, 0, predictions)
        plt.savefig(fig_dir + 'cl_dp_ret.png', dpi=500, format='png')
        plt.close()
            
        return render_template('current_loans.html', cl_form=mform, 
                               rnum=np.random.randint(0,100000),
                               tot_loans=len(predictions)) 
Example #4
0
def current_loans():
    global predictions, load_time

    cur_time = time.time()
    if (cur_time - load_time) > refresh_loan_time:
        load_time = cur_time
        print('Grabbing loan data at {}'.format(load_time))
        predictions = LCP.get_LC_loans(auth_keys['LC_auth_key'], model_data,
                                       zip3_loc_data, use_grades)

    mform = cl_form(request.form)
    if request.method == 'POST':
        app.cl_form = mform
        return redirect('/current_loans_results')

    else:
        fig = LCP.make_dp_ret_figure(predictions, 0, predictions)
        plt.savefig(fig_dir + 'cl_dp_ret.png', dpi=500, format='png')
        plt.close()

        return render_template('current_loans.html',
                               cl_form=mform,
                               rnum=np.random.randint(0, 100000),
                               tot_loans=len(predictions))
Example #5
0
#get lat/long coordinates for each 3-digit zip
zip3_loc_path = os.path.join(data_dir,'zip3_loc_data.p')
with open(zip3_loc_path,'rb') as in_strm:
    zip3_loc_data = dill.load(in_strm)       

# precompute additional columns for convenience when plotting
LD['short_purpose'] = LD['purpose'].map(purpose_map)
LD['issue_year'] = LD['issue_d'].dt.year

# load base map and get state and county paths
app.base_map = LCL.load_base_map(fig_dir + map_name)
(app.county_paths,app.state_paths) = LCL.get_map_paths(app.base_map,fips_to_zip)

predictor = namedtuple('predictor', ['col_name', 'full_name', 'norm_type'])
model_data = LCP.load_pickled_models()
sim_lookup = LCP.get_validation_data()

#%%
use_grades = ['A','B','C','D','E','F']
load_time = time.time()
print('Grabbing loan data at {}'.format(load_time))
predictions = LCP.get_LC_loans(auth_keys['LC_auth_key'], model_data,
                               zip3_loc_data, use_grades)
                               
#%%
@app.route('/') #redirect to index page
def main():
    return redirect('/index')

Example #6
0
#get lat/long coordinates for each 3-digit zip
zip3_loc_path = os.path.join(data_dir, 'zip3_loc_data.p')
with open(zip3_loc_path, 'rb') as in_strm:
    zip3_loc_data = dill.load(in_strm)

# precompute additional columns for convenience when plotting
LD['short_purpose'] = LD['purpose'].map(purpose_map)
LD['issue_year'] = LD['issue_d'].dt.year

# load base map and get state and county paths
app.base_map = LCL.load_base_map(fig_dir + map_name)
(app.county_paths,
 app.state_paths) = LCL.get_map_paths(app.base_map, fips_to_zip)

predictor = namedtuple('predictor', ['col_name', 'full_name', 'norm_type'])
model_data = LCP.load_pickled_models()
sim_lookup = LCP.get_validation_data()

#%%
use_grades = ['A', 'B', 'C', 'D', 'E', 'F']
load_time = time.time()
print('Grabbing loan data at {}'.format(load_time))
predictions = LCP.get_LC_loans(auth_keys['LC_auth_key'], model_data,
                               zip3_loc_data, use_grades)


#%%
@app.route('/')  #redirect to index page
def main():
    return redirect('/index')