Skip to content

Commit

Permalink
Merge pull request kaltura#2154 from kaltura/Jupiter-10.3.0-top-playb…
Browse files Browse the repository at this point in the history
…ackContext-report

Jupiter 10.3.0 top playback context report
  • Loading branch information
olampert committed Jan 20, 2015
2 parents 54ca895 + fc89023 commit 33b3545
Show file tree
Hide file tree
Showing 25 changed files with 678 additions and 18 deletions.
53 changes: 36 additions & 17 deletions alpha/apps/kaltura/lib/reports/myReportsMgr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class myReportsMgr
const REPORT_TYPE_OPERATION_SYSTEM = 22;
const REPORT_TYPE_BROWSERS = 23;
const REPORT_TYPE_LIVE = 24;
const REPORT_TYPE_TOP_PLAYBACK_CONTEXT = 25;

const REPORTS_TABLE_MAX_QUERY_SIZE = 20000;
const REPORTS_CSV_MAX_QUERY_SIZE = 130000;
Expand All @@ -59,7 +60,8 @@ class myReportsMgr
static $end_user_filter_get_count_reports = array (self::REPORT_TYPE_PLATFORMS,
self::REPORT_TYPE_OPERATION_SYSTEM,
self::REPORT_TYPE_BROWSERS,
self::REPORT_TYPE_TOP_CONTENT);
self::REPORT_TYPE_TOP_CONTENT,
self::REPORT_TYPE_TOP_PLAYBACK_CONTEXT);


public static function runQuery ( $query_file , $map , $debug = false )
Expand Down Expand Up @@ -671,7 +673,7 @@ private static function createCacheKey ( $partner_id , $report_type , reportsInp
$input_filter->from_date . $input_filter->to_date . $input_filter->keywords . $input_filter->search_in_admin_tags . $input_filter->search_in_tags . $input_filter->interval .
$object_ids . $input_filter->categories;
if ($input_filter instanceof endUserReportsInputFilter)
$key = $key . $input_filter->application . $input_filter->userIds . $input_filter->playbackContext;
$key = $key . $input_filter->application . $input_filter->userIds . $input_filter->playbackContext . $input_filter->ancestorPlaybackContext;
return $key;
}

Expand Down Expand Up @@ -731,23 +733,30 @@ private static function executeQueryByType ( $partner_id , $report_type , $repor
$category_ids_clause = "1=1";
if ($input_filter instanceof endUserReportsInputFilter)
{
if ($input_filter->playbackContext)
if ($input_filter->playbackContext || $input_filter->ancestorPlaybackContext)
{
$categoryFilter = new categoryFilter();
$categoryFilter->set("_in_full_name", $input_filter->playbackContext);
$c = KalturaCriteria::create(categoryPeer::OM_CLASS);
$categoryFilter->attachToCriteria($c);
$c->applyFilters();

$categoryIdsFromDB = $c->getFetchedIds();

if (count($categoryIdsFromDB))
$categoryIds = implode(",", $categoryIdsFromDB);
else
if ($input_filter->playbackContext && $input_filter->ancestorPlaybackContext)
$categoryIds = category::CATEGORY_ID_THAT_DOES_NOT_EXIST;
else {
if ($input_filter->playbackContext)
$categoryFilter->set("_in_full_name", $input_filter->playbackContext);
if ($input_filter->ancestorPlaybackContext)
$categoryFilter->set("_matchor_likex_full_name", $input_filter->ancestorPlaybackContext);

$c = KalturaCriteria::create(categoryPeer::OM_CLASS);
$categoryFilter->attachToCriteria($c);
$c->applyFilters();

$categoryIdsFromDB = $c->getFetchedIds();

if (count($categoryIdsFromDB))
$categoryIds = implode(",", $categoryIdsFromDB);
else
$categoryIds = category::CATEGORY_ID_THAT_DOES_NOT_EXIST;
}

$category_ids_clause = "ev.context_id in ( $categoryIds )";

}
}

Expand Down Expand Up @@ -915,7 +924,8 @@ private static function executeQueryByType ( $partner_id , $report_type , $repor
self::REPORT_TYPE_PLATFORMS => 'platforms',
self::REPORT_TYPE_OPERATION_SYSTEM => 'os',
self::REPORT_TYPE_BROWSERS => 'browsers',
self::REPORT_TYPE_LIVE => "live" ,
self::REPORT_TYPE_LIVE => "live",
self::REPORT_TYPE_TOP_PLAYBACK_CONTEXT => "top_playback_context",

);

Expand Down Expand Up @@ -1112,6 +1122,14 @@ private static function getOrderBy ( $report_type , $order_by )
),
"live" => array (
"count_plays"
),
"top_playback_context" => array (
"count_plays" ,
"sum_time_viewed" ,
"avg_time_viewed" ,
"count_loads" ,
"avg_view_drop_off",
"load_play_ratio" ,
)
);

