Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.py 4.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  1. import os
  2. import pandas as pd
  3. from sqlalchemy import create_engine
  4. import dash
  5. import dash_core_components as dcc
  6. import dash_html_components as html
  7. import dash_table
  8. import plotly.graph_objects as go
  9. import plotly.express as px
  10. from dash.dependencies import Input, Output
  11. from lendingclub import config
  12. external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
  13. # load api_loans df and historical scores df
  14. disk_engine = create_engine(f'sqlite:///{config.lc_api_db}')
  15. df = pd.read_sql('lc_api_loans',
  16. con=disk_engine,
  17. parse_dates=[
  18. 'accept_d', 'exp_d', 'list_d', 'credit_pull_d',
  19. 'review_status_d', 'ils_exp_d', 'last_seen_list_d'
  20. ])
  21. hist_df = pd.read_feather(
  22. os.path.join(config.data_dir, 'all_eval_loan_info_scored.fth'))
  23. # setup some constants for use in app
  24. rounds = sorted(df['list_d'].dt.hour.unique())
  25. min_date = df['list_d'].min().date()
  26. max_date = df['list_d'].max().date()
  27. print(min_date, max_date)
  28. app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
  29. app.layout = html.Div([
  30. html.H3('API loans'),
  31. html.Div([
  32. dcc.DatePickerRange(id='api-loans-date-picker-range',
  33. start_date=max_date,
  34. end_date=max_date,
  35. min_date_allowed=min_date,
  36. # for some reason I couldn't select max date
  37. max_date_allowed=max_date + pd.DateOffset(days=1),),
  38. html.Div(id='api-loans-date-picker-range-info')
  39. ]),
  40. html.Div([
  41. dcc.Dropdown(id='api-loans-round-dropdown',
  42. options=[{'label':i, 'value': i} for i in rounds],
  43. multi=True,
  44. value=rounds),
  45. html.Div(id='api-loans-round-dropdown-info')
  46. ]),
  47. dcc.Graph(id='api-loans-graph', ),
  48. dash_table.DataTable(
  49. id='api-table',
  50. columns=[{
  51. "name": i,
  52. "id": i
  53. } for i in df.columns],
  54. fixed_columns={
  55. 'headers': True,
  56. 'data': 1
  57. },
  58. fixed_rows={
  59. 'headers': True,
  60. 'data': 0
  61. },
  62. style_table={
  63. 'maxHeight': '250px',
  64. 'maxWidth': '900px',
  65. 'overflowY': 'scroll',
  66. 'overflowX': 'scroll'
  67. },
  68. style_cell={'width': '150px'},
  69. style_data_conditional=[{
  70. 'if': {
  71. 'row_index': 'odd'
  72. },
  73. 'backgroundColor': 'rgb(248, 248, 248)'
  74. }],
  75. style_header={
  76. 'backgroundColor': 'rgb(230, 230, 230)',
  77. 'fontWeight': 'bold',
  78. 'border': '1px solid pink',
  79. },
  80. style_data={},
  81. ),
  82. html.H3('CSV loans'),
  83. ])
  84. ##### CALLBACKS #####
  85. @app.callback(
  86. Output('api-table', 'data'),
  87. [Input('api-loans-date-picker-range', 'start_date'),
  88. Input('api-loans-date-picker-range', 'end_date'),
  89. Input('api-loans-round-dropdown', 'value'),]
  90. )
  91. def update_api_table(start_date, end_date, listing_sess):
  92. sub_df = df.query('list_d >= @start_date and list_d <= @end_date and list_d_hour in @listing_sess')
  93. return sub_df.to_dict('records')
  94. @app.callback(
  95. Output('api-loans-date-picker-range-info', 'children'),
  96. [Input('api-loans-date-picker-range', 'start_date'),
  97. Input('api-loans-date-picker-range', 'end_date'),]
  98. )
  99. def update_api_loans_date_picker_range_info(start_date, end_date):
  100. return f'Dates selected from {start_date} to {end_date}'
  101. @app.callback(
  102. Output('api-loans-round-dropdown-info', 'children'),
  103. [Input('api-loans-round-dropdown', 'value'),]
  104. )
  105. def update_api_loans_round_dropdown_info(value):
  106. '''
  107. So far, haven't been able to find how to sort multi-select dropdown.
  108. '''
  109. return f'Selected daily loan release rounds {", ".join([str(i) for i in sorted(value)])}'
  110. @app.callback(
  111. Output('api-loans-graph', 'figure'),
  112. [Input('api-loans-date-picker-range', 'start_date'),
  113. Input('api-loans-date-picker-range', 'end_date'),
  114. Input('api-loans-round-dropdown', 'value'),]
  115. )
  116. def update_api_loans_graph(start_date, end_date, listing_sess):
  117. sub_df = df.query('list_d >= @start_date and list_d <= @end_date and list_d_hour in @listing_sess')
  118. fig = px.histogram(sub_df, x='catboost_comb_20', nbins=100, histnorm='probability density', color='sub_grade', marginal='rug')
  119. return fig
  120. if __name__ == '__main__':
  121. app.run_server(debug=True)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...