question

Kvaba Interactive avatar image
Kvaba Interactive asked

Recreating Average Duration via Data Explorer (advanced)

Why: my client is currently using some statistics from the game into a bigger sheet of their own. They're using the daily email values and the Average duration from Data > Dashboard > Average duration. So each day they'll get the values from the email and then go to admin panel and hover on the new day to get the Average Duration value.

I am trying to recreate the Average duration with a Kusto query so it could be either automated or they could run it manually in the explorer and get the data more easily. So if there's an easier way to do it without a query (downloadable Average Duration) please tell me about it.

 ['events.all'] 
 | where FullName_Name == "client_focus_change" and Timestamp > startofday(now(-10d)) // get all events of type focus change in the past 10 days
 | extend Day = format_datetime(Timestamp, 'yyyy-MM-dd') // get the date from the event's timestamp to be used for grouping 
 | extend parsed = parse_json(tostring(EventData.PayloadJSON)) // get the event's data in useful format
 | extend var2 = toreal(parsed.FocusStateDuration) // get the session duration in seconds
 | where var2 > 0 // remove any 0 sessions
 | summarize smrz = avg(var2) by Day // group the results by Day and fill the smrz field with the average value of this group's sessions lengths
 | extend avgSessionDuration = format_datetime(todatetime(smrz * 1s), 'mm:ss') // format the result from number to time mm:ss
 | project Day, avgSessionDuration, smrz // show only columns that are of interest
 | order by Day desc  // order by date descending

The query returns results that seem fine, but differ from the Admin Panel's data by a random percent in a +/- 10% range.

In this comment how-is-the-average-screen-time-calculated.html there's a hint PlayFab Admin Panel might be grouping within 10 minute ranges.

Looking for advice :)

dataPlayStream
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Gosen Gao avatar image
Gosen Gao answered

According to the blog Sessions Preview Is Live! (playfab.com), our background algorithm may take other factors into account when calculating the average duration, so the result is different from the direct calculation of events. If you want to calculate the average duration by yourself, Kusto query is the best way, you can easily do it by following Connecting Kusto C# SDK to Insights - PlayFab | Microsoft Learn.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jean-Denis Boivin avatar image
Jean-Denis Boivin answered

I was looking into it as well and it seems like you need an additional condition to have accurate results:

| where var2 > 0 and parsed.FocusState == "false"

See: https://community.playfab.com/questions/40289/how-to-analyze-with-client-focus-change.html

Not very intuitive but the actual relevant duration is calculated when the focus is off otherwise this include the time outside the app or something?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.