Expand Down Expand Up @@ -1433,13 +1451,14 @@ class endUserReportsInputFilter extends reportsInputFilter
public $application;
public $userIds;
public $playbackContext;
public $ancestorPlaybackContext;

public function getFilterBy() {
$filterBy = "";
if ($this->playbackContext != null)
if ($this->playbackContext != null || $this->ancestorPlaybackContext != null)
$filterBy = "_by_context";
if ($this->userIds != null)
$filterBy = "_by_user";
$filterBy = $filterBy . "_by_user";
if ($this->application != null)
$filterBy = $filterBy . "_by_app";

Expand Down
67 changes: 67 additions & 0 deletions alpha/apps/kaltura/lib/reports/myReportsSqlFileMgr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,73 @@ private static function getFileNameMappingConfig ( $type_str , $flavor_str , $no
"count_without_filter" => "count",
"count_no_text" => "count",
),
"top_playback_context" => array (
"graph_no_text" => "user_engagement/graph_no_text",
"graph_without_filter" => "user_engagement/graph_by_context",
"graph_by_context" => "user_engagement/graph_by_context",
"graph_by_context_for_objects" => "user_engagement/graph_by_context_for_objects",
"graph_by_context_by_user" => "user_engagement/graph_by_user",
"graph_by_context_by_user_for_objects" => "user_engagement/graph_by_user",
"graph_by_context_by_app" => "user_engagement/graph_by_app",
"graph_by_context_by_app_for_objects" => "user_engagement/graph_by_app_for_objects",
"graph_by_context_by_user_by_app" => "user_engagement/graph_by_user_by_app",
"graph_by_context_by_user_by_app_for_objects" => "user_engagement/graph_by_user_by_app",
"graph_by_user" => "user_engagement/graph_by_user",
"graph_by_user_for_objects" => "user_engagement/graph_by_user",
"graph_by_user_by_app" => "user_engagement/graph_by_user_by_app",
"graph_by_user_by_app_for_objects" => "user_engagement/graph_by_user_by_app",
"graph_by_app" => "user_engagement/graph_by_app",
"graph_by_app_for_objects" => "user_engagement/graph_by_app_for_objects",
"total_no_text" => "user_engagement/total_no_text",
"total_without_filter" => "user_engagement/total_by_context",
"total_by_context" => "user_engagement/total_by_context",
"total_by_context_for_objects" => "total_by_context_for_objects",
"total_by_context_by_user" => "total_by_user",
"total_by_context_by_user_for_objects" => "total_by_user",
"total_by_context_by_app" => "user_engagement/total_by_app",
"total_by_context_by_app_for_objects" => "total_by_app_for_objects",
"total_by_context_by_user_by_app" => "total_by_user_by_app",
"total_by_context_by_user_by_app_for_objects" => "total_by_user_by_app",
"total_by_user" => "total_by_user",
"total_by_user_for_objects" => "total_by_user",
"total_by_user_by_app" => "total_by_user_by_app",
"total_by_user_by_app_for_objects" => "total_by_user_by_app",
"total_by_app" => "user_engagement/total_by_app",
"total_by_app_for_objects" => "total_by_app_for_objects",
"detail_no_text" => "detail_no_text",
"detail_without_filter" => "detail_by_context",
"detail_by_context" => "detail_by_context",
"detail_by_context_for_objects" => "detail_by_context_for_objects",
"detail_by_context_by_user" => "detail_by_user",
"detail_by_context_by_user_for_objects" => "detail_by_user",
"detail_by_context_by_app" => "detail_by_app",
"detail_by_context_by_app_for_objects" => "detail_by_app_for_objects",
"detail_by_context_by_user_by_app" => "detail_by_user_by_app",
"detail_by_context_by_user_by_app_for_objects" => "detail_by_user_by_app",
"detail_by_user" => "detail_by_user",
"detail_by_user_for_objects" => "detail_by_user",
"detail_by_user_by_app" => "detail_by_user_by_app",
"detail_by_user_by_app_for_objects" => "detail_by_user_by_app",
"detail_by_app" => "detail_by_app",
"detail_by_app_for_objects" => "detail_by_app_for_objects",

"count_no_text" => "count_no_text",
"count_without_filter" => "count_by_context",
"count_by_context" => "count_by_context",
"count_by_context_for_objects" => "count_by_context_for_objects",
"count_by_context_by_user" => "count_by_user",
"count_by_context_by_user_for_objects" => "count_by_user",
"count_by_context_by_app" => "count_by_app",
"count_by_context_by_app_for_objects" => "count_by_app_for_objects",
"count_by_context_by_user_by_app" => "count_by_user_by_app",
"count_by_context_by_user_by_app_for_objects" => "count_by_user_by_app",
"count_by_user" => "count_by_user",
"count_by_user_for_objects" => "count_by_user",
"count_by_user_by_app" => "count_by_user_by_app",
"count_by_user_by_app_for_objects" => "count_by_user_by_app",
"count_by_app" => "count_by_app",
"count_by_app_for_objects" => "count_by_app_for_objects",
),

);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SELECT COUNT(DISTINCT context_id) count_all
FROM
dwh_hourly_events_context_app ev, dwh_dim_applications ap
WHERE
{CAT_ID_CLAUSE}
AND ap.name = {APPLICATION_NAME}
AND ap.partner_id = ev.partner_id
AND ap.application_id = ev.application_id
AND ev.partner_id = {PARTNER_ID} # PARTNER_ID
AND date_id BETWEEN IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID})
AND IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID})
AND hour_id >= IF (date_id = IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 0)
AND hour_id < IF (date_id = IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 24)
AND ( count_time_viewed > 0 OR
count_plays > 0 OR
count_loads > 0 OR
sum_time_viewed > 0)

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SELECT COUNT(DISTINCT context_id) count_all
FROM
dwh_hourly_events_context_entry_user_app ev, dwh_dim_applications ap
WHERE
{OBJ_ID_CLAUSE} # ev.entry_id in
AND {CAT_ID_CLAUSE}
AND ap.name = {APPLICATION_NAME}
AND ap.partner_id = ev.partner_id
AND ap.application_id = ev.application_id
AND ev.partner_id = {PARTNER_ID} # PARTNER_ID
AND date_id BETWEEN IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID})
AND IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID})
AND hour_id >= IF (date_id = IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 0)
AND hour_id < IF (date_id = IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 24)
AND ( count_time_viewed > 0 OR
count_plays > 0 OR
count_loads > 0 OR
sum_time_viewed > 0)

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT COUNT(DISTINCT context_id) count_all
FROM
dwh_hourly_events_context_app ev
WHERE
{CAT_ID_CLAUSE}
AND partner_id = {PARTNER_ID} # PARTNER_ID
AND date_id BETWEEN IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID})
AND IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID})
AND hour_id >= IF (date_id = IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 0)
AND hour_id < IF (date_id = IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 24)
AND ( count_time_viewed > 0 OR
count_plays > 0 OR
count_loads > 0 OR
sum_time_viewed > 0)

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT COUNT(DISTINCT context_id) count_all
FROM
dwh_hourly_events_context_entry_user_app ev
WHERE
{OBJ_ID_CLAUSE} # ev.entry_id in
AND {CAT_ID_CLAUSE}
AND partner_id = {PARTNER_ID} # PARTNER_ID
AND date_id BETWEEN IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID})
AND IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID})
AND hour_id >= IF (date_id = IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 0)
AND hour_id < IF (date_id = IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 24)
AND ( count_time_viewed > 0 OR
count_plays > 0 OR
count_loads > 0 OR
sum_time_viewed > 0)

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SELECT COUNT(DISTINCT context_id) count_all
FROM
dwh_hourly_events_context_entry_user_app ev, dwh_dim_pusers us
WHERE
{OBJ_ID_CLAUSE}
AND {CAT_ID_CLAUSE}
AND ev.partner_id = {PARTNER_ID} # PARTNER_ID
AND ev.partner_id = us.partner_id
AND us.name IN {PUSER_ID}
AND us.puser_id = ev.user_id
AND date_id BETWEEN IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID})
AND IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID})
AND hour_id >= IF (date_id = IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 0)
AND hour_id < IF (date_id = IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 24)
AND ( count_time_viewed > 0 OR
count_plays > 0 OR
count_loads > 0 OR
sum_time_viewed > 0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SELECT COUNT(DISTINCT context_id) count_all
FROM
dwh_hourly_events_context_entry_user_app ev, dwh_dim_pusers us, dwh_dim_applications ap
WHERE
{OBJ_ID_CLAUSE} # ev.entry_id in
AND {CAT_ID_CLAUSE}
AND ev.partner_id = {PARTNER_ID} # PARTNER_ID
AND us.name IN {PUSER_ID}
AND ev.partner_id = us.partner_id
AND ev.user_id = us.puser_id
AND ap.name = {APPLICATION_NAME}
AND ap.application_id = ev.application_id
AND ap.partner_id = ev.partner_id
AND date_id BETWEEN IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID})
AND IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID})
AND hour_id >= IF (date_id = IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 0)
AND hour_id < IF (date_id = IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 24)
AND ( count_time_viewed > 0 OR
count_plays > 0 OR
count_loads > 0 OR
sum_time_viewed > 0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT
COUNT(DISTINCT context_id) count_all
FROM
dwh_hourly_events_context_entry_user_app ev
WHERE {OBJ_ID_CLAUSE}
AND partner_id = {PARTNER_ID} # PARTNER_ID
AND date_id BETWEEN IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID})
AND IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID})
AND hour_id >= IF (date_id = IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 0)
AND hour_id < IF (date_id = IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 24)
AND ( count_time_viewed > 0 OR
count_plays > 0 OR
count_loads > 0 OR
sum_time_viewed > 0)

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
SELECT
context_id object_id,
cat.name name,
count_plays,
sum_time_viewed,
avg_time_viewed,
avg_view_drop_off,
count_loads,
load_play_ratio
FROM
(
SELECT
context_id,
SUM(sum_time_viewed) sum_time_viewed,
SUM(sum_time_viewed)/SUM(count_plays) avg_time_viewed,
SUM(count_plays) count_plays,
SUM(count_loads) count_loads,
(SUM(IFNULL(count_plays_25,0)) + SUM(IFNULL(count_plays_50,0)) + SUM(IFNULL(count_plays_75,0)) + SUM(IFNULL(count_plays_100,0)))/4/SUM(count_plays) avg_view_drop_off,
( SUM(count_plays) / SUM(count_loads) ) load_play_ratio
FROM
dwh_hourly_events_context_app ev, dwh_dim_applications ap
WHERE
{CAT_ID_CLAUSE}
AND ap.name = {APPLICATION_NAME}
AND ap.partner_id = ev.partner_id
AND ap.application_id = ev.application_id
AND ev.partner_id = {PARTNER_ID} # PARTNER_ID
AND date_id BETWEEN IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID})
AND IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID})
AND hour_id >= IF (date_id = IF({TIME_SHIFT}>0,(DATE({FROM_DATE_ID}) - INTERVAL 1 DAY)*1, {FROM_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 0)
AND hour_id < IF (date_id = IF({TIME_SHIFT}<=0,(DATE({TO_DATE_ID}) + INTERVAL 1 DAY)*1, {TO_DATE_ID}), IF({TIME_SHIFT}>0, 24 - {TIME_SHIFT}, ABS({TIME_SHIFT})), 24)
AND ( count_time_viewed > 0 OR
count_plays > 0 OR
count_loads > 0 OR
sum_time_viewed > 0 )
GROUP BY context_id
ORDER BY {SORT_FIELD}
LIMIT {PAGINATION_FIRST},{PAGINATION_SIZE} /* pagination */
) AS ev_stats LEFT JOIN dwh_dim_category cat
ON ev_stats.context_id = cat.category_id

Loading

0 comments on commit 33b3545

Please sign in to comment.