本記事では CData サポート担当からこんなことを聞かれたらどこを確認すべきか?という観点で、よく頂くお問合せ内容をご紹介します。
記事はこちら →Pythonエコシステムには、多くのモジュールがあり、システム構築を素早く効率的に行うことができます。CData Python Connector for BullhornCRM を使うことで、pandas モジュールとDash フレームワークでBullhorn CRM にデータ連携するアプリケーションを効率的に開発することができます。本記事では、pandas、Dash とCData Connector を使って、Bullhorn CRM に連携して、Bullhorn CRM data をビジュアライズするシンプルなウエブアプリを作ります。
CData Python Connector は、ビルトインされた効率的なデータプロセスにより、リアルタイムBullhorn CRM data データにPython からアクセスし、高いパフォーマンスと接続性を発揮します。Bullhorn CRM に複雑なクエリを投げる際に、ドライバーはフィルタリング、集計などがサポートされている場合、SQL 処理を直接Bullhorn CRM 側に行わせ、サポートされていないSQL 処理については、組み込まれたSQL エンジンによりクライアント側で処理を行います(特にJOIN やSQL 関数など)。
Bullhorn CRM data への連携は、RDB ソースへのアクセスと同感覚で行うことができます。必要な接続プロパティを使って接続文字列を作成します。本記事では、接続文字列をcreate_engine 関数のパラメータとして送ります。
Begin by providing your Bullhorn CRM account credentials in the following:
If you are uncertain about your data center code, codes like CLS2, CLS21, etc. are cluster IDs that are contained in a user's browser URL (address bar) once they are logged in.
Example: https://cls21.bullhornstaffing.com/BullhornSTAFFING/MainFrame.jsp?#no-ba... indicates that the logged in user is on CLS21.
Bullhorn CRM uses the OAuth 2.0 authentication standard. To authenticate using OAuth, create and configure a custom OAuth app. See the Help documentation for more information.
以下の手順に従い、必要なモジュールをインストールし、Python オブジェクト経由でBullhorn CRM にアクセスします。
pip で必要なモジュールおよびフレームワークをインストールします:
pip install pandas pip install dash pip install dash-daq
必要なモジュールとフレームワークがインストールされたら、ウェブアプリを開発していきます。コードのスニペットは以下の通りです。フルコードは記事の末尾に付いています。
まず、CData Connector を含むモジュールをインポートします:
import os import dash import dash_core_components as dcc import dash_html_components as html import pandas as pd import cdata.bullhorncrm as mod import plotly.graph_objs as go
接続文字列を使ってデータへの接続を確立します。connect 関数を使ってCData Bullhorn CRM Connector にBullhorn CRM data との接続を確立します。
cnxn = mod.connect("DataCenterCode=CLS33;OAuthClientId=myoauthclientid;OAuthClientSecret=myoauthclientsecret;InitiateOAuth=GETANDREFRESH;OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt")")
read_sql 関数を使って、padas からSQL 文を発行し、DataFrame に結果を格納します。
df = pd.read_sql("""SELECT Id, CandidateName FROM Candidate WHERE CandidateName = 'Jane Doe'""", cnxn)
DataFrame に格納されたクエリ結果を使って、ウェブアプリにname、stylesheet、title を設定していきます。
app_name = 'dash-bullhorncrmedataplot' external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] app = dash.Dash(__name__, external_stylesheets=external_stylesheets) app.title = 'CData + Dash'
次に、Bullhorn CRM data をベースにした棒グラフを作詞し、アプリのレイアウトを設定します。
trace = go.Bar(x=df.Id, y=df.CandidateName, name='Id') app.layout = html.Div(children=[html.H1("CData Extention + Dash", style={'textAlign': 'center'}), dcc.Graph( id='example-graph', figure={ 'data': [trace], 'layout': go.Layout(alt='Bullhorn CRM Candidate Data', barmode='stack') }) ], className="container")
接続、アプリ、レイアウトを定義したら、アプリを実行してみましょう。Python コードの最後はこのようです。
if __name__ == '__main__': app.run_server(debug=True)
では、Python でウェブアプリを稼働させて、ブラウザでBullhorn CRM data を見てみましょう。
python bullhorncrm-dash.py
Bullhorn CRM Python Connector の30日の無償トライアル をぜひダウンロードして、Bullhorn CRM data への接続をPython アプリやスクリプトから簡単に作成しましょう。
import os import dash import dash_core_components as dcc import dash_html_components as html import pandas as pd import cdata.bullhorncrm as mod import plotly.graph_objs as go cnxn = mod.connect("DataCenterCode=CLS33;OAuthClientId=myoauthclientid;OAuthClientSecret=myoauthclientsecret;InitiateOAuth=GETANDREFRESH;OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt") df = pd.read_sql("SELECT Id, CandidateName FROM Candidate WHERE CandidateName = 'Jane Doe'", cnxn) app_name = 'dash-bullhorncrmdataplot' external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] app = dash.Dash(__name__, external_stylesheets=external_stylesheets) app.title = 'CData + Dash' trace = go.Bar(x=df.Id, y=df.CandidateName, name='Id') app.layout = html.Div(children=[html.H1("CData Extention + Dash", style={'textAlign': 'center'}), dcc.Graph( id='example-graph', figure={ 'data': [trace], 'layout': go.Layout(alt='Bullhorn CRM Candidate Data', barmode='stack') }) ], className="container") if __name__ == '__main__': app.run_server(debug=True)