OliverKeyes has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/257926

Change subject: Add dwell time calculations for the Portal
......................................................................

Add dwell time calculations for the Portal

What it says on the tin; calculates median, 95th% and 99th% dwell
time for portal traffic in the same way we calculate for search.

Bug:T120432
Change-Id: Id9c45748ccab706087af1a82733bd4b22173b1b4
---
M portal/portal.R
1 file changed, 17 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/discovery/golden 
refs/changes/26/257926/1

diff --git a/portal/portal.R b/portal/portal.R
index e6687bb..fa16280 100644
--- a/portal/portal.R
+++ b/portal/portal.R
@@ -8,7 +8,7 @@
                      event_destination AS destination,
                      event_event_type AS type,
                      event_section_used AS section_used,
-                     event_cohort",
+                     timestamp AS ts",
                      date = date,
                      table = table,
                      conditionals = "((event_cohort IS NULL) OR (event_cohort 
= 'null'))")
@@ -17,6 +17,20 @@
   data$section_used[is.na(data$section_used)] <- "no action"
   data$date <- as.Date(ymd(data$date))
   data <- as.data.table(data)
+  
+  # Generate dwell time
+  data$ts <- lubridate::ymd_hms(data$ts)
+  dwell_metric <- data[,j = {
+    if(.N > 1){
+      sorted_ts <- as.numeric(.SD$ts[order(.SD$ts, decreasing = TRUE)])
+      sorted_ts[1] - sorted_ts[2]
+    } else {
+      NULL
+    }
+  }, by = "session"]
+  
+  dwell_output <- data.frame(t(quantile(dwell_metric$V1, c(0.5, 0.95, 0.99))))
+  names(dwell_output) <- c("Median", "95th percentile", "99th Percentile")
   
   # Generate clickthrough rate data
   clickthrough_data <- data[,j=list(events=.N),by = c("date","type")]
@@ -28,6 +42,8 @@
   
   conditional_write(clickthrough_data, file.path(base_path, 
"clickthrough_rate.tsv"))
   conditional_write(breakdown_data, file.path(base_path, 
"clickthrough_breakdown.tsv"))
+  conditional_write(dwell_output, file.path(base_path, "dwell_metrics.tsv"))
   
+  # Generate dwell time metric
   return(invisible())
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/257926
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9c45748ccab706087af1a82733bd4b22173b1b4
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/golden
Gerrit-Branch: master
Gerrit-Owner: OliverKeyes <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to