本ページでは、Realtime Compute のパートナーである Gegejia のユースケースを紹介し、Realtime Compute を使用してリアルタイムページビュー (PV) とユニークビジター (UV) 曲線を作成する方法を説明します。
概要
新しいリテールの台頭に伴い、インターネット E コマース業界での競争はますます激しくなっています。 リアルタイムデータは、PV と UV の合計に関する統計を Web サイトに収集するなど、E コマース業界にとって特に重要です。
ユースケース
- ビジネスアーキテクチャー
- ビジネスプロセス
- binlog ファイルを DataHub に同期するには、DataHub が提供する SDK を使用します。
- Realtime Compute を使用して、DataHub のデータをサブスクライブし、リアルタイムコンピューティングを行います。
- リアルタイムデータを RDS に挿入します。
- Alibaba Cloud DataV またはその他のビジュアルダッシュボードにデータを表示します。
- 準備
次の表では、ログソーステーブルのフィールドについて説明します。
フィールド名 データ型 説明 account_id VARCHAR ユーザーの ID client_ip VARCHAR クライアントの IP アドレス client_info VARCHAR デバイスのモデル platform VARCHAR デバイスのオペレーティングシステムタイプ imei VARCHAR デバイスの国際モバイル機器 ID (IMEI) 番号 version BIGINT デバイスのオペレーティングシステムのバージョン action BIGINT ページジャンプの説明 gpm VARCHAR トラッキングパス c_time VARCHAR リクエストが送信される時刻 target_type VARCHAR 要求されたデータのタイプ target_id VARCHAR 要求されたデータの ID udata VARCHAR 拡張情報 session_id VARCHAR セッションの ID product_id_chain VARCHAR 製品 ID の文字列 cart_product_id_chain VARCHAR カートに追加された商品の ID 文字列 tag VARCHAR 特別なタグ position VARCHAR ユーザーの場所 network VARCHAR ユーザーのネットワークタイプ p_dt VARCHAR 日ごとの時分割 p_platform VARCHAR パーティションシステムのバージョン 次の表では、RDS 結果テーブルのフィールドについて説明します。
フィールド名 データ型 説明 summary_date BIGINT 統計が収集される日付 summary_min VARCHAR 統計が収集される時間 (分) pv BIGINT 指定された Web サイトのクリック数 uv BIGINT 指定された Web サイトをクリックした訪問者の数 注 1 日以内に同じ訪問者が複数回クリックした場合は、UV は 1 つだけカウントされます。currenttime TIMESTAMP 現在のシステム時刻 - ビジネスロジック
// Create source tables. CREATE TABLE source_ods_fact_log_track_action ( account_id VARCHAR, // The ID of the user. client_ip VARCHAR, // The IP address of the client. client_info VARCHAR, // The model of the device. platform VARCHAR, // The operating system type of the device. imei VARCHAR, // The IMEI number of the device. `version` VARCHAR, // The operating system version of the device. `action` VARCHAR, // The page jump description. gpm VARCHAR, // The tracking path. c_time VARCHAR, // The time when the request was made. target_type VARCHAR, // The type of requested data. target_id VARCHAR, // The ID of requested data. udata VARCHAR, // The extended information in JSON format. session_id VARCHAR, // The ID of the session. product_id_chain VARCHAR, // The string of product IDs. cart_product_id_chain VARCHAR, // The ID string of the products added to the car. tag VARCHAR, // The special tag. `position` VARCHAR, // The location of the user. network VARCHAR, // The network type of the user. p_dt VARCHAR, // The time partition by day. p_platform VARCHAR // The partition system version. ) WITH ( type='datahub', endPoint='yourEndpointURL', project='yourProjectName', topic='yourTopicName', accessId='yourAccessId', accessKey='yourAccessSecret', batchReadSize='1000' ); CREATE TABLE result_cps_total_summary_pvuv_min ( summary_date BIGINT, // The date when the statistics are collected. summary_min VARCHAR, // The minute when the statistics are collected. pv BIGINT, // The number of clicks on the specified website. uv BIGINT, // The number of visitors who click the specified website. Only one UV is counted for multiple clicks by the same visitor within one day. currenttime TIMESTAMP, // The current system time. primary key (summary_date,summary_min) ) WITH ( type= 'rds', url = 'yourRDSDatabaseURL', userName = 'yourDatabaseUserName', password = 'yourDatabasePassword', tableName = 'yourTableName' ); CREATE VIEW result_cps_total_summary_pvuv_min_01 AS select cast(p_dt as BIGINT) as summary_date // The time partition by day. ,count(client_ip) as pv // Compute the number of PVs by client IP address. ,count(distinct client_ip) as uv // Deduplicate visitors by client IP address. ,cast(max(c_time ) as TIMESTAMP) as c_time // The time when the request was made. from source_ods_fact_log_track_action group by p_dt; INSERT into result_cps_total_summary_pvuv_min select a.summary_date, // The time partition by day. cast(DATE_FORMAT(c_time,'HH:mm') as VARCHAR) as summary_min, // Obtain the time string representing the hour and minute. a.pv, a.uv, CURRENT_TIMESTAMP as currenttime // The current system time. from result_cps_total_summary_pvuv_min_01 AS a ;
- キーポイント
構造化コードを理解し、コードのメンテナンスを容易にするために、ビューを使用してビジネスロジックを 2 つのモジュールに分割することを推奨します。 ビューについての詳細は、「データビューの作成 (Create a data view)」をご参照ください。
- モジュール 1
CREATE VIEW result_cps_total_summary_pvuv_min_01 AS select cast(p_dt as BIGINT) as summary_date // The time partition by day. ,count(client_ip) as pv // Compute the number of PVs by client IP address. ,count(distinct client_ip) as uv // Deduplicate visitors by client IP address. ,cast(max(c_time ) as TIMESTAMP) as c_time // The time when the request was made. from source_ods_fact_log_track_action group by p_dt;
- クライアントの IP アドレスで Web サイトのクリック数を計算し、PV の数として使用します。 UV の数を計算するために、クライアント IP アドレスごとに訪問者の重複を排除します。
cast(max(c_time) as TIMESTAMP)
// 最後のリクエストが行われた時刻です。- このビジネスロジックコードのスニペットは、データを
p_dt
(day
によってタイムパーティションを指定) でグループ化し、max(c_time)
を使用してタイムパーティションの最後のアクセス時間を判定します。 最後に、Realtime Compute は PV と UV の数をデータベースに挿入します。
パラメーターについて、次のテーブルで説明します。
p_dt pv uv max(c_time)
2017-12-12 1000 100 2017-12-12 9:00:00
2017-12-12 1500 120 2017-12-12 9:01:00
2017-12-12 2200 200 2017-12-12 9:02:00
2017-12-12 3300 320 2017-12-12 9:03:00
- モジュール 2
INSERT into result_cps_total_summary_pvuv_min select a.summary_date, // The time partition by day. cast(DATE_FORMAT(c_time,'HH:mm') as VARCHAR) as summary_min, // Obtain the time string representing the hour and minute. a.pv, a.uv, CURRENT_TIMESTAMP as currenttime // The current system time. from result_cps_total_summary_pvuv_min_01 AS a
次の図に示すように、モジュール 1 のデータを時間と分で抽出し、PV と UV の成長曲線を取得します。
- モジュール 1